Completed
Branch master (ffbd82)
by Nikola
14:42 queued 12:20
created

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
        $strategy = new UnderscoredBundleNamePrefix($this->mockKernel(), array(
0 ignored issues
show
Unused Code introduced by
$strategy is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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()
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...
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(Kernel::class)->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