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( |
|
|
|
|
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
|
|
View Code Duplication |
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(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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.