Skip to content

Commit

Permalink
Support shouldHaveReceive and shouldNotHaveReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDemeyer authored and ondrejmirtes committed May 9, 2022
1 parent f0cf73b commit 245b17c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ cs-fix:

.PHONY: phpstan
phpstan:
php vendor/bin/phpstan analyse -l 8 -c phpstan.neon src tests
php vendor/bin/phpstan analyse -l 9 -c phpstan.neon src tests
14 changes: 14 additions & 0 deletions stubs/MockInterface.stub
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ interface LegacyMockInterface
*/
public function shouldNotReceive(...$methodNames);

/**
* @param null|string $method
* @param null|array<string> $args
* @return Expectation
*/
public function shouldHaveReceived($method, $args = null);

/**
* @param null|string $method
* @param null|array<string> $args
* @return Expectation
*/
public function shouldNotHaveReceived($method, $args = null);

/**
* @return static
*/
Expand Down
18 changes: 14 additions & 4 deletions tests/Mockery/MockeryBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,27 @@ public function testExpectationMethodsAreCalled(): void
self::assertSame('foo', $bar->doFoo());
}

public function testShouldNotReceiveAndHaveReceived(): void
public function testShouldNotReceive(): void
{
$this->fooMock->shouldNotReceive('doFoo')->andReturn('bar');
$this->fooMock->shouldNotHaveReceived('doFoo');
}

public function testShouldReceiveAndHaveReceived(): void
public function testShouldReceive(): void
{
$this->fooMock->shouldReceive('doFoo')->andReturn('bar');
self::assertSame('bar', $this->fooMock->doFoo());
$this->fooMock->shouldHaveReceived('doFoo');
}

public function testShouldNotHaveReceived(): void
{
$this->fooMock->shouldNotHaveReceived(null)->withArgs(['bar']);
}

public function testShouldHaveReceived(): void
{
$this->fooMock->allows('doFoo')->andReturn('bar');
self::assertSame('bar', $this->fooMock->doFoo());
$this->fooMock->shouldHaveReceived('doFoo')->once();
}

}

0 comments on commit 245b17c

Please sign in to comment.