Skip to content

Commit 74cb0e5

Browse files
Support Symfony 5.1, fix CI Build and update PHPUnit (#545)
1 parent 396eea2 commit 74cb0e5

24 files changed

+89
-95
lines changed

.styleci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ preset: symfony
22

33
enabled:
44
- alpha_ordered_imports
5-
- short_array_syntax
65

76
disabled:
87
- single_line_throw

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ env:
1717
global:
1818
- PHPUNIT_FLAGS="-v"
1919
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
20-
- SYMFONY_PHPUNIT_VERSION=6.5
2120

2221
branches:
2322
only:

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
"require-dev": {
3131
"php-http/guzzle6-adapter": "^1.0 || ^2.0",
3232
"php-http/message": "^1.0 || ^2.0",
33-
"mockery/mockery": "^1.0 || ^2.0",
33+
"mockery/mockery": "^1.3.2",
3434
"monolog/monolog": "*",
3535
"sensio/framework-extra-bundle": "^3.0 || ^4.0 || ^5.0",
3636
"symfony/browser-kit": "^3.4.4 || ^4.2.7 || ^5.0",
3737
"symfony/console": "^3.4.26 || ^4.2.7 || ^5.0",
3838
"symfony/finder": "^3.4.26 || ^4.2.7 || ^5.0",
39-
"symfony/phpunit-bridge": "^4.2.4 || ^5.0",
39+
"symfony/phpunit-bridge": "^4.4.11 || ^5.1.3",
4040
"symfony/security-bundle": "^3.4.26 || ^4.2.7 || ^5.0",
4141
"symfony/twig-bundle": "^3.4.26 || ^4.2.7 || ^5.0",
4242
"symfony/yaml": "^3.4.26 || ^4.2.7 || ^5.0",

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
colors="true"
55
convertErrorsToExceptions="true"
66
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
syntaxCheck="true">
7+
convertWarningsToExceptions="true">
98
<testsuites>
109
<testsuite name="unit">
1110
<directory suffix="Test.php">./tests/Unit</directory>
@@ -32,5 +31,6 @@
3231
<env name="KERNEL_DIR" value="./tests/Functional/Fixtures/app" />
3332
<env name="KERNEL_CLASS" value="AppKernel" />
3433
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
34+
<server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
3535
</php>
3636
</phpunit>

src/Security/Http/Logout/ContextInvalidationLogoutHandler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18+
use Symfony\Component\Security\Http\Event\LogoutEvent;
1819
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
1920

2021
/**
@@ -38,6 +39,13 @@ public function __construct(UserContextInvalidator $invalidator)
3839
public function logout(Request $request, Response $response, TokenInterface $token)
3940
{
4041
@trigger_error('Using the ContextInvalidationLogoutHandler is deprecated', E_USER_DEPRECATED);
42+
43+
if (class_exists(LogoutEvent::class)) {
44+
// This class no longer works at all with Symfony 5.1, force usage of ContextInvalidationSessionLogoutHandler instead
45+
// See also: https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/pull/545#discussion_r465089219
46+
throw new \LogicException(__CLASS__.'::'.__METHOD__.' no longer works with Symfony 5.1. Remove fos_http_cache.user_context.logout_handler from your firewall configuration. See the changelog for version 2.2. for more information.');
47+
}
48+
4149
$this->invalidator->invalidateContext($request->getSession()->getId());
4250
}
4351
}

tests/Functional/DependencyInjection/ServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testCanBeLoaded()
5858
if ('fos_http_cache.user_context.logout_handler' === $id) {
5959
continue;
6060
}
61-
$this->assertInternalType('object', $container->get($id));
61+
$this->assertIsObject($container->get($id));
6262
}
6363
}
6464
}

tests/Functional/EventListener/CacheControlListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function testNotCached()
3434
$client->request('GET', '/noncached');
3535
$response = $client->getResponse();
3636
// using contains because Symfony 3.2 add `private` when the cache is not public
37-
$this->assertContains('no-cache', $response->headers->get('Cache-Control'));
37+
$this->assertStringContainsString('no-cache', $response->headers->get('Cache-Control'));
3838
}
3939
}

tests/Functional/Security/Http/Logout/ContextInvalidationLogoutHandlerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1717
use Symfony\Component\BrowserKit\Cookie;
1818
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
19+
use Symfony\Component\Security\Http\Event\LogoutEvent;
1920

2021
class ContextInvalidationLogoutHandlerTest extends WebTestCase
2122
{
2223
use MockeryPHPUnitIntegration;
2324

2425
public function testLogout()
2526
{
27+
if (class_exists(LogoutEvent::class)) {
28+
// @see https://github.com/symfony/symfony/pull/36243/files#r465083756
29+
// @see https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/pull/545/files#diff-05cbcfd492fd361b33ee70130dc687b2
30+
$this->markTestSkipped('This test does not work with Symfony 5.1.');
31+
}
32+
2633
$client = static::createClient();
2734
$session = $client->getContainer()->get('session');
2835

tests/Unit/CacheManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CacheManagerTest extends TestCase
2525

2626
protected $proxyClient;
2727

28-
public function setUp()
28+
public function setUp(): void
2929
{
3030
$this->proxyClient = \Mockery::mock(ProxyClient::class);
3131
}

tests/Unit/Command/InvalidatePathCommandTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ class InvalidatePathCommandTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

25-
/**
26-
* @expectedException \RuntimeException
27-
*/
2825
public function testExecuteMissingParameters()
2926
{
27+
$this->expectException(\RuntimeException::class);
28+
3029
$invalidator = \Mockery::mock(CacheManager::class);
3130

3231
$application = new Application();

tests/Unit/Command/InvalidateRegexCommandTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ class InvalidateRegexCommandTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

25-
/**
26-
* @expectedException \RuntimeException
27-
*/
2825
public function testExecuteNoParameters()
2926
{
27+
$this->expectException(\RuntimeException::class);
28+
3029
$invalidator = \Mockery::mock(CacheManager::class);
3130

3231
$application = new Application();

tests/Unit/Command/InvalidateTagCommandTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ class InvalidateTagCommandTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

25-
/**
26-
* @expectedException \RuntimeException
27-
*/
2825
public function testExecuteMissingParameters()
2926
{
27+
$this->expectException(\RuntimeException::class);
28+
3029
$invalidator = \Mockery::mock(CacheManager::class);
3130

3231
$application = new Application();

tests/Unit/Command/RefreshPathCommandTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ class RefreshPathCommandTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

25-
/**
26-
* @expectedException \RuntimeException
27-
*/
2825
public function testExecuteMissingParameters()
2926
{
27+
$this->expectException(\RuntimeException::class);
28+
3029
$invalidator = \Mockery::mock(CacheManager::class);
3130

3231
$application = new Application();

tests/Unit/Configuration/InvalidateRouteTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,22 @@ class InvalidateRouteTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

25-
/**
26-
* @expectedException \RuntimeException
27-
* @expectedExceptionMessage InvalidateRoute params must be an array
28-
*/
2925
public function testExecuteInvalidParams()
3026
{
27+
$this->expectException(\RuntimeException::class);
28+
$this->expectExceptionMessage('InvalidateRoute params must be an array');
29+
3130
new InvalidateRoute([
3231
'name' => 'test',
3332
'params' => 'foo',
3433
]);
3534
}
3635

37-
/**
38-
* @expectedException \RuntimeException
39-
* @expectedExceptionMessage InvalidateRoute param id must be string
40-
*/
4136
public function testExecuteNoExpression()
4237
{
38+
$this->expectException(\RuntimeException::class);
39+
$this->expectExceptionMessage('InvalidateRoute param id must be string');
40+
4341
new InvalidateRoute([
4442
'name' => 'test',
4543
'params' => [

tests/Unit/Configuration/TagTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Tests\Unit\Configuration;
1313

1414
use FOS\HttpCacheBundle\Configuration\Tag;
15+
use FOS\HttpCacheBundle\Exception\InvalidTagException;
1516
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1617
use PHPUnit\Framework\TestCase;
1718

@@ -22,12 +23,11 @@ class TagTest extends TestCase
2223
{
2324
use MockeryPHPUnitIntegration;
2425

25-
/**
26-
* @expectedException \FOS\HttpCacheBundle\Exception\InvalidTagException
27-
* @expectedExceptionMessage is invalid because it contains ,
28-
*/
2926
public function testExecuteInvalidParams()
3027
{
28+
$this->expectException(InvalidTagException::class);
29+
$this->expectExceptionMessage('is invalid because it contains ,');
30+
3131
new Tag([
3232
'tags' => ['foo, bar'],
3333
]);

tests/Unit/DependencyInjection/Compiler/HashGeneratorPassTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension;
1616
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1717
use PHPUnit\Framework\TestCase;
18+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\Definition;
2021
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -33,7 +34,7 @@ class HashGeneratorPassTest extends TestCase
3334
*/
3435
private $userContextListenerPass;
3536

36-
protected function setUp()
37+
protected function setUp(): void
3738
{
3839
$this->extension = new FOSHttpCacheExtension();
3940
$this->userContextListenerPass = new HashGeneratorPass();
@@ -56,12 +57,11 @@ public function testConfigNoContext()
5657
}
5758
}
5859

59-
/**
60-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
61-
* @expectedExceptionMessage No user context providers found
62-
*/
6360
public function testConfigNoProviders()
6461
{
62+
$this->expectException(InvalidConfigurationException::class);
63+
$this->expectExceptionMessage('No user context providers found');
64+
6565
$container = $this->createContainer();
6666
$config = $this->getBaseConfig();
6767
$config['user_context']['enabled'] = true;

tests/Unit/DependencyInjection/Compiler/TagListenerPassTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ class TagListenerPassTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

25-
/**
26-
* @expectedException \RuntimeException
27-
* @expectedExceptionMessage require the SensioFrameworkExtraBundle
28-
*/
2925
public function testNoFrameworkBundle()
3026
{
27+
$this->expectException(\RuntimeException::class);
28+
$this->expectExceptionMessage('require the SensioFrameworkExtraBundle');
29+
3130
$extension = new FOSHttpCacheExtension();
3231
$tagListenerPass = new TagListenerPass();
3332
$container = $this->createContainer();

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,11 @@ public function testSupportsSymfony()
298298
}
299299
}
300300

301-
/**
302-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
303-
* @expectedExceptionMessage Either configure the "http.servers" section or enable "proxy_client.symfony.use_kernel_dispatcher
304-
*/
305301
public function testEmptyServerConfigurationIsNotAllowed()
306302
{
303+
$this->expectException(InvalidConfigurationException::class);
304+
$this->expectExceptionMessage('Either configure the "http.servers" section or enable "proxy_client.symfony.use_kernel_dispatcher');
305+
307306
$params = $this->getEmptyConfig();
308307
$params['proxy_client'] = [
309308
'symfony' => [
@@ -457,7 +456,7 @@ public function testCacheManagerNoClient()
457456
$this->assertProcessedConfigurationEquals([], [$format]);
458457
$this->fail('No exception thrown on invalid configuration');
459458
} catch (InvalidConfigurationException $e) {
460-
$this->assertContains('need to configure a proxy_client', $e->getMessage());
459+
$this->assertStringContainsString('need to configure a proxy_client', $e->getMessage());
461460
}
462461
}
463462
}
@@ -477,7 +476,7 @@ public function testTagsNoCacheManager()
477476
$this->assertProcessedConfigurationEquals([], [$format]);
478477
$this->fail('No exception thrown on invalid configuration');
479478
} catch (InvalidConfigurationException $e) {
480-
$this->assertContains('cache_manager needed for tag handling', $e->getMessage());
479+
$this->assertStringContainsString('cache_manager needed for tag handling', $e->getMessage());
481480
}
482481
}
483482
}
@@ -599,7 +598,7 @@ public function testInvalidationNoCacheManager()
599598
$this->assertProcessedConfigurationEquals([], [$format]);
600599
$this->fail('No exception thrown on invalid configuration');
601600
} catch (InvalidConfigurationException $e) {
602-
$this->assertContains('cache_manager needed for invalidation handling', $e->getMessage());
601+
$this->assertStringContainsString('cache_manager needed for invalidation handling', $e->getMessage());
603602
}
604603
}
605604
}
@@ -627,7 +626,7 @@ public function testUserContextLogoutHandler(string $configFile, $expected, $cac
627626
$this->assertProcessedConfigurationEquals([], [$configFile]);
628627
$this->fail('No exception thrown on invalid configuration');
629628
} catch (InvalidConfigurationException $e) {
630-
$this->assertContains($exception, $e->getMessage());
629+
$this->assertStringContainsString($exception, $e->getMessage());
631630
}
632631

633632
return;
@@ -667,7 +666,7 @@ public function testInvalidDate()
667666
$this->assertProcessedConfigurationEquals([], [$format]);
668667
$this->fail('No exception thrown on invalid configuration');
669668
} catch (InvalidConfigurationException $e) {
670-
$this->assertContains('Failed to parse time string', $e->getMessage());
669+
$this->assertStringContainsString('Failed to parse time string', $e->getMessage());
671670
}
672671
}
673672
}

0 commit comments

Comments
 (0)