---
title: "#mockery articles | Hashnode"
description: "Explore 5 articles tagged #mockery on Hashnode. Tutorials, guides, and how-tos from the community."
url: "https://hashnode.com/tag/mockery"
---

Tag

# #mockery

5 posts · 0 followers

[recca0120](https://hashnode.com/@recca0120) · [Mar 8](https://hashnode.com/posts/phpunit-sleep-1/69add9aabc4378bf8e67b28f)

### [PHPUnit: Mock sleep() in 2 Ways Without Waiting](https://recca0120.hashnode.dev/phpunit-sleep-1?utm_source=hashnode&utm_medium=feed)

When sleep() slows PHPUnit tests, extract a Clock class and use Mockery spy to replace it, or use php-mock to mock the built-in function with no code changes.

2 min read · [recca0120.hashnode.dev](https://recca0120.hashnode.dev/phpunit-sleep-1?utm_source=hashnode&utm_medium=feed)

[recca0120](https://hashnode.com/@recca0120) · [Mar 8](https://hashnode.com/posts/how-to-test-closure-in-phpunit-1/69add9793db07d80867ebed5)

### [PHPUnit: Test Closures with Mockery::spy](https://recca0120.hashnode.dev/how-to-test-closure-in-phpunit-1?utm_source=hashnode&utm_medium=feed)

Assertions inside a closure pass silently even if never called. Wrap the closure in Mockery::spy to verify invocation count and arguments in PHPUnit tests.

1 min read · [recca0120.hashnode.dev](https://recca0120.hashnode.dev/how-to-test-closure-in-phpunit-1?utm_source=hashnode&utm_medium=feed)

[recca0120](https://hashnode.com/@recca0120) · [Mar 3](https://hashnode.com/posts/mockery-capturing-arguments/69a63e32edbe7b25ac9f577e)

### [Write Deterministic PHPUnit Assertions with Mockery::capture](https://recca0120.hashnode.dev/mockery-capturing-arguments?utm_source=hashnode&utm_medium=feed)

When a method uses random\_int internally, Mockery::capture with passthru captures the intermediate value so you can compute the expected result and assert it.

2 min read · [recca0120.hashnode.dev](https://recca0120.hashnode.dev/mockery-capturing-arguments?utm_source=hashnode&utm_medium=feed)

[recca0120](https://hashnode.com/@recca0120) · [Mar 3](https://hashnode.com/posts/how-to-use-mockery-to-mock-iteratoraggregate/69a63dccb5b0a9cd95d01fd0)

### [Mock IteratorAggregate with Mockery to Fix foreach in Tests](https://recca0120.hashnode.dev/how-to-use-mockery-to-mock-iteratoraggregate?utm_source=hashnode&utm_medium=feed)

Mocking IteratorAggregate breaks foreach in PHPUnit. Return an ArrayObject from the mocked getIterator method to make foreach iterate over test data correctly.

1 min read · [recca0120.hashnode.dev](https://recca0120.hashnode.dev/how-to-use-mockery-to-mock-iteratoraggregate?utm_source=hashnode&utm_medium=feed)

[Bedram Tamang](https://hashnode.com/@Bedram) · [Mar 31, 2023](https://hashnode.com/posts/test-doubles-in-php-with-mockery-and-phpunit/642661637d1a2cc219e3e275)

### [Test Doubles in PHP with Mockery and PHPUnit](https://blog.jobins.jp/test-doubles-in-php-with-mockery-and-phpunit?utm_source=hashnode&utm_medium=feed)

Test doubles is a technique in which you replace the actual object with pretend object or a real method by pretend method or pre-define the return data and function arguments for a method to ease the testing purpose. In the real world, our applicatio...

5 min read · [blog.jobins.jp](https://blog.jobins.jp/test-doubles-in-php-with-mockery-and-phpunit?utm_source=hashnode&utm_medium=feed)

[1](https://hashnode.com/posts/test-doubles-in-php-with-mockery-and-phpunit/642661637d1a2cc219e3e275)
