Completed
Pull Request — 2.x (#93)
by
unknown
02:09
created

OrmMetadataTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 3 Features 2
Metric Value
wmc 14
c 7
b 3
f 2
lcom 1
cbo 1
dl 0
loc 174
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testEntityNames() 0 10 1
A testDirectoryWithDotInPath() 0 10 1
A testGetMappingEntityDirectory() 0 11 1
A testGetExtendedMappingEntityDirectory() 0 11 1
A testGetEntityDirectory() 0 11 1
A testGetExtendedEntityDirectory() 0 11 1
A testGetExtendedSerializerDirectory() 0 11 1
A testGetEntityMappingFiles() 0 18 2
A testGetEntityMappingFilesWithFilesNotFound() 0 9 1
A testGetRepositoryFiles() 0 18 2
A testGetRepositoryFilesWithFilesNotFound() 0 9 1
B getBundleMetadataMock() 0 26 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\EasyExtendsBundle\Tests\Bundle;
13
14
use Sonata\EasyExtendsBundle\Bundle\BundleMetadata;
15
use Sonata\EasyExtendsBundle\Bundle\OrmMetadata;
16
17
class OrmMetadataTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testEntityNames()
20
    {
21
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock(__DIR__.'/Fixtures/bundle1'));
22
23
        $entityNames = $ormMetadata->getEntityNames();
24
25
        $this->assertEquals(4, count($entityNames));
26
        $this->assertContains('Block', $entityNames);
27
        $this->assertContains('Page', $entityNames);
28
    }
29
30
    public function testDirectoryWithDotInPath()
31
    {
32
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock(__DIR__.'/Fixtures/bundle2/dot.dot'));
33
34
        $entityNames = $ormMetadata->getEntityNames();
35
36
        $this->assertEquals(4, count($entityNames));
37
        $this->assertContains('Block', $entityNames);
38
        $this->assertContains('Page', $entityNames);
39
    }
40
41
    public function testGetMappingEntityDirectory()
42
    {
43
        $bundlePath = __DIR__.'/Fixtures/bundle1';
44
        $expectedDirectory = $bundlePath.'/Resources/config/doctrine/';
45
46
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock($bundlePath));
47
48
        $directory = $ormMetadata->getMappingEntityDirectory();
49
50
        $this->assertEquals($expectedDirectory, $directory);
51
    }
52
53
    public function testGetExtendedMappingEntityDirectory()
54
    {
55
        $bundlePath = __DIR__.'/Fixtures/bundle1';
56
        $expectedDirectory = 'Application/Sonata/AcmeBundle/Resources/config/doctrine/';
57
58
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock($bundlePath));
59
60
        $directory = $ormMetadata->getExtendedMappingEntityDirectory();
61
62
        $this->assertEquals($expectedDirectory, $directory);
63
    }
64
65
    public function testGetEntityDirectory()
66
    {
67
        $bundlePath = __DIR__.'/Fixtures/bundle1';
68
        $expectedDirectory = $bundlePath.'/Entity';
69
70
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock($bundlePath));
71
72
        $directory = $ormMetadata->getEntityDirectory();
73
74
        $this->assertEquals($expectedDirectory, $directory);
75
    }
76
77
    public function testGetExtendedEntityDirectory()
78
    {
79
        $bundlePath = __DIR__.'/Fixtures/bundle1';
80
        $expectedDirectory = 'Application/Sonata/AcmeBundle/Entity';
81
82
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock($bundlePath));
83
84
        $directory = $ormMetadata->getExtendedEntityDirectory();
85
86
        $this->assertEquals($expectedDirectory, $directory);
87
    }
88
89
    public function testGetExtendedSerializerDirectory()
90
    {
91
        $bundlePath = __DIR__.'/Fixtures/bundle1';
92
        $expectedDirectory = 'Application/Sonata/AcmeBundle/Resources/config/serializer';
93
94
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock($bundlePath));
95
96
        $directory = $ormMetadata->getExtendedSerializerDirectory();
97
98
        $this->assertEquals($expectedDirectory, $directory);
99
    }
100
101
    public function testGetEntityMappingFiles()
102
    {
103
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock(__DIR__.'/Fixtures/bundle1'));
104
105
        $filterIterator = $ormMetadata->getEntityMappingFiles();
106
107
        $files = array();
108
        foreach ($filterIterator as $file) {
109
            $files[] = $file->getFilename();
110
        }
111
112
        $this->assertInstanceOf('Iterator', $filterIterator);
113
        $this->assertContainsOnly('Symfony\Component\Finder\SplFileInfo', $filterIterator);
114
        $this->assertContains('Block.orm.xml.skeleton', $files);
115
        $this->assertContains('Page.orm.xml.skeleton', $files);
116
        $this->assertNotContains('Block.mongodb.xml.skeleton', $files);
117
        $this->assertNotContains('Page.mongodb.xml.skeleton', $files);
118
    }
119
120
    public function testGetEntityMappingFilesWithFilesNotFound()
121
    {
122
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock(__DIR__.'/Fixtures'));
123
124
        $result = $ormMetadata->getEntityMappingFiles();
125
126
        $this->assertInternalType('array', $result);
127
        $this->assertEmpty($result);
128
    }
129
130
    public function testGetRepositoryFiles()
131
    {
132
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock(__DIR__.'/Fixtures/bundle1'));
133
134
        $filterIterator = $ormMetadata->getRepositoryFiles();
135
136
        $files = array();
137
        foreach ($filterIterator as $file) {
138
            $files[] = $file->getFilename();
139
        }
140
141
        $this->assertInstanceOf('Iterator', $filterIterator);
142
        $this->assertContainsOnly('Symfony\Component\Finder\SplFileInfo', $filterIterator);
143
        $this->assertContains('BlockRepository.php', $files);
144
        $this->assertContains('PageRepository.php', $files);
145
        $this->assertNotContains('Block.php', $files);
146
        $this->assertNotContains('Page.php', $files);
147
    }
148
149
    public function testGetRepositoryFilesWithFilesNotFound()
150
    {
151
        $ormMetadata = new OrmMetadata($this->getBundleMetadataMock(__DIR__.'/Fixtures'));
152
153
        $result = $ormMetadata->getRepositoryFiles();
154
155
        $this->assertInternalType('array', $result);
156
        $this->assertEmpty($result);
157
    }
158
159
    /**
160
     * @param string $bundlePath
161
     *
162
     * @return BundleMetadata
163
     */
164
    private function getBundleMetadataMock($bundlePath)
165
    {
166
        $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
167
        $bundle->expects($this->any())
168
            ->method('getPath')
169
            ->will($this->returnValue($bundlePath));
170
171
        $bundleMetadata = $this->getMock(
172
            'Sonata\EasyExtendsBundle\Bundle\BundleMetadata',
173
            array(),
174
            array($bundle),
175
            '',
176
            true
177
        );
178
        $bundleMetadata->expects($this->any())
179
            ->method('getBundle')
180
            ->will($this->returnValue($bundle));
181
        $bundleMetadata->expects($this->any())
182
            ->method('getClass')
183
            ->will($this->returnValue('Sonata\\AcmeBundle\\SonataAcmeBundle'));
184
        $bundleMetadata->expects($this->any())
185
            ->method('getExtendedDirectory')
186
            ->will($this->returnValue('Application/Sonata/AcmeBundle'));
187
188
        return $bundleMetadata;
189
    }
190
}
191