Skip to content

Commit 245b17c

Browse files
MichaelDemeyerondrejmirtes
authored andcommitted
Support shouldHaveReceive and shouldNotHaveReceived
1 parent f0cf73b commit 245b17c

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ cs-fix:
2020

2121
.PHONY: phpstan
2222
phpstan:
23-
php vendor/bin/phpstan analyse -l 8 -c phpstan.neon src tests
23+
php vendor/bin/phpstan analyse -l 9 -c phpstan.neon src tests

stubs/MockInterface.stub

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ interface LegacyMockInterface
3939
*/
4040
public function shouldNotReceive(...$methodNames);
4141

42+
/**
43+
* @param null|string $method
44+
* @param null|array<string> $args
45+
* @return Expectation
46+
*/
47+
public function shouldHaveReceived($method, $args = null);
48+
49+
/**
50+
* @param null|string $method
51+
* @param null|array<string> $args
52+
* @return Expectation
53+
*/
54+
public function shouldNotHaveReceived($method, $args = null);
55+
4256
/**
4357
* @return static
4458
*/

tests/Mockery/MockeryBarTest.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,27 @@ public function testExpectationMethodsAreCalled(): void
4040
self::assertSame('foo', $bar->doFoo());
4141
}
4242

43-
public function testShouldNotReceiveAndHaveReceived(): void
43+
public function testShouldNotReceive(): void
4444
{
4545
$this->fooMock->shouldNotReceive('doFoo')->andReturn('bar');
46-
$this->fooMock->shouldNotHaveReceived('doFoo');
4746
}
4847

49-
public function testShouldReceiveAndHaveReceived(): void
48+
public function testShouldReceive(): void
5049
{
5150
$this->fooMock->shouldReceive('doFoo')->andReturn('bar');
5251
self::assertSame('bar', $this->fooMock->doFoo());
53-
$this->fooMock->shouldHaveReceived('doFoo');
52+
}
53+
54+
public function testShouldNotHaveReceived(): void
55+
{
56+
$this->fooMock->shouldNotHaveReceived(null)->withArgs(['bar']);
57+
}
58+
59+
public function testShouldHaveReceived(): void
60+
{
61+
$this->fooMock->allows('doFoo')->andReturn('bar');
62+
self::assertSame('bar', $this->fooMock->doFoo());
63+
$this->fooMock->shouldHaveReceived('doFoo')->once();
5464
}
5565

5666
}

0 commit comments

Comments
 (0)