Skip to content

Commit 2b1b760

Browse files
committed
Support shouldNotReceive
This fixes the issue when using: ``` $this->fooMock->shouldNotReceive('doFoo')->andReturn('bar'); // Call to an undefined method Mockery\ExpectationInterface|Mockery\HigherOrderMessage::andReturn() ``` Add tests for `shouldHaveReceived` and `shouldNotHaveReceived`. Fixes #11
1 parent ebf744d commit 2b1b760

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

stubs/MockInterface.stub

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ interface MockInterface
1111
*/
1212
public function shouldReceive(...$methodNames);
1313

14+
/**
15+
* @param string|array<string, mixed> ...$methodNames
16+
* @return Expectation
17+
*/
18+
public function shouldNotReceive(...$methodNames);
19+
1420
/**
1521
* @return static
1622
*/
@@ -27,6 +33,12 @@ interface LegacyMockInterface
2733
*/
2834
public function shouldReceive(...$methodNames);
2935

36+
/**
37+
* @param string|array<string, mixed> ...$methodNames
38+
* @return Expectation
39+
*/
40+
public function shouldNotReceive(...$methodNames);
41+
3042
/**
3143
* @return static
3244
*/

tests/Mockery/MockeryBarTest.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
namespace PHPStan\Mockery;
44

5-
class MockeryBarTest extends \PHPUnit\Framework\TestCase
5+
use Mockery\Adapter\Phpunit\MockeryTestCase;
6+
7+
class MockeryBarTest extends MockeryTestCase
68
{
79

810
/** @var \Mockery\MockInterface|Foo */
911
private $fooMock;
1012

1113
protected function setUp(): void
1214
{
15+
parent::setUp();
16+
1317
$this->fooMock = \Mockery::mock(Foo::class);
1418
}
1519

@@ -34,4 +38,17 @@ public function testExpectationMethodsAreCalled(): void
3438
self::assertSame('foo', $bar->doFoo());
3539
}
3640

41+
public function testShouldNotReceiveAndHaveReceived(): void
42+
{
43+
$this->fooMock->shouldNotReceive('doFoo')->andReturn('bar');
44+
$this->fooMock->shouldNotHaveReceived('doFoo');
45+
}
46+
47+
public function testShouldReceiveAndHaveReceived(): void
48+
{
49+
$this->fooMock->shouldReceive('doFoo')->andReturn('bar');
50+
self::assertSame('bar', $this->fooMock->doFoo());
51+
$this->fooMock->shouldHaveReceived('doFoo');
52+
}
53+
3754
}

0 commit comments

Comments
 (0)