Completed
Branch master (c90b3f)
by Nikola
05:04 queued 02:56
created

UnderscoredBundleNamePrefixTest::classToTableNameLowercase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Doctrine Naming Strategy Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\DoctrineNamingStrategy\Tests\NamingStrategy;
11
12
use Symfony\Component\HttpKernel\Kernel;
13
use RunOpenCode\Bundle\DoctrineNamingStrategy\NamingStrategy\UnderscoredBundleNamePrefix;
14
use RunOpenCode\Bundle\DoctrineNamingStrategy\DoctrineNamingStrategyBundle;
15
16
class UnderscoredBundleNamePrefixTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @test
20
     */
21
    public function classToTableNameLowercase()
22
    {
23
        $strategy = new UnderscoredBundleNamePrefix($this->mockKernel(), array(
24
            'map' => array(
25
                'DoctrineNamingStrategyBundle' => 'my_prefix'
26
            )
27
        ));
28
29
        $this->assertSame('my_prefix_some_entity', $strategy->classToTableName('RunOpenCode\\Bundle\\DoctrineNamingStrategy\\Entity\\SomeEntity'));
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function classToTableNameUppercase()
36
    {
37
        $strategy = new UnderscoredBundleNamePrefix($this->mockKernel(), array(
38
            'map' => array(
39
                'DoctrineNamingStrategyBundle' => 'my_prefix',
40
            ),
41
            'case' => CASE_UPPER
42
        ));
43
44
        $this->assertSame('MY_PREFIX_SOME_ENTITY', $strategy->classToTableName('RunOpenCode\\Bundle\\DoctrineNamingStrategy\\Entity\\SomeEntity'));
45
    }
46
47
    /**
48
     * @test
49
     *
50
     * @expectedException \RuntimeException
51
     */
52
    public function invalidConfiguration()
53
    {
54
        new UnderscoredBundleNamePrefix($this->mockKernel(), array(
55
            'map' => array(
56
                'DoctrineNamingStrategyBundle' => 'my_prefix'
57
            ),
58
            'blacklist' => array(
59
                'DoctrineNamingStrategyBundle'
60
            ),
61
            'whitelist' => array(
62
                'DoctrineNamingStrategyBundle'
63
            )
64
        ));
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function blacklisted()
71
    {
72
        $strategy = new UnderscoredBundleNamePrefix($this->mockKernel(), array(
73
            'map' => array(
74
                'DoctrineNamingStrategyBundle' => 'my_prefix'
75
            ),
76
            'blacklist' => array(
77
                'DoctrineNamingStrategyBundle'
78
            )
79
        ));
80
81
        $this->assertSame('some_entity', $strategy->classToTableName('RunOpenCode\\Bundle\\DoctrineNamingStrategy\\Entity\\SomeEntity'));
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function whitelisted()
88
    {
89
        $strategy = new UnderscoredBundleNamePrefix($this->mockKernel(), array(
90
            'map' => array(
91
                'DoctrineNamingStrategyBundle' => 'my_prefix'
92
            ),
93
            'whitelist' => array(
94
                'SomeNonExistingBundle'
95
            )
96
        ));
97
98
        $this->assertSame('some_entity', $strategy->classToTableName('RunOpenCode\\Bundle\\DoctrineNamingStrategy\\Entity\\SomeEntity'));
99
    }
100
101
    private function mockKernel()
102
    {
103
        $stub = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')->disableOriginalConstructor()->getMock();
104
105
        $stub->method('getBundles')
106
            ->willReturn(array(
107
                new DoctrineNamingStrategyBundle()  // For now, it is not possible to mock with namespace, so we will use bundle's bundle class
108
            ));
109
110
        return $stub;
111
    }
112
}
113