Skip to content

Commit 6a2d6ec

Browse files
authored
Merge pull request #43 from romainf/php-8.0
Php 8.0
2 parents c39c076 + d03beb6 commit 6a2d6ec

File tree

4 files changed

+88
-53
lines changed

4 files changed

+88
-53
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ matrix:
1212
- php: 7.1
1313
- php: 7.2
1414
- php: 7.3
15+
- php: 7.4
16+
- php: 8.0
1517

1618
cache:
1719
directories:

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Florianv\SwapBundle\Tests\DependencyInjection;
1313

1414
use Florianv\SwapBundle\DependencyInjection\Configuration;
15+
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Config\Definition\Exception\Exception;
1617
use Symfony\Component\Config\Definition\Processor;
1718

@@ -20,25 +21,25 @@
2021
* @package Tests\DependencyInjection
2122
* @author Etienne Dauvergne <[email protected]>
2223
*/
23-
class ConfigurationTest extends \PHPUnit_Framework_TestCase
24+
class ConfigurationTest extends TestCase
2425
{
2526
/**
26-
* @var Configuration
27+
* @var ?Configuration
2728
*/
2829
private $configuration;
2930

3031
/**
31-
* @var Processor
32+
* @var ?Processor
3233
*/
3334
private $processor;
3435

35-
protected function setUp()
36+
protected function setUp(): void
3637
{
3738
$this->configuration = new Configuration();
3839
$this->processor = new Processor();
3940
}
4041

41-
protected function tearDown()
42+
protected function tearDown(): void
4243
{
4344
$this->configuration = null;
4445
$this->processor = null;
@@ -49,21 +50,24 @@ protected function tearDown()
4950
*
5051
* @dataProvider provideValidProvidersConfigs
5152
*/
52-
public function testValidProvidersConfig(array $providers)
53+
public function testValidProvidersConfig(array $providers): void
5354
{
54-
$this->processor->processConfiguration($this->configuration, [
55+
$configuration = $this->processor->processConfiguration($this->configuration, [
5556
'florianv_swap' => [
5657
'providers' => $providers,
5758
],
5859
]);
60+
61+
self::assertTrue(is_array($configuration));
62+
5963
}
6064

6165
/**
6266
* @param array $providers
6367
*
6468
* @dataProvider provideInvalidProvidersConfigs
6569
*/
66-
public function testInvalidProvidersConfig(array $providers)
70+
public function testInvalidProvidersConfig(array $providers): void
6771
{
6872
$this->expectException(Exception::class);
6973

@@ -79,22 +83,24 @@ public function testInvalidProvidersConfig(array $providers)
7983
*
8084
* @dataProvider provideValidCacheConfigs
8185
*/
82-
public function testValidCacheConfig(array $cache)
86+
public function testValidCacheConfig(array $cache): void
8387
{
84-
$this->processor->processConfiguration($this->configuration, [
88+
$configuration = $this->processor->processConfiguration($this->configuration, [
8589
'florianv_swap' => [
8690
'providers' => ['fixer' => ['access_key' => 'YOUR_KEY']],
8791
'cache' => $cache,
8892
],
8993
]);
94+
95+
self::assertTrue(is_array($configuration));
9096
}
9197

9298
/**
9399
* @param array $cache
94100
*
95101
* @dataProvider provideInvalidCacheConfigs
96102
*/
97-
public function testInvalidCacheConfig(array $cache)
103+
public function testInvalidCacheConfig(array $cache): void
98104
{
99105
$this->expectException(Exception::class);
100106

@@ -106,7 +112,7 @@ public function testInvalidCacheConfig(array $cache)
106112
]);
107113
}
108114

109-
public function provideValidProvidersConfigs()
115+
public function provideValidProvidersConfigs(): array
110116
{
111117
return [
112118
[['central_bank_of_czech_republic' => null]],
@@ -153,7 +159,7 @@ public function provideValidProvidersConfigs()
153159
];
154160
}
155161

156-
public function provideInvalidProvidersConfigs()
162+
public function provideInvalidProvidersConfigs(): array
157163
{
158164
return [
159165
[[]],
@@ -184,15 +190,15 @@ public function provideInvalidProvidersConfigs()
184190
];
185191
}
186192

187-
public function provideValidCacheConfigs()
193+
public function provideValidCacheConfigs(): array
188194
{
189195
return [
190196
[[]],
191197
[['ttl' => 60, 'type' => 'array']],
192198
];
193199
}
194200

195-
public function provideInvalidCacheConfigs()
201+
public function provideInvalidCacheConfigs(): array
196202
{
197203
return [
198204
[['any' => 'any']],

Tests/DependencyInjection/FlorianvSwapExtensionTest.php

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
namespace Florianv\SwapBundle\Tests\DependencyInjection;
1313

1414
use Florianv\SwapBundle\DependencyInjection\FlorianvSwapExtension;
15+
use PHPUnit\Framework\TestCase;
1516
use Swap\Builder;
1617
use Swap\Swap;
1718
use Symfony\Component\Cache\Adapter;
1819
use Symfony\Component\Cache\Adapter\ApcuAdapter;
20+
use Symfony\Component\Cache\Psr16Cache;
1921
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
2022
use Symfony\Component\DependencyInjection\ContainerBuilder;
2123
use Symfony\Component\DependencyInjection\Definition;
2224
use 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
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"test": "vendor/bin/phpunit"
1717
},
1818
"require": {
19-
"php": "^5.6|^7.0|^8.0",
19+
"php": "^7.1.3|^8.0",
2020
"symfony/framework-bundle": "~3.0|~4.0|~5.0",
2121
"florianv/swap": "^4.0"
2222
},
2323
"require-dev": {
2424
"php-http/guzzle6-adapter": "^1.0",
2525
"php-http/message": "^1.7",
2626
"symfony/cache": "~3.0|~4.0|~5.0",
27-
"phpunit/phpunit": "~5.0",
27+
"phpunit/phpunit": "~5.7|~6.0|~7.0|~8.0|~9.0",
2828
"nyholm/psr7": "^1.1"
2929
},
3030
"suggest": {

0 commit comments

Comments
 (0)