1 | <?php |
||
17 | * @coversDefaultClass DoctrineModule\Validator\Service\UniqueObjectFactory |
||
18 | * @group validator |
||
19 | */ |
||
20 | class UniqueObjectFactoryTest extends TestCase |
||
21 | { |
||
22 | /** @var UniqueObjectFactory */ |
||
23 | private $object; |
||
24 | |||
25 | /** |
||
26 | * Sets up the fixture, for example, opens a network connection. |
||
27 | * This method is called before a test is executed. |
||
28 | */ |
||
29 | protected function setUp() : void |
||
30 | { |
||
31 | $this->object = new UniqueObjectFactory(); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @covers ::__invoke |
||
36 | */ |
||
37 | public function testInvoke() : void |
||
38 | { |
||
39 | $options = [ |
||
40 | 'target_class' => 'Foo\Bar', |
||
41 | 'fields' => ['test'], |
||
42 | ]; |
||
43 | |||
44 | $repository = $this->prophesize(ObjectRepository::class); |
||
45 | $objectManager = $this->prophesize(ObjectManager::class); |
||
46 | $objectManager->getRepository('Foo\Bar') |
||
47 | ->shouldBeCalled() |
||
48 | ->willReturn($repository->reveal()); |
||
49 | |||
50 | $container = $this->prophesize(ContainerInterface::class); |
||
51 | $container->get('doctrine.entitymanager.orm_default') |
||
52 | ->shouldBeCalled() |
||
53 | ->willReturn($objectManager->reveal()); |
||
54 | |||
55 | $instance = $this->object->__invoke( |
||
56 | $container->reveal(), |
||
57 | UniqueObject::class, |
||
58 | $options |
||
59 | ); |
||
60 | $this->assertInstanceOf(UniqueObject::class, $instance); |
||
61 | } |
||
62 | } |
||
63 |