Skip to content

Commit 88ae859

Browse files
fancywebondrejmirtes
authored andcommitted
Fix MockInterface::shouldHaveReceived() and MockInterface::shouldNotHaveReceived() stub methods
1 parent 40dc3e2 commit 88ae859

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Diff for: stubs/MockInterface.stub

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ interface LegacyMockInterface
4141

4242
/**
4343
* @param null|string $method
44-
* @param null|array<string> $args
44+
* @param null|array<mixed>|\Closure $args
4545
* @return Expectation
4646
*/
4747
public function shouldHaveReceived($method, $args = null);
4848

4949
/**
5050
* @param null|string $method
51-
* @param null|array<string> $args
51+
* @param null|array<mixed>|\Closure $args
5252
* @return Expectation
5353
*/
5454
public function shouldNotHaveReceived($method, $args = null);

Diff for: tests/Mockery/MockeryBarTest.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
class MockeryBarTest extends MockeryTestCase
1010
{
1111

12-
/** @var MockInterface|Foo */
12+
/** @var MockInterface&Foo */
1313
private $fooMock;
1414

15+
/** @var MockInterface&Foo */
16+
private $fooSpy;
17+
1518
protected function setUp(): void
1619
{
1720
parent::setUp();
1821

1922
$this->fooMock = Mockery::mock(Foo::class);
23+
$this->fooSpy = Mockery::spy(Foo::class);
2024
}
2125

2226
public function testFooIsCalled(): void
@@ -53,14 +57,24 @@ public function testShouldReceive(): void
5357

5458
public function testShouldNotHaveReceived(): void
5559
{
56-
$this->fooMock->shouldNotHaveReceived(null)->withArgs(['bar']);
60+
$this->fooSpy->shouldNotHaveReceived(null)->withArgs(['bar']);
61+
$this->fooSpy->doBar('ccc');
62+
$this->fooSpy->shouldNotHaveReceived('doBar', ['ddd']);
63+
$this->fooSpy->shouldNotHaveReceived('doBar', static function (string $arg): bool {
64+
return $arg !== 'ccc';
65+
});
5766
}
5867

5968
public function testShouldHaveReceived(): void
6069
{
61-
$this->fooMock->allows('doFoo')->andReturn('bar');
62-
self::assertSame('bar', $this->fooMock->doFoo());
63-
$this->fooMock->shouldHaveReceived('doFoo')->once();
70+
$this->fooSpy->allows('doFoo')->andReturn('bar');
71+
self::assertSame('bar', $this->fooSpy->doFoo());
72+
$this->fooSpy->shouldHaveReceived('doFoo')->once();
73+
$this->fooSpy->doBar('ccc');
74+
$this->fooSpy->shouldHaveReceived('doBar', ['ccc']);
75+
$this->fooSpy->shouldHaveReceived('doBar', static function (string $arg): bool {
76+
return $arg === 'ccc';
77+
});
6478
}
6579

6680
}

Diff for: tests/Mockery/data/Foo.php

+3
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ public function doFoo(): ?string
2222
return 'foo';
2323
}
2424

25+
public function doBar(string $arg): void
26+
{
27+
}
2528
}

0 commit comments

Comments
 (0)