From 245b17ccd00f04be3c6b9fc6645f63793b37b2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Demeyer?= Date: Thu, 5 May 2022 14:12:44 +0200 Subject: [PATCH] Support shouldHaveReceive and shouldNotHaveReceived --- Makefile | 2 +- stubs/MockInterface.stub | 14 ++++++++++++++ tests/Mockery/MockeryBarTest.php | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fe917d3..93110c9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/stubs/MockInterface.stub b/stubs/MockInterface.stub index e5d8b40..d7f107a 100644 --- a/stubs/MockInterface.stub +++ b/stubs/MockInterface.stub @@ -39,6 +39,20 @@ interface LegacyMockInterface */ public function shouldNotReceive(...$methodNames); + /** + * @param null|string $method + * @param null|array $args + * @return Expectation + */ + public function shouldHaveReceived($method, $args = null); + + /** + * @param null|string $method + * @param null|array $args + * @return Expectation + */ + public function shouldNotHaveReceived($method, $args = null); + /** * @return static */ diff --git a/tests/Mockery/MockeryBarTest.php b/tests/Mockery/MockeryBarTest.php index 6b24071..0c0ad15 100644 --- a/tests/Mockery/MockeryBarTest.php +++ b/tests/Mockery/MockeryBarTest.php @@ -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(); } }