I am trying to create a mockery unit test but it giving me this error
This test did not perform any assertions
public function testGetById()
{
$mock = Mockery::mock(PostService::class)->makePartial();
$mock->shouldReceive('getById')
->withSomeOfArgs(1);
$mock->getById(1);
}
! get by id→ This test did not perform any assertions \tests\Unit\PostControllerTest.php:30
Tests: 1 risked Time: 0.32s Warning: TTY mode is not supported on Windows platform.
There are two options.
Option 1:
$this->assertTrue(true);Option 2:
You can also extend Mockery\Adapter\Phpunit\MockeryTestCase instead of the usual PHPUnit\Framework\TestCase. That way you don't have to add phpunit assertions at all.
I am sorry that I cannot help you 100%, I cannot setup a testing project right now to try this, but you can try it:
public function testGetById()
{
$mock = Mockery::spy(PostService::class);
// Bind the mock to the Service Container so it gets injected (DI)
// Execute the code that would run that mock
$mock->shouldHaveReceived('getById')
->withSomeOfArgs(1);
}
Spies allow you to spy if the desired method got called with desired conditions. If you mock, you are just "faking" what it will return or do, if you spy, you will be able to assert what happened to a method.
Read more about it on the official Mockery documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With