Completed
Push — master ( f496a8...4f1947 )
by Sebastien
03:00 queued 01:27
created

MongoFixtureTest::testConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 11
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\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(
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__ . '/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();
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...
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()
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...
55
    {
56
        $loader = new YamlLoader($this->kernel, array('SomeBundle/cars'), 'DataFixtures');
57
        $loader->loadFixtures();
58
59
        $dm = $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...
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()
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...
67
    {
68
        $loader = new YamlLoader($this->kernel, array('SomeBundle/cars', 'SomeBundle'), 'DataFixtures');
69
        $loader->loadFixtures();
70
71
        $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...
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()
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...
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();
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...
85
        $this->assertEquals(count($cars), 0);
86
87
        $drivers = $this->doctrine->getManager()->getRepository('Khepin\Fixture\Document\Driver')->findAll();
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...
88
        $this->assertEquals(count($drivers), 0);
89
    }
90
91 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...
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');
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...
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');
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...
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');
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...
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()
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...
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');
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...
140
        $car = $repo->findOneBy(array('name' => 'toyota'));
141
        $this->assertTrue('toyota' === $car->getName());
142
    }
143
144 View Code Duplication
    public function testEmbedOne()
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...
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');
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...
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()
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...
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');
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...
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()
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...
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');
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...
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');
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...
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