Skip to content

Commit 08eec87

Browse files
msvrtanondrejmirtes
authored andcommitted
Add MockeryBar test
In order to test expects() in a more native way, as an inner dependency of test under subject, lets add a Bar class that uses Foo and lets test it
1 parent ae30a72 commit 08eec87

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/Mockery/Bar.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Mockery;
4+
5+
class Bar
6+
{
7+
8+
/** @var Foo */
9+
private $foo;
10+
11+
public function __construct(Foo $foo)
12+
{
13+
$this->foo = $foo;
14+
}
15+
16+
public function doFoo(): ?string
17+
{
18+
return $this->foo->doFoo();
19+
}
20+
21+
}

tests/Mockery/MockeryBarTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Mockery;
4+
5+
class MockeryBarTest extends \PHPUnit\Framework\TestCase
6+
{
7+
8+
/** @var \Mockery\MockInterface|Foo */
9+
private $fooMock;
10+
11+
protected function setUp(): void
12+
{
13+
$this->fooMock = \Mockery::mock(Foo::class);
14+
}
15+
16+
public function testFooIsCalled(): void
17+
{
18+
$bar = new Bar($this->fooMock);
19+
20+
$this->fooMock->expects()->doFoo()->andReturn('foo');
21+
self::assertSame('foo', $bar->doFoo());
22+
}
23+
24+
}

0 commit comments

Comments
 (0)