Skip to content

Commit 784ddb0

Browse files
authored
Merge pull request #52 from nusje2000/feature/symfony-6-support
Update composer.json
2 parents b5457d1 + ca35c50 commit 784ddb0

7 files changed

Lines changed: 95 additions & 112 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
php-versions: [ '7.4', '8.0' ]
15+
php-versions: [ '8.0' ]
1616
steps:
1717
- name: Setup PHP, with composer and extensions
1818
uses: shivammathur/setup-php@v2
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
strategy:
3333
matrix:
34-
php-versions: [ '7.4', '8.0' ]
34+
php-versions: [ '8.0' ]
3535
steps:
3636
- name: Setup PHP, with composer and extensions
3737
uses: shivammathur/setup-php@v2

composer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
}
1414
},
1515
"require": {
16-
"php": "^7.2 || ^8.0",
16+
"php": "^8.0",
1717
"myclabs/php-enum": "^1.0",
18-
"psr/log": "^1.0",
19-
"symfony/cache": "^5.0",
20-
"symfony/config": "^5.0",
21-
"symfony/console": "^5.0",
22-
"symfony/dependency-injection": "^5.0",
23-
"symfony/event-dispatcher": "^5.0",
24-
"symfony/filesystem": "^5.0",
25-
"symfony/http-client": "^5.0",
26-
"symfony/http-foundation": "^5.0",
27-
"symfony/http-kernel": "^5.0",
18+
"psr/log": "^1.0|^2.0|^3.0",
19+
"symfony/cache": "^5.0|^6.0",
20+
"symfony/config": "^5.0|^6.0",
21+
"symfony/console": "^5.0|^6.0",
22+
"symfony/dependency-injection": "^5.0|^6.0",
23+
"symfony/event-dispatcher": "^5.0|^6.0",
24+
"symfony/filesystem": "^5.0|^6.0",
25+
"symfony/http-client": "^5.0|^6.0",
26+
"symfony/http-foundation": "^5.0|^6.0",
27+
"symfony/http-kernel": "^5.0|^6.0",
2828
"symfony/polyfill-php80": "^1.22"
2929
},
3030
"require-dev": {

src/Decorator/CachingEnvironmentRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function all(): array
4747
if ($item->isHit()) {
4848
$this->logger->info(sprintf('Attempting to use cache with key "%s".', $item->getKey()));
4949

50-
/** @psalm-var mixed $value */
50+
/** @var mixed $value */
5151
$value = $item->get();
5252

5353
if ($this->isValidEnvironmentArray($value)) {
@@ -76,7 +76,7 @@ public function find(string $environment): Environment
7676
if ($item->isHit()) {
7777
$this->logger->info(sprintf('Attempting to use cache with key "%s".', $item->getKey()));
7878

79-
/** @psalm-var mixed $value */
79+
/** @var mixed $value */
8080
$value = $item->get();
8181

8282
if ($value instanceof Environment) {
@@ -105,7 +105,7 @@ public function exists(string $environment): bool
105105
if ($item->isHit()) {
106106
$this->logger->info(sprintf('Attempting to use cache with key "%s".', $item->getKey()));
107107

108-
/** @psalm-var mixed $value */
108+
/** @var mixed $value */
109109
$value = $item->get();
110110

111111
if (is_bool($value)) {

src/Decorator/CachingFeatureRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function all(string $environment): array
4646
if ($item->isHit()) {
4747
$this->logger->info(sprintf('Attempting to use cache with key "%s".', $item->getKey()));
4848

49-
/** @psalm-var mixed $value */
49+
/** @var mixed $value */
5050
$value = $item->get();
5151

5252
if ($this->isValidFeatureArray($value)) {
@@ -75,7 +75,7 @@ public function find(string $environment, string $feature): Feature
7575
if ($item->isHit()) {
7676
$this->logger->info(sprintf('Attempting to use cache with key "%s".', $item->getKey()));
7777

78-
/** @psalm-var mixed $value */
78+
/** @var mixed $value */
7979
$value = $item->get();
8080

8181
if ($value instanceof Feature) {
@@ -104,7 +104,7 @@ public function exists(string $environment, string $feature): bool
104104
if ($item->isHit()) {
105105
$this->logger->info(sprintf('Attempting to use cache with key "%s".', $item->getKey()));
106106

107-
/** @psalm-var mixed $value */
107+
/** @var mixed $value */
108108
$value = $item->get();
109109

110110
if (is_bool($value)) {

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function getConfigTreeBuilder(): TreeBuilder
3737
$remote = $repository->children()->arrayNode('remote')->canBeEnabled()->children();
3838
$remote->scalarNode('host')->isRequired();
3939
$remote->scalarNode('scheme')->defaultValue('https');
40-
$remote->scalarNode('cache_store')->setDeprecated(...$this->getDeprecationParameters('1.1.1'))->defaultNull();
40+
/**
41+
* @psalm-suppress MixedArgument
42+
* @psalm-suppress TooFewArguments
43+
*/
44+
$remote->scalarNode('cache_store')->setDeprecated(...$this->getDeprecationParameters('1.1.1'))->defaultNull(); // @phpstan-ignore-line
4145
$remote->scalarNode('base_path')->defaultValue('/api/feature-toggle');
4246

4347
$environment = $root->children()->arrayNode('environment')->canBeEnabled()->children();
@@ -59,15 +63,14 @@ public function getConfigTreeBuilder(): TreeBuilder
5963
}
6064

6165
/**
62-
* @return array{0: null}|array{0: string, 1: string, 2:null}
66+
* @return array{0: null}|array{0: string, 1: string}
6367
*/
6468
private function getDeprecationParameters(string $version): array
6569
{
6670
if (method_exists(BaseNode::class, 'getDeprecation')) {
6771
return [
6872
'nusje2000/feature-toggle-bundle',
6973
$version,
70-
null,
7174
];
7275
}
7376

tests/Unit/Decorator/CachingEnvironmentRepositoryTest.php

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
use PHPUnit\Framework\TestCase;
1111
use Psr\Log\LoggerInterface;
1212
use Symfony\Component\Cache\Adapter\AdapterInterface;
13-
use Symfony\Contracts\Cache\ItemInterface;
13+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1414

1515
final class CachingEnvironmentRepositoryTest extends TestCase
1616
{
1717
public function testAll(): void
1818
{
1919
$logger = $this->createMock(LoggerInterface::class);
2020

21-
$adapter = $this->createAdapterWithItem(
22-
$this->createCacheItem('nusje2000_feature_toggle.environment._all', null, true)
23-
);
21+
$adapter = new ArrayAdapter();
2422

2523
$wrapped = $this->createMock(EnvironmentRepository::class);
2624
$wrapped->expects(self::once())->method('all')->willReturn([
@@ -37,11 +35,10 @@ public function testAllWithCachedItem(): void
3735
{
3836
$logger = $this->createMock(LoggerInterface::class);
3937

40-
$adapter = $this->createAdapterWithItem(
41-
$this->createCacheItem('nusje2000_feature_toggle.environment._all', [
42-
$this->createEnvironment(),
43-
], false)
44-
);
38+
$adapter = new ArrayAdapter();
39+
$item = $adapter->getItem('nusje2000_feature_toggle.environment._all');
40+
$item->set([$this->createEnvironment()]);
41+
$adapter->save($item);
4542

4643
$wrapped = $this->createMock(EnvironmentRepository::class);
4744
$wrapped->expects(self::never())->method('all');
@@ -56,9 +53,10 @@ public function testAllWithInvalidCachedItem(): void
5653
{
5754
$logger = $this->createMock(LoggerInterface::class);
5855

59-
$adapter = $this->createAdapterWithItem(
60-
$this->createCacheItem('nusje2000_feature_toggle.environment._all', 1, true)
61-
);
56+
$adapter = new ArrayAdapter();
57+
$item = $adapter->getItem('nusje2000_feature_toggle.environment._all');
58+
$item->set(1);
59+
$adapter->save($item);
6260

6361
$wrapped = $this->createMock(EnvironmentRepository::class);
6462
$wrapped->expects(self::once())->method('all')->willReturn([
@@ -75,9 +73,10 @@ public function testAllWithInvalidArrayItemInCache(): void
7573
{
7674
$logger = $this->createMock(LoggerInterface::class);
7775

78-
$adapter = $this->createAdapterWithItem(
79-
$this->createCacheItem('nusje2000_feature_toggle.environment._all', [1], true)
80-
);
76+
$adapter = new ArrayAdapter();
77+
$item = $adapter->getItem('nusje2000_feature_toggle.environment._all');
78+
$item->set([1]);
79+
$adapter->save($item);
8180

8281
$wrapped = $this->createMock(EnvironmentRepository::class);
8382
$wrapped->expects(self::once())->method('all')->willReturn([
@@ -94,9 +93,7 @@ public function testFind(): void
9493
{
9594
$logger = $this->createMock(LoggerInterface::class);
9695

97-
$adapter = $this->createAdapterWithItem(
98-
$this->createCacheItem('nusje2000_feature_toggle.environment.some_env', null, true)
99-
);
96+
$adapter = new ArrayAdapter();
10097

10198
$wrapped = $this->createMock(EnvironmentRepository::class);
10299
$wrapped->expects(self::once())->method('find')->willReturn($this->createEnvironment());
@@ -109,9 +106,10 @@ public function testFindWithCachedItem(): void
109106
{
110107
$logger = $this->createMock(LoggerInterface::class);
111108

112-
$adapter = $this->createAdapterWithItem(
113-
$this->createCacheItem('nusje2000_feature_toggle.environment.some_env', $this->createEnvironment(), false)
114-
);
109+
$adapter = new ArrayAdapter();
110+
$item = $adapter->getItem('nusje2000_feature_toggle.environment.some_env');
111+
$item->set($this->createEnvironment());
112+
$adapter->save($item);
115113

116114
$wrapped = $this->createMock(EnvironmentRepository::class);
117115
$wrapped->expects(self::never())->method('find');
@@ -124,9 +122,10 @@ public function testFindWithInvalidCachedItem(): void
124122
{
125123
$logger = $this->createMock(LoggerInterface::class);
126124

127-
$adapter = $this->createAdapterWithItem(
128-
$this->createCacheItem('nusje2000_feature_toggle.environment.some_env', 1, true)
129-
);
125+
$adapter = new ArrayAdapter();
126+
$item = $adapter->getItem('nusje2000_feature_toggle.environment.some_env');
127+
$item->set(1);
128+
$adapter->save($item);
130129

131130
$wrapped = $this->createMock(EnvironmentRepository::class);
132131
$wrapped->expects(self::once())->method('find')->willReturn($this->createEnvironment());
@@ -139,9 +138,7 @@ public function testExists(): void
139138
{
140139
$logger = $this->createMock(LoggerInterface::class);
141140

142-
$adapter = $this->createAdapterWithItem(
143-
$this->createCacheItem('nusje2000_feature_toggle.environment._exists.some_env', null, true)
144-
);
141+
$adapter = new ArrayAdapter();
145142

146143
$wrapped = $this->createMock(EnvironmentRepository::class);
147144
$wrapped->expects(self::once())->method('exists')->willReturn(true);
@@ -154,9 +151,10 @@ public function testExistsWithCachedItem(): void
154151
{
155152
$logger = $this->createMock(LoggerInterface::class);
156153

157-
$adapter = $this->createAdapterWithItem(
158-
$this->createCacheItem('nusje2000_feature_toggle.environment._exists.some_env', true, false)
159-
);
154+
$adapter = new ArrayAdapter();
155+
$item = $adapter->getItem('nusje2000_feature_toggle.environment._exists.some_env');
156+
$item->set(true);
157+
$adapter->save($item);
160158

161159
$wrapped = $this->createMock(EnvironmentRepository::class);
162160
$wrapped->expects(self::never())->method('exists');
@@ -169,9 +167,10 @@ public function testExistsWithInvalidCachedItem(): void
169167
{
170168
$logger = $this->createMock(LoggerInterface::class);
171169

172-
$adapter = $this->createAdapterWithItem(
173-
$this->createCacheItem('nusje2000_feature_toggle.environment._exists.some_env', 1, true)
174-
);
170+
$adapter = new ArrayAdapter();
171+
$item = $adapter->getItem('nusje2000_feature_toggle.environment._exists.some_env');
172+
$item->set(1);
173+
$adapter->save($item);
175174

176175
$wrapped = $this->createMock(EnvironmentRepository::class);
177176
$wrapped->expects(self::once())->method('exists')->willReturn(true);
@@ -195,28 +194,6 @@ public function testAdd(): void
195194
$repository->add($this->createEnvironment());
196195
}
197196

198-
private function createAdapterWithItem(ItemInterface $item): AdapterInterface
199-
{
200-
$adapter = $this->createMock(AdapterInterface::class);
201-
$adapter->expects(self::once())->method('getItem')->with($item->getKey())->willReturn($item);
202-
203-
return $adapter;
204-
}
205-
206-
/**
207-
* @param mixed $value
208-
*/
209-
private function createCacheItem(string $key, $value, bool $expectUpdate): ItemInterface
210-
{
211-
$item = $this->createMock(ItemInterface::class);
212-
$item->method('getKey')->willReturn($key);
213-
$item->method('isHit')->willReturn(null !== $value);
214-
$item->method('get')->willReturn($value);
215-
$item->expects($expectUpdate ? self::once() : self::never())->method('set');
216-
217-
return $item;
218-
}
219-
220197
private function createEnvironment(): Environment
221198
{
222199
return $this->createStub(Environment::class);

0 commit comments

Comments
 (0)