1 | <?php |
||
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 |