Completed
Push — master ( 178a08...5c0b6f )
by Oleg
05:22
created

EntityManagerFactoryTest::testExcludedPaths()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace DataFlow\Tests\Unit\Doctrine;
5
6
use SlayerBirden\DataFlowServer\Doctrine\EntityManagerFactory;
7
8
class EntityManagerFactoryTest extends \Codeception\Test\Unit
9
{
10
    /**
11
     * @expectedException \SlayerBirden\DataFlowServer\Doctrine\Exception\MissingDoctrineConfigException
12
     */
13
    public function testMissingDoctrineConfig()
14
    {
15
        $sm = new \Zend\ServiceManager\ServiceManager();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
16
17
        $factory = new EntityManagerFactory();
18
19
        $factory($sm);
20
    }
21
22
    public function testConfigOption()
23
    {
24
        $sm = new \Zend\ServiceManager\ServiceManager();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
25
26
        $sm->setService('config', [
27
            'doctrine' => [
28
                'configuration' => [
29
                    'proxy_dir' => 'path_to_proxy',
30
                    'filter' => [
31
                        'name',
32
                        'CoolNameFilter',
33
                    ]
34
                ],
35
            ],
36
            'db' => [
37
                'url' => 'sqlite:///data/db/db.sqlite',
38
            ],
39
        ]);
40
41
        $factory = new EntityManagerFactory();
42
43
        $em = $factory($sm);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $em. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
44
45
        $this->assertEquals('path_to_proxy', $em->getConfiguration()->getProxyDir());
46
        $this->assertEquals('CoolNameFilter', $em->getConfiguration()->getFilterClassName('name'));
47
    }
48
49
    /**
50
     * @expectedException \SlayerBirden\DataFlowServer\Doctrine\Exception\InvalidArgumentDoctrineConfigException
51
     */
52
    public function testInvalidConfigOption()
53
    {
54
        $sm = new \Zend\ServiceManager\ServiceManager();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
55
56
        $sm->setService('config', [
57
            'doctrine' => [
58
                'configuration' => [
59
                    'non_existing_option' => 'bar'
60
                ],
61
            ]
62
        ]);
63
64
        $factory = new EntityManagerFactory();
65
66
        $factory($sm);
67
    }
68
69
    /**
70
     * @expectedException \SlayerBirden\DataFlowServer\Doctrine\Exception\InvalidArgumentDoctrineConfigException
71
     */
72
    public function testInvalidConfigOptionType()
73
    {
74
        $sm = new \Zend\ServiceManager\ServiceManager();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
75
76
        $sm->setService('config', [
77
            'doctrine' => [
78
                'configuration' => [
79
                    'metadata_driver_impl' => 'driver'
80
                ],
81
            ]
82
        ]);
83
84
        $factory = new EntityManagerFactory();
85
86
        $factory($sm);
87
    }
88
89
90
    /**
91
     * @throws \Doctrine\ORM\ORMException
92
     */
93
    public function testConfigOptionFromServiceManager()
94
    {
95
        $sm = new \Zend\ServiceManager\ServiceManager();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
96
97
        $driver = $this->createMock(\Doctrine\Common\Persistence\Mapping\Driver\MappingDriver::class);
98
99
        $sm->setService('driver', $driver);
100
101
        $sm->setService('config', [
102
            'doctrine' => [
103
                'configuration' => [
104
                    'metadata_driver_impl' => 'driver'
105
                ],
106
            ],
107
            'db' => [
108
                'url' => 'sqlite:///data/db/db.sqlite',
109
            ],
110
        ]);
111
112
        $factory = new EntityManagerFactory();
113
114
        $em = $factory($sm);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $em. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
115
116
        $this->assertInstanceOf(
117
            \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver::class,
118
            $em->getConfiguration()->getMetadataDriverImpl()
119
        );
120
    }
121
122
    /**
123
     * @throws \Doctrine\ORM\ORMException
124
     */
125
    public function testExcludedPaths()
126
    {
127
        $sm = new \Zend\ServiceManager\ServiceManager();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
128
129
        $pathToExclude = [
130
            'path_to_tests',
131
            'path_to_logs',
132
        ];
133
134
        $sm->setService('config', [
135
            'doctrine' => [
136
                'excludePaths' => $pathToExclude,
137
            ],
138
            'db' => [
139
                'url' => 'sqlite:///data/db/db.sqlite',
140
            ],
141
        ]);
142
143
        $factory = new EntityManagerFactory();
144
145
        $em = $factory($sm);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $em. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
146
147
        $driver = $em->getConfiguration()->getMetadataDriverImpl();
148
        if ($driver instanceof \Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver) {
149
            $this->assertEquals($pathToExclude, $driver->getExcludePaths());
150
        }
151
    }
152
}
153