Skip to content

Fix CI Build and update PHPUnit #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ preset: symfony

enabled:
- alpha_ordered_imports
- short_array_syntax

disabled:
- single_line_throw
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ env:
global:
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- SYMFONY_PHPUNIT_VERSION=6.5

branches:
only:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"require-dev": {
"php-http/guzzle6-adapter": "^1.0 || ^2.0",
"php-http/message": "^1.0 || ^2.0",
"mockery/mockery": "^1.0 || ^2.0",
"mockery/mockery": "^1.3.2",
"monolog/monolog": "*",
"sensio/framework-extra-bundle": "^3.0 || ^4.0 || ^5.0",
"symfony/browser-kit": "^3.4.4 || ^4.2.7 || ^5.0",
"symfony/console": "^3.4.26 || ^4.2.7 || ^5.0",
"symfony/finder": "^3.4.26 || ^4.2.7 || ^5.0",
"symfony/phpunit-bridge": "^4.2.4 || ^5.0",
"symfony/phpunit-bridge": "^4.4.11 || ^5.1.3",
"symfony/security-bundle": "^3.4.26 || ^4.2.7 || ^5.0",
"symfony/twig-bundle": "^3.4.26 || ^4.2.7 || ^5.0",
"symfony/yaml": "^3.4.26 || ^4.2.7 || ^5.0",
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
syntaxCheck="true">
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">./tests/Unit</directory>
Expand All @@ -32,5 +31,6 @@
<env name="KERNEL_DIR" value="./tests/Functional/Fixtures/app" />
<env name="KERNEL_CLASS" value="AppKernel" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
<server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
</php>
</phpunit>
8 changes: 8 additions & 0 deletions src/Security/Http/Logout/ContextInvalidationLogoutHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;

/**
Expand All @@ -38,6 +39,13 @@ public function __construct(UserContextInvalidator $invalidator)
public function logout(Request $request, Response $response, TokenInterface $token)
{
@trigger_error('Using the ContextInvalidationLogoutHandler is deprecated', E_USER_DEPRECATED);

if (class_exists(LogoutEvent::class)) {
// This class no longer works at all with Symfony 5.1, force usage of ContextInvalidationSessionLogoutHandler instead
// See also: https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/pull/545#discussion_r465089219
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.');
}

$this->invalidator->invalidateContext($request->getSession()->getId());
}
}
2 changes: 1 addition & 1 deletion tests/Functional/DependencyInjection/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testCanBeLoaded()
if ('fos_http_cache.user_context.logout_handler' === $id) {
continue;
}
$this->assertInternalType('object', $container->get($id));
$this->assertIsObject($container->get($id));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function testNotCached()
$client->request('GET', '/noncached');
$response = $client->getResponse();
// using contains because Symfony 3.2 add `private` when the cache is not public
$this->assertContains('no-cache', $response->headers->get('Cache-Control'));
$this->assertStringContainsString('no-cache', $response->headers->get('Cache-Control'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Event\LogoutEvent;

class ContextInvalidationLogoutHandlerTest extends WebTestCase
{
use MockeryPHPUnitIntegration;

public function testLogout()
{
if (class_exists(LogoutEvent::class)) {
// @see https://github.com/symfony/symfony/pull/36243/files#r465083756
// @see https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/pull/545/files#diff-05cbcfd492fd361b33ee70130dc687b2
$this->markTestSkipped('This test does not work with Symfony 5.1.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets wait until tomorrow if we get a reaction on for https://github.com/symfony/symfony/pull/36243/files#r465083756 and then either remove this again, or also add a check to the actual implementation to make people realize the handler does not work with symfony 5.1

Copy link
Contributor Author

@alexander-schranz alexander-schranz Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to throw an exception when the ContextInvalidationLogoutHandler class is used in Symfony 5.1? I'm little bit afraid doing that 🙈

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its the correct thing to do. its not something we can silently work around, it simply does not work at all so devs need to be made aware if they did not check the changelog. better a clear error than a security issue that is silently sitting there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 853eaa0

}

$client = static::createClient();
$session = $client->getContainer()->get('session');

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CacheManagerTest extends TestCase

protected $proxyClient;

public function setUp()
public function setUp(): void
{
$this->proxyClient = \Mockery::mock(ProxyClient::class);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Command/InvalidatePathCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class InvalidatePathCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \RuntimeException
*/
public function testExecuteMissingParameters()
{
$this->expectException(\RuntimeException::class);

$invalidator = \Mockery::mock(CacheManager::class);

$application = new Application();
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Command/InvalidateRegexCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class InvalidateRegexCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \RuntimeException
*/
public function testExecuteNoParameters()
{
$this->expectException(\RuntimeException::class);

$invalidator = \Mockery::mock(CacheManager::class);

$application = new Application();
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Command/InvalidateTagCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class InvalidateTagCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \RuntimeException
*/
public function testExecuteMissingParameters()
{
$this->expectException(\RuntimeException::class);

$invalidator = \Mockery::mock(CacheManager::class);

$application = new Application();
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Command/RefreshPathCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class RefreshPathCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \RuntimeException
*/
public function testExecuteMissingParameters()
{
$this->expectException(\RuntimeException::class);

$invalidator = \Mockery::mock(CacheManager::class);

$application = new Application();
Expand Down
14 changes: 6 additions & 8 deletions tests/Unit/Configuration/InvalidateRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ class InvalidateRouteTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage InvalidateRoute params must be an array
*/
public function testExecuteInvalidParams()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('InvalidateRoute params must be an array');

new InvalidateRoute([
'name' => 'test',
'params' => 'foo',
]);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage InvalidateRoute param id must be string
*/
public function testExecuteNoExpression()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('InvalidateRoute param id must be string');

new InvalidateRoute([
'name' => 'test',
'params' => [
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Configuration/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FOS\HttpCacheBundle\Tests\Unit\Configuration;

use FOS\HttpCacheBundle\Configuration\Tag;
use FOS\HttpCacheBundle\Exception\InvalidTagException;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase;

Expand All @@ -22,12 +23,11 @@ class TagTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \FOS\HttpCacheBundle\Exception\InvalidTagException
* @expectedExceptionMessage is invalid because it contains ,
*/
public function testExecuteInvalidParams()
{
$this->expectException(InvalidTagException::class);
$this->expectExceptionMessage('is invalid because it contains ,');

new Tag([
'tags' => ['foo, bar'],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
Expand All @@ -33,7 +34,7 @@ class HashGeneratorPassTest extends TestCase
*/
private $userContextListenerPass;

protected function setUp()
protected function setUp(): void
{
$this->extension = new FOSHttpCacheExtension();
$this->userContextListenerPass = new HashGeneratorPass();
Expand All @@ -56,12 +57,11 @@ public function testConfigNoContext()
}
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage No user context providers found
*/
public function testConfigNoProviders()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('No user context providers found');

$container = $this->createContainer();
$config = $this->getBaseConfig();
$config['user_context']['enabled'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ class TagListenerPassTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage require the SensioFrameworkExtraBundle
*/
public function testNoFrameworkBundle()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('require the SensioFrameworkExtraBundle');

$extension = new FOSHttpCacheExtension();
$tagListenerPass = new TagListenerPass();
$container = $this->createContainer();
Expand Down
17 changes: 8 additions & 9 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,11 @@ public function testSupportsSymfony()
}
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Either configure the "http.servers" section or enable "proxy_client.symfony.use_kernel_dispatcher
*/
public function testEmptyServerConfigurationIsNotAllowed()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Either configure the "http.servers" section or enable "proxy_client.symfony.use_kernel_dispatcher');

$params = $this->getEmptyConfig();
$params['proxy_client'] = [
'symfony' => [
Expand Down Expand Up @@ -457,7 +456,7 @@ public function testCacheManagerNoClient()
$this->assertProcessedConfigurationEquals([], [$format]);
$this->fail('No exception thrown on invalid configuration');
} catch (InvalidConfigurationException $e) {
$this->assertContains('need to configure a proxy_client', $e->getMessage());
$this->assertStringContainsString('need to configure a proxy_client', $e->getMessage());
}
}
}
Expand All @@ -477,7 +476,7 @@ public function testTagsNoCacheManager()
$this->assertProcessedConfigurationEquals([], [$format]);
$this->fail('No exception thrown on invalid configuration');
} catch (InvalidConfigurationException $e) {
$this->assertContains('cache_manager needed for tag handling', $e->getMessage());
$this->assertStringContainsString('cache_manager needed for tag handling', $e->getMessage());
}
}
}
Expand Down Expand Up @@ -599,7 +598,7 @@ public function testInvalidationNoCacheManager()
$this->assertProcessedConfigurationEquals([], [$format]);
$this->fail('No exception thrown on invalid configuration');
} catch (InvalidConfigurationException $e) {
$this->assertContains('cache_manager needed for invalidation handling', $e->getMessage());
$this->assertStringContainsString('cache_manager needed for invalidation handling', $e->getMessage());
}
}
}
Expand Down Expand Up @@ -627,7 +626,7 @@ public function testUserContextLogoutHandler(string $configFile, $expected, $cac
$this->assertProcessedConfigurationEquals([], [$configFile]);
$this->fail('No exception thrown on invalid configuration');
} catch (InvalidConfigurationException $e) {
$this->assertContains($exception, $e->getMessage());
$this->assertStringContainsString($exception, $e->getMessage());
}

return;
Expand Down Expand Up @@ -667,7 +666,7 @@ public function testInvalidDate()
$this->assertProcessedConfigurationEquals([], [$format]);
$this->fail('No exception thrown on invalid configuration');
} catch (InvalidConfigurationException $e) {
$this->assertContains('Failed to parse time string', $e->getMessage());
$this->assertStringContainsString('Failed to parse time string', $e->getMessage());
}
}
}
Expand Down
Loading