YamlFixtureTest::testWithAssociation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Khepin\Tests;
4
5
use \Mockery as m;
6
use Khepin\YamlFixturesBundle\Loader\YamlLoader;
7
use Khepin\Utils\BaseTestCaseOrm;
8
9
/**
10
 * @group orm
11
 */
12
class YamlFixtureTest extends BaseTestCaseOrm
13
{
14
    protected $kernel = null;
15
16
    public function setUp()
17
    {
18
        $this->getDoctrine();
19
        $service = m::mock()->shouldReceive('lowerCaseName')->withAnyArgs()->andReturnUsing(
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Mockery\Expectation>.

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...
20
            function ($car) {
21
                    $car->setName(strtolower($car->getName()));
22
            }
23
        )->mock();
24
        $container = m::mock('Container')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
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__ . '/simple_loading/',
32
                    'getContainer'   => $container
33
            )
34
        );
35
    }
36
37
    public function testSimpleLoading()
38
    {
39
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
40
        $loader->loadFixtures();
41
42
        $em = $this->doctrine->getEntityManager();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
43
        $cars = $em->getRepository('Khepin\Fixture\Entity\Car')->findAll();
44
        $this->assertEquals(2, count($cars));
45
        $car = $cars[0];
46
        $this->assertEquals('Mercedes', $car->getName());
47
        $date = new \DateTime('2012-01-01');
48
        $this->assertEquals($date, $car->getDatePurchased());
49
        $this->assertEquals(get_class($date), get_class($car->getDatePurchased()));
50
51
        $car = $cars[1];
52
        $this->assertEquals('BMW', $car->getName());
53
    }
54
55 View Code Duplication
    public function testLoadSingleFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $loader = new YamlLoader($this->kernel, array('SomeBundle/cars'), 'DataFixtures');
58
        $loader->loadFixtures();
59
60
        $em = $this->doctrine->getManager();
0 ignored issues
show
Bug introduced by
The method getManager() does not seem to exist on object<Mockery\MockInterface>.

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...
61
        $cars = $em->getRepository('Khepin\Fixture\Entity\Car')->findAll();
62
        $this->assertEquals(2, count($cars));
63
        $drivers = $em->getRepository('Khepin\Fixture\Entity\Driver')->findAll();
64
        $this->assertEquals(0, count($drivers));
65
    }
66
67 View Code Duplication
    public function testSingleFileLoadedOnlyOnce()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $loader = new YamlLoader($this->kernel, array('SomeBundle/cars', 'SomeBundle'), 'DataFixtures');
70
        $loader->loadFixtures();
71
72
        $em = $this->doctrine->getManager();
0 ignored issues
show
Bug introduced by
The method getManager() does not seem to exist on object<Mockery\MockInterface>.

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...
73
        $cars = $em->getRepository('Khepin\Fixture\Entity\Car')->findAll();
74
        $this->assertEquals(2, count($cars));
75
        $drivers = $em->getRepository('Khepin\Fixture\Entity\Driver')->findAll();
76
        $this->assertEquals(0, count($drivers));
77
    }
78
79 View Code Duplication
    public function testContext()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
82
        $loader->loadFixtures('french_cars');
83
84
        $repo = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Car');
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
85
        $cars = $repo->findAll();
86
        $this->assertEquals(4, count($cars));
87
88
        $car = $repo->findOneBy(array('name' => 'Peugeot'));
89
        $this->assertEquals('Peugeot', $car->getName());
90
91
        $car = $repo->findOneBy(array('name' => 'BMW'));
92
        $this->assertEquals('BMW', $car->getName());
93
    }
94
95 View Code Duplication
    public function testWithAssociation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
98
        $loader->loadFixtures('with_drivers');
99
100
        $repo = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Driver');
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
101
        $driver = $repo->findOneBy(array('name' => 'Mom'));
102
        $this->assertEquals($driver->getCar()->getName(), 'Mercedes');
103
        $driver = $repo->findOneBy(array('name' => 'Dad'));
104
        $this->assertEquals($driver->getCar()->getName(), 'BMW');
105
106
        $this->assertEquals(get_class($driver->getCar()), 'Khepin\Fixture\Entity\Car');
107
    }
108
109 View Code Duplication
    public function testPurge()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
112
        $loader->loadFixtures('with_drivers');
113
        $loader->purgeDatabase('orm');
114
115
        $cars = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Car')->findAll();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
116
        $this->assertEmpty($cars);
117
        $drivers = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Driver')->findAll();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
118
        $this->assertEmpty($drivers);
119
    }
120
121
    public function testPurgeWithTruncate()
122
    {
123
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
124
        $loader->loadFixtures('with_drivers');
125
126
        $cars = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Car')->findAll();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
127
        $firstCar = $cars[0];
128
        $firstCarIdBefore = $firstCar->getId();
129
130
        $loader->purgeDatabase('orm', null, true);
131
132
        $cars = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Car')->findAll();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
133
        $this->assertEmpty($cars);
134
135
        $loader->loadFixtures('with_drivers');
136
137
        $cars = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Car')->findAll();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
138
        $firstCar = $cars[0];
139
        $firstCarIdAfter = $firstCar->getId();
140
141
        $this->assertEquals($firstCarIdBefore, $firstCarIdAfter);
142
    }
143
144
    public function testNullValuesInAssociations()
145
    {
146
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
147
        $loader->loadFixtures('with_drivers');
148
149
        $repo = $this->doctrine->getEntityManager()->getRepository('Khepin\Fixture\Entity\Driver');
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
150
151
        $driver = $repo->findOneBy(array('name' => 'Mom'));
152
        $this->assertEquals(get_class($driver->getCar()), 'Khepin\Fixture\Entity\Car');
153
        $this->assertEquals($driver->getCar()->getName(), 'Mercedes');
154
        $this->assertEquals($driver->getSecondCar(), null);
155
156
        $driver = $repo->findOneBy(array('name' => 'Son'));
157
        $this->assertEquals(get_class($driver->getCar()), 'Khepin\Fixture\Entity\Car');
158
        $this->assertEquals($driver->getCar()->getName(), 'BMW');
159
        $this->assertEquals($driver->getSecondCar(), null);
160
161
        $driver = $repo->findOneBy(array('name' => 'Dad'));
162
        $this->assertEquals(get_class($driver->getCar()), 'Khepin\Fixture\Entity\Car');
163
        $this->assertEquals($driver->getCar()->getName(), 'BMW');
164
        $this->assertEquals(get_class($driver->getSecondCar()), 'Khepin\Fixture\Entity\Car');
165
        $this->assertEquals($driver->getSecondCar()->getName(), 'Mercedes');
166
    }
167
168 View Code Duplication
    public function testServiceCalls()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
    {
170
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
171
        $loader->loadFixtures('service');
172
173
        $repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Entity\Car');
0 ignored issues
show
Bug introduced by
The method getManager() does not seem to exist on object<Mockery\MockInterface>.

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...
174
        $car = $repo->findOneByName('toyota');
175
        $this->assertTrue('toyota' === $car->getName());
176
    }
177
178
    public function testArrayAssociation()
179
    {
180
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
181
        $loader->loadFixtures();
182
183
        $em   = $this->doctrine->getEntityManager();
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not seem to exist on object<Mockery\MockInterface>.

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...
184
        $owner = $em->getRepository('Khepin\Fixture\Entity\Owner')->findOneById(1);
185
        $this->assertEquals(2, count($owner->getOwnedCars()));
186
187
        $car1 = $owner->getOwnedCars()->get(0);
188
        $this->assertEquals(get_class($car1), 'Khepin\Fixture\Entity\Car');
189
        $this->assertEquals('Mercedes', $car1->getName());
190
191
        $car2 = $owner->getOwnedCars()->get(1);
192
        $this->assertEquals(get_class($car2), 'Khepin\Fixture\Entity\Car');
193
        $this->assertEquals('BMW', $car2->getName());
194
    }
195
196 View Code Duplication
    public function testConstructor()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
197
    {
198
        $loader = new YamlLoader($this->kernel, array('SomeBundle'), 'DataFixtures');
199
        $loader->loadFixtures('construct');
200
201
        $repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Entity\Car');
0 ignored issues
show
Bug introduced by
The method getManager() does not seem to exist on object<Mockery\MockInterface>.

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...
202
        $car = $repo->findOneByName('Ford');
203
        $this->assertEquals('Ford', $car->getName());
204
        $this->assertInstanceOf('\DateTime', $car->getDatePurchased());
205
206
        $repo = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Entity\Owner');
0 ignored issues
show
Bug introduced by
The method getManager() does not seem to exist on object<Mockery\MockInterface>.

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...
207
        $owner = $repo->findOneByName('Some Small Company');
208
        $this->assertEquals(1, count($owner->getOwnedCars()));
209
        $this->assertEquals('Some Small Company', $owner->getName());
210
    }
211
}
212