The MockeryExpectations
trait provides a convenient method to assert Mockery expectations in PHPUnit tests. It is particularly useful when working with Mockery for mocking and stubbing objects.
To use the MockeryExpectations
trait in your PHPUnit test class, follow these steps:
- Include the trait in your test class:
use Tests\Util\MockeryExpectations;
class YourTestClass extends \PHPUnit\Framework\TestCase
{
use MockeryExpectations;
// ... your test methods
}
- Call the assertMockeryExpectations() method in your test class after you have finished your assertions:
public function testYourFeature(): void
{
// ... your test logic and assertions
// Call the assertMockeryExpectations() method to ensure Mockery expectations are met
$this->assertMockeryExpectations();
}
- The trait includes a method named assertMockeryExpectations, which calls Mockery's getExpectationCount method and asserts it using PHPUnit's addToAssertionCount.
- This trait is particularly handy when using Mockery in PHPUnit tests.