These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace DoctrineModule\Validator\Service; |
||
6 | |||
7 | use Doctrine\Persistence\ObjectManager; |
||
8 | use Doctrine\Persistence\ObjectRepository; |
||
9 | use DoctrineModule\Validator\NoObjectExists; |
||
10 | use DoctrineModule\Validator\Service\Exception\ServiceCreationException; |
||
11 | use Interop\Container\ContainerInterface; |
||
12 | use Laminas\ServiceManager\ServiceLocatorAwareInterface; |
||
13 | use Laminas\ServiceManager\ServiceLocatorInterface; |
||
14 | use PHPUnit\Framework\TestCase; |
||
15 | use function interface_exists; |
||
16 | |||
17 | /** |
||
18 | * Generated by PHPUnit_SkeletonGenerator on 2017-09-04 at 11:12:27. |
||
19 | * |
||
20 | * @coversDefaultClass DoctrineModule\Validator\Service\NoObjectExistsFactory |
||
21 | * @group validator |
||
22 | */ |
||
23 | class NoObjectExistsFactoryTest extends TestCase |
||
24 | { |
||
25 | /** @var NoObjectExistsFactory */ |
||
26 | private $object; |
||
27 | |||
28 | /** |
||
29 | * Sets up the fixture, for example, opens a network connection. |
||
30 | * This method is called before a test is executed. |
||
31 | */ |
||
32 | protected function setUp() : void |
||
33 | { |
||
34 | $this->object = new NoObjectExistsFactory(); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @coversNothing |
||
39 | */ |
||
40 | public function testCallable() : void |
||
41 | { |
||
42 | $this->assertIsCallable($this->object); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @covers ::__invoke |
||
47 | * @covers ::container |
||
48 | * @covers ::getRepository |
||
49 | * @covers ::getObjectManager |
||
50 | * @covers ::getFields |
||
51 | */ |
||
52 | public function testInvoke() : void |
||
53 | { |
||
54 | $options = [ |
||
55 | 'target_class' => 'Foo\Bar', |
||
56 | 'fields' => ['test'], |
||
57 | ]; |
||
58 | |||
59 | $repository = $this->prophesize(ObjectRepository::class); |
||
0 ignored issues
–
show
|
|||
60 | $objectManager = $this->prophesize(ObjectManager::class); |
||
61 | $objectManager->getRepository('Foo\Bar') |
||
62 | ->shouldBeCalled() |
||
63 | ->willReturn($repository->reveal()); |
||
64 | |||
65 | $container = $this->prophesize(ContainerInterface::class); |
||
66 | $container->get('doctrine.entitymanager.orm_default') |
||
67 | ->shouldBeCalled() |
||
68 | ->willReturn($objectManager->reveal()); |
||
69 | |||
70 | $instance = $this->object->__invoke( |
||
71 | $container->reveal(), |
||
72 | NoObjectExists::class, |
||
73 | $options |
||
74 | ); |
||
75 | $this->assertInstanceOf(NoObjectExists::class, $instance); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @covers ::__invoke |
||
80 | * @covers ::container |
||
81 | * @covers ::getRepository |
||
82 | * @covers ::getObjectManager |
||
83 | * @covers ::getFields |
||
84 | */ |
||
85 | public function testInvokeWithObjectManagerGiven() : void |
||
86 | { |
||
87 | $repository = $this->prophesize(ObjectRepository::class); |
||
0 ignored issues
–
show
The method
prophesize() does not seem to exist on object<DoctrineModule\Va...bjectExistsFactoryTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
88 | $objectManager = $this->prophesize(ObjectManager::class); |
||
89 | $objectManager->getRepository('Foo\Bar') |
||
90 | ->shouldBeCalled() |
||
91 | ->willReturn($repository->reveal()); |
||
92 | |||
93 | $options = [ |
||
94 | 'target_class' => 'Foo\Bar', |
||
95 | 'object_manager' => $objectManager->reveal(), |
||
96 | 'fields' => ['test'], |
||
97 | ]; |
||
98 | |||
99 | $container = $this->prophesize(ContainerInterface::class); |
||
100 | $container->get('doctrine.entitymanager.orm_default') |
||
101 | ->shouldNotBeCalled(); |
||
102 | |||
103 | $instance = $this->object->__invoke( |
||
104 | $container->reveal(), |
||
105 | NoObjectExists::class, |
||
106 | $options |
||
107 | ); |
||
108 | $this->assertInstanceOf(NoObjectExists::class, $instance); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @covers ::merge |
||
113 | */ |
||
114 | public function testInvokeWithMerge() : void |
||
115 | { |
||
116 | $options = [ |
||
117 | 'target_class' => 'Foo\Bar', |
||
118 | 'fields' => ['test'], |
||
119 | 'messages' => [NoObjectExists::ERROR_OBJECT_FOUND => 'test'], |
||
120 | ]; |
||
121 | |||
122 | $repository = $this->prophesize(ObjectRepository::class); |
||
123 | $objectManager = $this->prophesize(ObjectManager::class); |
||
124 | $objectManager->getRepository('Foo\Bar') |
||
125 | ->shouldBeCalled() |
||
126 | ->willReturn($repository->reveal()); |
||
127 | |||
128 | $container = $this->prophesize(ContainerInterface::class); |
||
129 | $container->get('doctrine.entitymanager.orm_default') |
||
130 | ->shouldBeCalled() |
||
131 | ->willReturn($objectManager->reveal()); |
||
132 | |||
133 | $instance = $this->object->__invoke( |
||
134 | $container->reveal(), |
||
135 | NoObjectExists::class, |
||
136 | $options |
||
137 | ); |
||
138 | $templates = $instance->getMessageTemplates(); |
||
139 | $this->assertArrayHasKey(NoObjectExists::ERROR_OBJECT_FOUND, $templates); |
||
140 | $this->assertSame('test', $templates[NoObjectExists::ERROR_OBJECT_FOUND]); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @covers ::getRepository |
||
145 | */ |
||
146 | public function testInvokeWithoutTargetClass() : void |
||
147 | { |
||
148 | $this->expectException(ServiceCreationException::class); |
||
0 ignored issues
–
show
The method
expectException() does not seem to exist on object<DoctrineModule\Va...bjectExistsFactoryTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
149 | |||
150 | $container = $this->prophesize(ContainerInterface::class); |
||
151 | $this->object->__invoke( |
||
152 | $container->reveal(), |
||
153 | NoObjectExists::class, |
||
154 | [] |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @covers ::createService |
||
160 | * @covers ::setCreationOptions |
||
161 | */ |
||
162 | public function testCreateService() : void |
||
163 | { |
||
164 | $options = [ |
||
165 | 'target_class' => 'Foo\Bar', |
||
166 | 'fields' => ['test'], |
||
167 | ]; |
||
168 | |||
169 | $repository = $this->prophesize(ObjectRepository::class); |
||
170 | $objectManager = $this->prophesize(ObjectManager::class); |
||
171 | $objectManager->getRepository('Foo\Bar') |
||
172 | ->shouldBeCalled() |
||
173 | ->willReturn($repository->reveal()); |
||
174 | |||
175 | $container = $this->prophesize(ServiceLocatorInterface::class); |
||
176 | $container->get('doctrine.entitymanager.orm_default') |
||
177 | ->shouldBeCalled() |
||
178 | ->willReturn($objectManager->reveal()); |
||
179 | |||
180 | $this->object->setCreationOptions($options); |
||
181 | $instance = $this->object->createService($container->reveal()); |
||
182 | $this->assertInstanceOf(NoObjectExists::class, $instance); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @covers ::container |
||
187 | */ |
||
188 | public function testCreateServiceWithServiceLocatorAwareInterface() : void |
||
189 | { |
||
190 | if (! interface_exists(ServiceLocatorAwareInterface::class)) { |
||
191 | $this->markTestSkipped('ServiceLocatorAwareInterface not defined'); |
||
192 | } |
||
193 | |||
194 | $options = [ |
||
195 | 'target_class' => 'Foo\Bar', |
||
196 | 'fields' => ['test'], |
||
197 | ]; |
||
198 | |||
199 | $repository = $this->prophesize(ObjectRepository::class); |
||
200 | $objectManager = $this->prophesize(ObjectManager::class); |
||
201 | $objectManager->getRepository('Foo\Bar') |
||
202 | ->shouldBeCalled() |
||
203 | ->willReturn($repository->reveal()); |
||
204 | |||
205 | $container = $this->prophesize(ServiceLocatorInterface::class); |
||
206 | $container->get('doctrine.entitymanager.orm_default') |
||
207 | ->shouldBeCalled() |
||
208 | ->willReturn($objectManager->reveal()); |
||
209 | |||
210 | $parentContainer = $this->prophesize(ServiceLocatorInterface::class); |
||
211 | $parentContainer->willImplement(ServiceLocatorAwareInterface::class); |
||
212 | $parentContainer->getServiceLocator() |
||
213 | ->shouldBeCalled() |
||
214 | ->willReturn($container->reveal()); |
||
215 | |||
216 | $this->object->setCreationOptions($options); |
||
217 | $instance = $this->object->createService($parentContainer->reveal()); |
||
218 | $this->assertInstanceOf(NoObjectExists::class, $instance); |
||
219 | } |
||
220 | } |
||
221 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.