|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Khepin\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use \Mockery as m; |
|
6
|
|
|
use Khepin\YamlFixturesBundle\Loader\YamlLoader; |
|
7
|
|
|
use Khepin\Utils\BaseTestCaseMongo; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @group mongo |
|
11
|
|
|
*/ |
|
12
|
|
|
class MongoFixtureTest extends BaseTestCaseMongo |
|
13
|
|
|
{ |
|
14
|
|
|
protected $kernel = null; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->getDoctrine(); |
|
19
|
|
|
$service = m::mock()->shouldReceive('lowerCaseName')->withAnyArgs()->andReturnUsing( |
|
|
|
|
|
|
20
|
|
|
function ($car) { |
|
21
|
|
|
$car->setName(strtolower($car->getName())); |
|
22
|
|
|
} |
|
23
|
|
|
)->mock(); |
|
24
|
|
|
$container = m::mock('Container') |
|
|
|
|
|
|
25
|
|
|
->shouldReceive('get')->with('my_service')->andReturn($service) |
|
26
|
|
|
->shouldReceive('get')->withAnyArgs()->andReturn($this->doctrine) |
|
27
|
|
|
->mock(); |
|
28
|
|
|
$this->kernel = m::mock( |
|
29
|
|
|
'\Symfony\Component\HttpKernel\KernelInterface', |
|
30
|
|
|
array( |
|
31
|
|
|
'locateResource' => __DIR__ . '/mongo/', |
|
32
|
|
|
'getContainer' => $container |
|
33
|
|
|
) |
|
34
|
|
|
); |
|
35
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
36
|
|
|
$loader->purgeDatabase('mongodb'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testSimpleLoading() |
|
40
|
|
|
{ |
|
41
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
42
|
|
|
$loader->loadFixtures(); |
|
43
|
|
|
|
|
44
|
|
|
$dm = $this->doctrine->getManager(); |
|
|
|
|
|
|
45
|
|
|
$cars = $dm->getRepository('Khepin\Fixture\Document\Car')->findAll(); |
|
46
|
|
|
$this->assertEquals(2, count($cars)); |
|
47
|
|
|
$car = $dm->getRepository('Khepin\Fixture\Document\Car')->findOneBy(array('name' => 'Mercedes')); |
|
48
|
|
|
$this->assertEquals('Mercedes', $car->getName()); |
|
49
|
|
|
$date = new \DateTime('2012-01-01'); |
|
50
|
|
|
$this->assertEquals($date, $car->getDatePurchased()); |
|
51
|
|
|
$this->assertEquals(get_class($date), get_class($car->getDatePurchased())); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
View Code Duplication |
public function testLoadSingleFile() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle/cars'), 'DataFixtures'); |
|
57
|
|
|
$loader->loadFixtures(); |
|
58
|
|
|
|
|
59
|
|
|
$dm = $this->doctrine->getManager(); |
|
|
|
|
|
|
60
|
|
|
$cars = $dm->getRepository('Khepin\Fixture\Document\Car')->findAll(); |
|
61
|
|
|
$this->assertEquals(2, count($cars)); |
|
62
|
|
|
$drivers = $dm->getRepository('Khepin\Fixture\Document\Driver')->findAll(); |
|
63
|
|
|
$this->assertEquals(0, count($drivers)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
View Code Duplication |
public function testSingleFileLoadedOnlyOnce() |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle/cars', 'SomeBundle'), 'DataFixtures'); |
|
69
|
|
|
$loader->loadFixtures(); |
|
70
|
|
|
|
|
71
|
|
|
$em = $this->doctrine->getManager(); |
|
|
|
|
|
|
72
|
|
|
$cars = $em->getRepository('Khepin\Fixture\Document\Car')->findAll(); |
|
73
|
|
|
$this->assertEquals(2, count($cars)); |
|
74
|
|
|
$drivers = $em->getRepository('Khepin\Fixture\Document\Driver')->findAll(); |
|
75
|
|
|
$this->assertEquals(0, count($drivers)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
public function testPurge() |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
81
|
|
|
$loader->loadFixtures(); |
|
82
|
|
|
$loader->purgeDatabase('mongodb'); |
|
83
|
|
|
|
|
84
|
|
|
$cars = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Car')->findAll(); |
|
|
|
|
|
|
85
|
|
|
$this->assertEquals(count($cars), 0); |
|
86
|
|
|
|
|
87
|
|
|
$drivers = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Driver')->findAll(); |
|
|
|
|
|
|
88
|
|
|
$this->assertEquals(count($drivers), 0); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
View Code Duplication |
public function testContext() |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
94
|
|
|
$loader->loadFixtures('french_cars'); |
|
95
|
|
|
|
|
96
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Car'); |
|
|
|
|
|
|
97
|
|
|
$cars = $repo->findAll(); |
|
98
|
|
|
$this->assertEquals(5, count($cars)); |
|
99
|
|
|
|
|
100
|
|
|
$car = $repo->findOneBy(array('name' => 'Peugeot')); |
|
101
|
|
|
$this->assertEquals('Peugeot', $car->getName()); |
|
102
|
|
|
|
|
103
|
|
|
$car = $repo->findOneBy(array('name' => 'BMW')); |
|
104
|
|
|
$this->assertEquals('BMW', $car->getName()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function testReferenceOne() |
|
108
|
|
|
{ |
|
109
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
110
|
|
|
$loader->loadFixtures('with_drivers', 'family_cars'); |
|
111
|
|
|
|
|
112
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Driver'); |
|
|
|
|
|
|
113
|
|
|
$driver = $repo->findOneBy(array('name' => 'Mom')); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertEquals('Mercedes', $driver->getPreferredCar()->getName()); |
|
116
|
|
|
$this->assertNotEquals('BMW', $driver->getPreferredCar()->getName()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testReferenceMany() |
|
120
|
|
|
{ |
|
121
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
122
|
|
|
$loader->loadFixtures('with_drivers', 'family_cars'); |
|
123
|
|
|
|
|
124
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Driver'); |
|
|
|
|
|
|
125
|
|
|
$driver = $repo->findOneBy(array('name' => 'Mom')); |
|
126
|
|
|
$this->assertEquals($driver->getCars()->count(), 3); |
|
127
|
|
|
$cars = $driver->getCars(); |
|
128
|
|
|
$car = $cars[0]; |
|
129
|
|
|
$this->assertEquals('Mercedes', $car->getName()); |
|
130
|
|
|
$driver = $repo->findOneBy(array('name' => 'Dad')); |
|
131
|
|
|
$this->assertEquals($driver->getCars()->count(), 3); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
View Code Duplication |
public function testServiceCalls() |
|
|
|
|
|
|
135
|
|
|
{ |
|
136
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
137
|
|
|
$loader->loadFixtures('service'); |
|
138
|
|
|
|
|
139
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Car'); |
|
|
|
|
|
|
140
|
|
|
$car = $repo->findOneBy(array('name' => 'toyota')); |
|
141
|
|
|
$this->assertTrue('toyota' === $car->getName()); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
View Code Duplication |
public function testEmbedOne() |
|
|
|
|
|
|
145
|
|
|
{ |
|
146
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
147
|
|
|
$loader->loadFixtures('embed_one'); |
|
148
|
|
|
|
|
149
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Article'); |
|
|
|
|
|
|
150
|
|
|
$articles = $repo->createQueryBuilder()->getQuery()->execute(); |
|
151
|
|
|
$this->assertEquals($articles->count(), 1); |
|
152
|
|
|
$article = $articles->getNext(); |
|
153
|
|
|
$this->assertInstanceOf('Khepin\Fixture\Document\Article', $article); |
|
154
|
|
|
$author = $article->getAuthor(); |
|
155
|
|
|
$this->assertInstanceOf('Khepin\Fixture\Document\Author', $author); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertEquals($author->getName(), 'Paul'); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
View Code Duplication |
public function testEmbedMany() |
|
|
|
|
|
|
161
|
|
|
{ |
|
162
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
163
|
|
|
$loader->loadFixtures('embed_many'); |
|
164
|
|
|
|
|
165
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Article'); |
|
|
|
|
|
|
166
|
|
|
$articles = $repo->createQueryBuilder()->getQuery()->execute(); |
|
167
|
|
|
$this->assertEquals($articles->count(), 1); |
|
168
|
|
|
$article = $articles->getNext(); |
|
169
|
|
|
$this->assertInstanceOf('Khepin\Fixture\Document\Article', $article); |
|
170
|
|
|
$tags = $article->getTags(); |
|
171
|
|
|
$this->assertEquals('YAML', $tags[0]->getName()); |
|
172
|
|
|
$this->assertEquals($tags->count(), 2); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
View Code Duplication |
public function testConstructor() |
|
|
|
|
|
|
176
|
|
|
{ |
|
177
|
|
|
$loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures'); |
|
178
|
|
|
$loader->loadFixtures('construct'); |
|
179
|
|
|
|
|
180
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Car'); |
|
|
|
|
|
|
181
|
|
|
$car = $repo->findOneByName('Ford'); |
|
182
|
|
|
$this->assertEquals('Ford', $car->getName()); |
|
183
|
|
|
$this->assertInstanceOf('\DateTime', $car->getDatePurchased()); |
|
184
|
|
|
|
|
185
|
|
|
$repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Owner'); |
|
|
|
|
|
|
186
|
|
|
$owner = $repo->findOneByName('Some Small Company'); |
|
187
|
|
|
$this->assertEquals(1, count($owner->getOwnedCars())); |
|
188
|
|
|
$this->assertEquals('Some Small Company', $owner->getName()); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
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.