1212namespace Florianv \SwapBundle \Tests \DependencyInjection ;
1313
1414use Florianv \SwapBundle \DependencyInjection \FlorianvSwapExtension ;
15+ use PHPUnit \Framework \TestCase ;
1516use Swap \Builder ;
1617use Swap \Swap ;
1718use Symfony \Component \Cache \Adapter ;
1819use Symfony \Component \Cache \Adapter \ApcuAdapter ;
20+ use Symfony \Component \Cache \Psr16Cache ;
1921use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
2022use Symfony \Component \DependencyInjection \ContainerBuilder ;
2123use Symfony \Component \DependencyInjection \Definition ;
2224use Symfony \Component \DependencyInjection \Reference ;
2325
24- class FlorianvSwapExtensionTest extends \PHPUnit_Framework_TestCase
26+ class FlorianvSwapExtensionTest extends TestCase
2527{
2628 /**
2729 * @var ContainerBuilder
@@ -33,54 +35,69 @@ class FlorianvSwapExtensionTest extends \PHPUnit_Framework_TestCase
3335 */
3436 private $ extension ;
3537
36- protected function setUp ()
38+ protected function setUp (): void
3739 {
3840 $ this ->container = new ContainerBuilder ();
3941 $ this ->extension = new FlorianvSwapExtension ();
4042 }
4143
42- public function testBuilderService ()
44+ /**
45+ * @throws \Exception
46+ */
47+ public function testBuilderService (): void
4348 {
4449 $ this ->buildContainer ();
4550
46- /** @var \Swap\ Builder $builder */
51+ /** @var Builder $builder */
4752 $ builder = $ this ->container ->get ('florianv_swap.builder ' );
4853
49- $ this -> assertInstanceOf (Builder::class, $ builder );
54+ self :: assertInstanceOf (Builder::class, $ builder );
5055 }
5156
52- public function testSwapService ()
57+ /**
58+ * @throws \Exception
59+ */
60+ public function testSwapService (): void
5361 {
5462 $ this ->buildContainer ();
5563
56- /** @var \Swap\ Swap $swap */
64+ /** @var Swap $swap */
5765 $ swap = $ this ->container ->get ('florianv_swap.swap ' );
58- $ this -> assertInstanceOf (Swap::class, $ swap );
66+ self :: assertInstanceOf (Swap::class, $ swap );
5967 }
6068
61- public function testNoProvider ()
69+ public function testNoProvider (): void
6270 {
6371 $ this ->expectException (InvalidConfigurationException::class);
6472
6573 $ this ->buildContainer ([], []);
6674 }
6775
68- public function testFixerProvider ()
76+ /**
77+ * @doesNotPerformAssertions
78+ */
79+ public function testFixerProvider (): void
6980 {
7081 $ this ->buildContainer (['fixer ' => ['access_key ' => 'test ' ]]);
7182 }
7283
73- public function testForgeProvider ()
84+ /**
85+ * @doesNotPerformAssertions
86+ */
87+ public function testForgeProvider (): void
7488 {
7589 $ this ->buildContainer (['forge ' => ['api_key ' => 'test ' ]]);
7690 }
7791
78- public function testXchangeApiProvider ()
92+ /**
93+ * @doesNotPerformAssertions
94+ */
95+ public function testXchangeApiProvider (): void
7996 {
8097 $ this ->buildContainer (['xchangeapi ' => ['api-key ' => 'test ' ]]);
8198 }
8299
83- public function testProviderPriorities ()
100+ public function testProviderPriorities (): void
84101 {
85102 $ this ->buildContainer ([
86103 'fixer ' => ['access_key ' => 'YOUR_KEY ' ],
@@ -97,47 +114,56 @@ public function testProviderPriorities()
97114 $ calls = $ swap ->getMethodCalls ();
98115
99116 // European Central Bank first
100- $ this -> assertEquals ($ calls [0 ][0 ], ' add ' );
101- $ this -> assertEquals ($ calls [0 ][1 ][0 ], ' european_central_bank ' );
102- $ this -> assertEquals ($ calls [0 ][1 ][1 ], [ ]);
117+ self :: assertEquals (' add ' , $ calls [0 ][0 ]);
118+ self :: assertEquals (' european_central_bank ' , $ calls [0 ][1 ][0 ]);
119+ self :: assertEquals ([], $ calls [0 ][1 ][1 ]);
103120
104121 // Forge second
105- $ this -> assertEquals ($ calls [1 ][0 ], ' add ' );
106- $ this -> assertEquals ($ calls [1 ][1 ][0 ], ' forge ' );
107- $ this -> assertEquals ($ calls [ 1 ][ 1 ][ 1 ], [ 'api_key ' => 'test ' ]);
122+ self :: assertEquals (' add ' , $ calls [1 ][0 ]);
123+ self :: assertEquals (' forge ' , $ calls [1 ][1 ][0 ]);
124+ self :: assertEquals ([ 'api_key ' => 'test ' ], $ calls [ 1 ][ 1 ][ 1 ]);
108125
109126 // Fixer third
110- $ this -> assertEquals ($ calls [2 ][0 ], ' add ' );
111- $ this -> assertEquals ($ calls [2 ][1 ][0 ], ' fixer ' );
112- $ this -> assertEquals ($ calls [ 2 ][ 1 ][ 1 ], [ 'access_key ' => 'YOUR_KEY ' , 'enterprise ' => false ]);
127+ self :: assertEquals (' add ' , $ calls [2 ][0 ]);
128+ self :: assertEquals (' fixer ' , $ calls [2 ][1 ][0 ]);
129+ self :: assertEquals ([ 'access_key ' => 'YOUR_KEY ' , 'enterprise ' => false ], $ calls [ 2 ][ 1 ][ 1 ]);
113130 }
114131
115- public function testCacheMissTtl ()
132+ public function testCacheMissTtl (): void
116133 {
117134 $ this ->expectException (InvalidConfigurationException::class);
118135
119136 $ this ->buildContainer (['fixer ' => ['access_key ' => 'YOUR_KEY ' ]], ['ttl ' => null ]);
120137 }
121138
122- public function testArrayCache ()
139+ /**
140+ * @throws \Exception
141+ */
142+ public function testArrayCache (): void
123143 {
124144 $ this ->buildContainer (['fixer ' => ['access_key ' => 'YOUR_KEY ' ]], ['type ' => 'array ' , 'ttl ' => 60 ]);
125145
126146 $ this ->assertCache (Adapter \ArrayAdapter::class, [60 ]);
127147 }
128148
129- public function testApcuCache ()
149+ /**
150+ * @throws \Exception
151+ */
152+ public function testApcuCache (): void
130153 {
131154 if (!ApcuAdapter::isSupported ()) {
132- $ this -> markTestSkipped ('APCU is not enabled ' );
155+ self :: markTestSkipped ('APCU is not enabled ' );
133156 }
134157
135158 $ this ->buildContainer (['fixer ' => ['access_key ' => 'YOUR_KEY ' ]], ['type ' => 'apcu ' ]);
136159
137160 $ this ->assertCache (Adapter \ApcuAdapter::class, ['swap ' , 3600 ]);
138161 }
139162
140- public function testFilesystemCache ()
163+ /**
164+ * @throws \Exception
165+ */
166+ public function testFilesystemCache (): void
141167 {
142168 $ this ->buildContainer (['fixer ' => ['access_key ' => 'YOUR_KEY ' ]], ['type ' => 'filesystem ' ]);
143169
@@ -150,7 +176,7 @@ public function testFilesystemCache()
150176 * @param array $providers
151177 * @param array $cache
152178 */
153- private function buildContainer (array $ providers = ['fixer ' => ['access_key ' => 'test ' ]], array $ cache = [])
179+ private function buildContainer (array $ providers = ['fixer ' => ['access_key ' => 'test ' ]], array $ cache = []): void
154180 {
155181 $ this ->extension ->load ([
156182 'florianv_swap ' => [
@@ -167,24 +193,25 @@ private function buildContainer(array $providers = ['fixer' => ['access_key' =>
167193 * @param $config
168194 * @throws \Exception
169195 */
170- private function assertCache ($ class , $ config )
196+ private function assertCache ($ class , $ config ): void
171197 {
172198 $ swap = $ this ->container ->getDefinition ('florianv_swap.builder ' );
173199 $ calls = $ swap ->getMethodCalls ();
174- $ this ->assertEquals ($ calls [0 ][0 ], 'useSimpleCache ' );
200+ self ::assertEquals ('useSimpleCache ' , $ calls [0 ][0 ]);
201+
175202 /** @var Reference $cacheReference */
176203 $ cacheReference = $ calls [0 ][1 ][0 ];
177- $ this -> assertEquals ('florianv_swap.cache ' , (string )$ cacheReference );
204+ self :: assertEquals ('florianv_swap.cache ' , (string )$ cacheReference );
178205
179206 /** @var Definition */
180207 $ cacheDefinition = $ this ->container ->getDefinition ('florianv_swap.cache ' );
181- $ this -> assertEquals ($ cacheDefinition ->getClass (), ' Symfony\Component\Cache\Psr16Cache ' );
182- $ this -> assertEquals ($ cacheDefinition ->getArgument (0 )->getClass (), $ class );
183- $ this -> assertFalse ($ cacheDefinition ->isPublic ());
208+ self :: assertEquals (Psr16Cache::class, $ cacheDefinition ->getClass ());
209+ self :: assertEquals ($ class , $ cacheDefinition ->getArgument (0 )->getClass ());
210+ self :: assertFalse ($ cacheDefinition ->isPublic ());
184211
185- $ this -> assertEquals ($ config , $ cacheDefinition ->getArgument (0 )->getArguments ());
212+ self :: assertEquals ($ config , $ cacheDefinition ->getArgument (0 )->getArguments ());
186213
187214 $ cache = $ this ->container ->get ('florianv_swap.cache ' );
188- $ this -> assertInstanceOf (' Symfony\Component\Cache\ Psr16Cache' , $ cache );
215+ self :: assertInstanceOf (Psr16Cache::class , $ cache );
189216 }
190217}
0 commit comments