|
2 | 2 |
|
3 | 3 | namespace Tests\Unit; |
4 | 4 |
|
5 | | -use Arachne\DIHelpers\ResolverInterface; |
6 | 5 | use Arachne\EntityLoader\EntityLoader; |
7 | 6 | use Arachne\EntityLoader\FilterInInterface; |
8 | | -use Codeception\MockeryModule\Test; |
9 | | -use Mockery; |
10 | | -use Mockery\MockInterface; |
| 7 | +use Codeception\Test\Unit; |
| 8 | +use DateTime; |
| 9 | +use Eloquent\Phony\Mock\Handle\InstanceHandle; |
| 10 | +use Eloquent\Phony\Phpunit\Phony; |
| 11 | +use Eloquent\Phony\Stub\StubVerifier; |
11 | 12 |
|
12 | 13 | /** |
13 | 14 | * @author Jáchym Toušek <enumag@gmail.com> |
14 | 15 | */ |
15 | | -class EntityLoaderTest extends Test |
| 16 | +class EntityLoaderTest extends Unit |
16 | 17 | { |
17 | 18 | /** |
18 | 19 | * @var EntityLoader |
19 | 20 | */ |
20 | 21 | private $entityLoader; |
21 | 22 |
|
22 | 23 | /** |
23 | | - * @var MockInterface |
| 24 | + * @var InstanceHandle |
24 | 25 | */ |
25 | | - private $filter; |
| 26 | + private $filterHandle; |
26 | 27 |
|
27 | 28 | /** |
28 | | - * @var MockInterface |
| 29 | + * @var StubVerifier |
29 | 30 | */ |
30 | 31 | private $filterResolver; |
31 | 32 |
|
32 | 33 | protected function _before() |
33 | 34 | { |
34 | | - $this->filter = Mockery::mock(FilterInInterface::class); |
35 | | - $this->filterResolver = Mockery::mock(ResolverInterface::class); |
| 35 | + $this->filterHandle = Phony::mock(FilterInInterface::class); |
| 36 | + $this->filterResolver = Phony::stub(); |
36 | 37 | $this->entityLoader = new EntityLoader($this->filterResolver); |
37 | 38 | } |
38 | 39 |
|
39 | 40 | public function testFilterIn() |
40 | 41 | { |
41 | 42 | $this->filterResolver |
42 | | - ->shouldReceive('resolve') |
43 | | - ->once() |
44 | | - ->with('Type1') |
45 | | - ->andReturn($this->filter); |
| 43 | + ->returns($this->filterHandle->get()); |
46 | 44 |
|
47 | | - $mock1 = Mockery::mock('Type1'); |
| 45 | + $mock1 = Phony::mock(DateTime::class)->get(); |
48 | 46 |
|
49 | | - $this->filter |
50 | | - ->shouldReceive('filterIn') |
51 | | - ->once() |
52 | | - ->with(1) |
53 | | - ->andReturn($mock1); |
| 47 | + $this->filterHandle |
| 48 | + ->filterIn |
| 49 | + ->returns($mock1); |
54 | 50 |
|
55 | | - $this->assertSame($mock1, $this->entityLoader->filterIn('Type1', 1)); |
| 51 | + $this->assertSame($mock1, $this->entityLoader->filterIn(DateTime::class, 1)); |
| 52 | + |
| 53 | + $this->filterHandle |
| 54 | + ->filterIn |
| 55 | + ->calledWith(1); |
56 | 56 | } |
57 | 57 |
|
58 | 58 | /** |
59 | | - * @expectedException Arachne\EntityLoader\Exception\UnexpectedValueException |
60 | | - * @expectedExceptionMessage FilterIn did not return an instance of 'Type1'. |
| 59 | + * @expectedException \Arachne\EntityLoader\Exception\UnexpectedValueException |
| 60 | + * @expectedExceptionMessage FilterIn did not return an instance of 'DateTime'. |
61 | 61 | */ |
62 | 62 | public function testFilterInFail() |
63 | 63 | { |
64 | 64 | $this->filterResolver |
65 | | - ->shouldReceive('resolve') |
66 | | - ->once() |
67 | | - ->with('Type1') |
68 | | - ->andReturn($this->filter); |
69 | | - |
70 | | - $this->filter |
71 | | - ->shouldReceive('filterIn') |
72 | | - ->once() |
73 | | - ->with(1) |
74 | | - ->andReturn(null); |
75 | | - |
76 | | - $this->entityLoader->filterIn('Type1', 1); |
| 65 | + ->returns($this->filterHandle->get()); |
| 66 | + |
| 67 | + $this->filterHandle |
| 68 | + ->filterIn |
| 69 | + ->returns(null); |
| 70 | + |
| 71 | + $this->entityLoader->filterIn(DateTime::class, 1); |
77 | 72 | } |
78 | 73 |
|
79 | 74 | public function testFilterInIgnore() |
80 | 75 | { |
81 | 76 | // Make sure that the converter is not called at all if the parameter already has the desired type. |
82 | | - $mock1 = Mockery::mock('Type1'); |
83 | | - $this->assertSame($mock1, $this->entityLoader->filterIn('Type1', $mock1)); |
| 77 | + $mock1 = Phony::mock(DateTime::class)->get(); |
| 78 | + $this->assertSame($mock1, $this->entityLoader->filterIn(DateTime::class, $mock1)); |
84 | 79 | } |
85 | 80 |
|
86 | 81 | /** |
87 | | - * @expectedException Arachne\EntityLoader\Exception\UnexpectedValueException |
88 | | - * @expectedExceptionMessage No filter in found for type 'Type1'. |
| 82 | + * @expectedException \Arachne\EntityLoader\Exception\UnexpectedValueException |
| 83 | + * @expectedExceptionMessage No filter in found for type 'DateTime'. |
89 | 84 | */ |
90 | 85 | public function testFilterNotFound() |
91 | 86 | { |
92 | 87 | $parameters = [ |
93 | 88 | 'entity' => 'value1', |
94 | 89 | ]; |
95 | 90 |
|
96 | | - $this->filterResolver |
97 | | - ->shouldReceive('resolve') |
98 | | - ->once() |
99 | | - ->with('Type1') |
100 | | - ->andReturn(); |
101 | | - |
102 | | - $this->entityLoader->filterIn('Type1', $parameters); |
| 91 | + $this->entityLoader->filterIn(DateTime::class, $parameters); |
103 | 92 | } |
104 | 93 | } |
0 commit comments