Skip to content

Commit

Permalink
Support shouldNotReceive
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ruudk authored and ondrejmirtes committed Feb 5, 2021
1 parent ebf744d commit 053bf9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions stubs/MockInterface.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ interface MockInterface
*/
public function shouldReceive(...$methodNames);

/**
* @param string|array<string, mixed> ...$methodNames
* @return Expectation
*/
public function shouldNotReceive(...$methodNames);

/**
* @return static
*/
Expand All @@ -27,6 +33,12 @@ interface LegacyMockInterface
*/
public function shouldReceive(...$methodNames);

/**
* @param string|array<string, mixed> ...$methodNames
* @return Expectation
*/
public function shouldNotReceive(...$methodNames);

/**
* @return static
*/
Expand Down
19 changes: 18 additions & 1 deletion tests/Mockery/MockeryBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace PHPStan\Mockery;

class MockeryBarTest extends \PHPUnit\Framework\TestCase
use Mockery\Adapter\Phpunit\MockeryTestCase;

class MockeryBarTest extends MockeryTestCase
{

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

protected function setUp(): void
{
parent::setUp();

$this->fooMock = \Mockery::mock(Foo::class);
}

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

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

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

}

0 comments on commit 053bf9e

Please sign in to comment.