1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoctrineModule\Validator\Service; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
6
|
|
|
use DoctrineModule\Validator\UniqueObject; |
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
8
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
9
|
|
|
use Interop\Container\ContainerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2017-09-04 at 11:57:37. |
13
|
|
|
* |
14
|
|
|
* @coversDefaultClass DoctrineModule\Validator\Service\UniqueObjectFactory |
15
|
|
|
* @group validator |
16
|
|
|
*/ |
17
|
|
|
class UniqueObjectFactoryTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var UniqueObjectFactory |
21
|
|
|
*/ |
22
|
|
|
private $object; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Sets up the fixture, for example, opens a network connection. |
26
|
|
|
* This method is called before a test is executed. |
27
|
|
|
*/ |
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->object = new UniqueObjectFactory; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @covers ::__invoke |
35
|
|
|
*/ |
36
|
|
|
public function test__invoke() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$options = [ |
39
|
|
|
'target_class' => 'Foo\Bar', |
40
|
|
|
'fields' => ['test'], |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$repository = $this->prophesize(ObjectRepository::class); |
44
|
|
|
$objectManager = $this->prophesize(ObjectManager::class); |
45
|
|
|
$objectManager->getRepository('Foo\Bar') |
46
|
|
|
->shouldBeCalled() |
47
|
|
|
->willReturn($repository->reveal()); |
48
|
|
|
|
49
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
50
|
|
|
$container->get('doctrine.entitymanager.orm_default') |
51
|
|
|
->shouldBeCalled() |
52
|
|
|
->willReturn($objectManager->reveal()); |
53
|
|
|
|
54
|
|
|
$instance = $this->object->__invoke( |
55
|
|
|
$container->reveal(), |
56
|
|
|
UniqueObject::class, |
57
|
|
|
$options |
58
|
|
|
); |
59
|
|
|
$this->assertInstanceOf(UniqueObject::class, $instance); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|