Skip to content

Commit b3b7fb5

Browse files
committed
Merge tag '2.1.1' into develop
no message
2 parents b789037 + 7538b8b commit b3b7fb5

File tree

7 files changed

+71
-22
lines changed

7 files changed

+71
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor/
22
.php_cs.cache
3+
.phpunit.result.cache
34
composer.lock

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ matrix:
1717
- php: 7.3
1818
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
1919
- php: 7.4snapshot
20+
- php: 7.4snapshot
21+
env: COMPOSER_DEV_STABILITY=true
2022
- php: 7.4snapshot
2123
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
2224
- php: nightly
25+
- php: nightly
26+
env: COMPOSER_DEV_STABILITY=true
2327
- php: nightly
2428
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
2529
allow_failures:
@@ -31,11 +35,13 @@ before_script:
3135
if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then
3236
COMPOSER_FLAGS="$COMPOSER_FLAGS --ignore-platform-reqs"
3337
fi;
38+
- if [[ $COMPOSER_DEV_STABILITY = true ]]; then composer config minimum-stability dev ; fi
3439
- travis_wait composer update --no-interaction $COMPOSER_FLAGS
3540

3641
script:
3742
- if [[ $COVERAGE ]]; then mkdir -p build/logs; fi
38-
- php vendor/bin/phpunit $COVERAGE
43+
- php bin/phpunit $COVERAGE
44+
- php vendor/bin/php-cs-fixer fix
3945

4046
after_script:
4147
- if [[ $COVERAGE ]]; then php vendor/bin/php-coveralls; fi

bin/phpunit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
5+
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
6+
exit(1);
7+
}
8+
9+
if (false === getenv('SYMFONY_PHPUNIT_VERSION') && PHP_VERSION_ID >= 70100) {
10+
putenv('SYMFONY_PHPUNIT_VERSION=7.5');
11+
}
12+
13+
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
],
1212
"require": {
1313
"php": "^5.6|^7.0",
14-
"symfony/lock": "^3.4|^4.0",
15-
"symfony/cache": "^3.4|^4.0",
16-
"symfony/http-foundation": "^3.0|^4.0",
17-
"symfony/http-kernel": "^3.0|^4.0",
18-
"symfony/options-resolver": "^3.0|^4.0"
14+
"symfony/lock": "^3.4|^4.0|^5.0",
15+
"symfony/cache": "^3.4|^4.0|^5.0",
16+
"symfony/http-foundation": "^3.0|^4.0|^5.0",
17+
"symfony/http-kernel": "^3.0|^4.0|^5.0",
18+
"symfony/options-resolver": "^3.0|^4.0|^5.0"
1919
},
2020
"require-dev": {
2121
"friendsofphp/php-cs-fixer": "^2.12",
22-
"phpunit/phpunit": "^5.7.27",
22+
"symfony/phpunit-bridge": "^4.3.5",
2323
"php-coveralls/php-coveralls": "^2.1"
2424
},
2525
"autoload": {

phpunit.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="vendor/autoload.php"
1312
>
13+
<php>
14+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
15+
</php>
1416
<testsuites>
1517
<testsuite name="PSR-6 HttpCache Store Test Suite">
1618
<directory>./tests/</directory>

src/Psr6Store.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
use Symfony\Component\HttpFoundation\File\File;
2424
use Symfony\Component\HttpFoundation\Request;
2525
use Symfony\Component\HttpFoundation\Response;
26+
use Symfony\Component\Lock\BlockingStoreInterface;
2627
use Symfony\Component\Lock\Exception\LockReleasingException;
2728
use Symfony\Component\Lock\Factory;
29+
use Symfony\Component\Lock\LockFactory;
2830
use Symfony\Component\Lock\LockInterface;
2931
use Symfony\Component\Lock\Store\FlockStore;
3032
use Symfony\Component\Lock\Store\SemaphoreStore;
@@ -56,7 +58,7 @@ class Psr6Store implements Psr6StoreInterface
5658
private $cache;
5759

5860
/**
59-
* @var Factory
61+
* @var Factory|LockFactory
6062
*/
6163
private $lockFactory;
6264

@@ -141,10 +143,16 @@ public function __construct(array $options = [])
141143
throw new MissingOptionsException('The cache_directory option is required unless you set the lock_factory explicitly as by default locks are also stored in the configured cache_directory.');
142144
}
143145

144-
return new Factory(
145-
$this->getDefaultLockStore($options['cache_directory'])
146-
);
147-
})->setAllowedTypes('lock_factory', Factory::class);
146+
$defaultLockStore = $this->getDefaultLockStore($options['cache_directory']);
147+
148+
if (class_exists(LockFactory::class)) {
149+
// Symfony >= 4.4
150+
return new LockFactory($defaultLockStore);
151+
}
152+
153+
// Symfony < 4.4
154+
return new Factory($defaultLockStore);
155+
})->setAllowedTypes('lock_factory', [Factory::class, LockFactory::class]);
148156

149157
$this->options = $resolver->resolve($options);
150158
$this->cache = $this->options['cache'];
@@ -248,7 +256,14 @@ public function write(Request $request, Response $response)
248256
// Tags
249257
$tags = [];
250258
if ($response->headers->has($this->options['cache_tags_header'])) {
251-
foreach ($response->headers->get($this->options['cache_tags_header'], '', false) as $header) {
259+
// Symfony < 4.4
260+
$headers = $response->headers->get($this->options['cache_tags_header'], '', false);
261+
if (\is_string($headers)) {
262+
// Symfony >= 4.4
263+
$headers = $response->headers->all($this->options['cache_tags_header']);
264+
}
265+
266+
foreach ($headers as $header) {
252267
foreach (explode(',', $header) as $tag) {
253268
$tags[] = $tag;
254269
}
@@ -583,7 +598,7 @@ private function restoreResponse(array $cacheData)
583598
*
584599
* @param string $cacheDir
585600
*
586-
* @return LockStoreInterface
601+
* @return LockStoreInterface|BlockingStoreInterface
587602
*
588603
* @codeCoverageIgnore Depends on your system.
589604
*/

tests/Psr6StoreTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\HttpFoundation\Response;
2626
use Symfony\Component\Lock\Exception\LockReleasingException;
2727
use Symfony\Component\Lock\Factory;
28+
use Symfony\Component\Lock\LockFactory;
2829
use Symfony\Component\Lock\LockInterface;
2930
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
3031

@@ -63,7 +64,7 @@ public function testCustomCacheAndLockFactory()
6364
$cache = $this->createMock(TagAwareAdapterInterface::class);
6465
$cache->expects($this->once())
6566
->method('deleteItem');
66-
$lockFactory = $this->createMock(Factory::class);
67+
$lockFactory = $this->createFactoryMock();
6768

6869
$store = new Psr6Store([
6970
'cache' => $cache,
@@ -225,7 +226,7 @@ public function testWriteStoresEntries()
225226

226227
$entries = $cacheItem->get();
227228

228-
$this->assertInternalType('array', $entries, 'Entries are stored in cache.');
229+
$this->assertTrue(\is_array($entries), 'Entries are stored in cache.');
229230
$this->assertCount(1, $entries, 'One entry is stored.');
230231
$this->assertSame($entries[Psr6Store::NON_VARYING_KEY]['headers'], array_diff_key($response->headers->all(), ['age' => []]), 'Response headers are stored with no age header.');
231232
}
@@ -389,7 +390,7 @@ public function testLookupWithVaryOnCookies()
389390
// Cookies match
390391
$request = Request::create('https://foobar.com/', 'GET', [], ['Foo' => 'Bar'], [], ['HTTP_COOKIE' => 'Foo=Bar']);
391392
$response = new Response('hello world', 200, ['Vary' => 'Cookie']);
392-
$response->headers->setCookie(new Cookie('Foo', 'Bar'));
393+
$response->headers->setCookie(new Cookie('Foo', 'Bar', 0, '/', false, null, true, false, null));
393394

394395
$this->store->write($request, $response);
395396

@@ -553,7 +554,7 @@ public function testAutoPruneExpiredEntries()
553554
->method('release')
554555
->willReturn(true);
555556

556-
$lockFactory = $this->createMock(Factory::class);
557+
$lockFactory = $this->createFactoryMock();
557558
$lockFactory
558559
->expects($this->any())
559560
->method('createLock')
@@ -622,7 +623,7 @@ public function testAutoPruneIsSkippedIfPruningIsAlreadyInProgress()
622623
->method('acquire')
623624
->willReturn(false);
624625

625-
$lockFactory = $this->createMock(Factory::class);
626+
$lockFactory = $this->createFactoryMock();
626627
$lockFactory
627628
->expects($this->any())
628629
->method('createLock')
@@ -665,7 +666,7 @@ public function testUnlockReturnsFalseOnLockReleasingException()
665666
->method('release')
666667
->willThrowException(new LockReleasingException());
667668

668-
$lockFactory = $this->createMock(Factory::class);
669+
$lockFactory = $this->createFactoryMock();
669670
$lockFactory
670671
->expects($this->once())
671672
->method('createLock')
@@ -690,7 +691,7 @@ public function testLockReleasingExceptionIsIgnoredOnCleanup()
690691
->method('release')
691692
->willThrowException(new LockReleasingException());
692693

693-
$lockFactory = $this->createMock(Factory::class);
694+
$lockFactory = $this->createFactoryMock();
694695
$lockFactory
695696
->expects($this->once())
696697
->method('createLock')
@@ -727,4 +728,15 @@ private function getCache($store = null)
727728

728729
return $cache->getValue($this->store);
729730
}
731+
732+
private function createFactoryMock()
733+
{
734+
if (class_exists(LockFactory::class)) {
735+
// Symfony >= 4.4
736+
return $this->createMock(LockFactory::class);
737+
}
738+
739+
// Symfony < 4.4
740+
return $this->createMock(Factory::class);
741+
}
730742
}

0 commit comments

Comments
 (0)