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 RunOpenCode\Bundle\DoctrineNamingStrategy\NamingStrategy\UnderscoredClassNamespacePrefix; |
13
|
|
|
|
14
|
|
|
class UnderscoredClassNamespacePrefixTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @test |
18
|
|
|
*/ |
19
|
|
|
public function classToTableNameLowercase() |
20
|
|
|
{ |
21
|
|
|
$strategy = new UnderscoredClassNamespacePrefix(array( |
22
|
|
|
'map' => array( |
23
|
|
|
'RunOpenCode\\Bundle\\TestNamespace\\Entity' => 'my_prefix' |
24
|
|
|
) |
25
|
|
|
)); |
26
|
|
|
|
27
|
|
|
$this->assertSame('my_prefix_some_entity', $strategy->classToTableName('RunOpenCode\\Bundle\\TestNamespace\\Entity\\SomeEntity')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function classToTableNameUppercase() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$strategy = new UnderscoredClassNamespacePrefix(array( |
36
|
|
|
'map' => array( |
37
|
|
|
'RunOpenCode\\Bundle\\TestNamespace\\Entity' => 'my_prefix' |
38
|
|
|
), |
39
|
|
|
'case' => CASE_UPPER |
40
|
|
|
)); |
41
|
|
|
|
42
|
|
|
$this->assertSame('MY_PREFIX_SOME_ENTITY', $strategy->classToTableName('RunOpenCode\\Bundle\\TestNamespace\\Entity\\SomeEntity')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @test |
47
|
|
|
* |
48
|
|
|
* @expectedException \RuntimeException |
49
|
|
|
*/ |
50
|
|
|
public function invalidConfiguration() |
51
|
|
|
{ |
52
|
|
|
$strategy = new UnderscoredClassNamespacePrefix(array( |
|
|
|
|
53
|
|
|
'map' => array( |
54
|
|
|
'RunOpenCode\\Bundle\\TestNamespace\\Entity' => 'my_prefix' |
55
|
|
|
), |
56
|
|
|
'blacklist' => array( |
57
|
|
|
'Test\\Bundle' |
58
|
|
|
), |
59
|
|
|
'whitelist' => array( |
60
|
|
|
'Test\\Bundle2' |
61
|
|
|
) |
62
|
|
|
)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function blacklisted() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$strategy = new UnderscoredClassNamespacePrefix(array( |
71
|
|
|
'map' => array( |
72
|
|
|
'RunOpenCode\\Bundle\\TestNamespace\\Entity' => 'my_prefix' |
73
|
|
|
), |
74
|
|
|
'blacklist' => array( |
75
|
|
|
'RunOpenCode\\Bundle' |
76
|
|
|
) |
77
|
|
|
)); |
78
|
|
|
|
79
|
|
|
$this->assertSame('some_entity', $strategy->classToTableName('RunOpenCode\\Bundle\\DoctrineNamingStrategy\\Entity\\SomeEntity')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @test |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function whitelisted() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$strategy = new UnderscoredClassNamespacePrefix(array( |
88
|
|
|
'map' => array( |
89
|
|
|
'RunOpenCode\\Bundle\\TestNamespace\\Entity' => 'my_prefix' |
90
|
|
|
), |
91
|
|
|
'whitelist' => array( |
92
|
|
|
'Test\\Bundle2' |
93
|
|
|
) |
94
|
|
|
)); |
95
|
|
|
|
96
|
|
|
$this->assertSame('some_entity', $strategy->classToTableName('RunOpenCode\\Bundle\\DoctrineNamingStrategy\\Entity\\SomeEntity')); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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.