From 03e22c6bdb368159c7e9d3fef9ded7042e78d63d Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 28 Nov 2019 13:23:15 +0100 Subject: [PATCH 1/3] test with php 7.4 --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6b29579e..62c3c2df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,25 +16,28 @@ matrix: # Minimum supported versions - php: 5.6 env: VARNISH_VERSION=3.0 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES="" + - php: 7.0 + env: VARNISH_VERSION=3.0 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES="" - php: 5.6 - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 env: DOCCHECK=true COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text" VARNISH_MODULES_VERSION=0.12.1 # Test with Varnish 4 - - php: 7.3 + - php: 7.4 env: VARNISH_VERSION=4.1 VARNISH_MODULES_VERSION=0.9.1 # Test Symfony LTS versions - - php: 7.3 + - php: 7.4 env: DEPENDENCIES="symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^2.2.0" - - php: 7.3 + - php: 7.4 env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4" # Latest commit to master - - php: 7.3 + - php: 7.4 env: STABILITY="dev" allow_failures: From 5f2449253d48ed4fdba38b164bcc23c5042c3cd1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 3 Jan 2020 15:58:06 +0100 Subject: [PATCH 2/3] use phpunit bridge and support current phpunit versions --- .travis.yml | 17 +- CHANGELOG.md | 11 +- composer.json | 11 +- phpunit.xml.dist | 2 +- src/Test/CacheAssertions.php | 4 +- src/Test/Legacy/WebServerListener6.php | 153 ++++++++++++++++++ src/Test/NginxTest.php | 4 +- .../PHPUnit/AbstractCacheConstraintTrait.php | 9 +- src/Test/PHPUnit/IsCacheHitConstraint.php | 2 +- src/Test/PHPUnit/IsCacheMissConstraint.php | 2 +- src/Test/SymfonyTest.php | 2 +- src/Test/VarnishTest.php | 4 +- src/Test/WebServerListener.php | 26 +-- .../ProxyClient/PurgeAssertions.php | 2 +- .../Varnish/UserContextFailureTest.php | 2 +- tests/Unit/CacheInvalidatorTest.php | 34 ++-- tests/Unit/ProxyClient/FastlyTest.php | 4 +- tests/Unit/ProxyClient/HttpDispatcherTest.php | 66 ++++---- .../ProxyClient/MultiplexerClientTest.php | 3 +- tests/Unit/ProxyClient/NoopTest.php | 2 +- tests/Unit/ProxyClient/SymfonyTest.php | 6 +- tests/Unit/ProxyClient/VarnishTest.php | 9 +- tests/Unit/SymfonyCache/CacheEventTest.php | 5 +- .../SymfonyCache/CustomTtlListenerTest.php | 4 +- tests/Unit/SymfonyCache/DebugListenerTest.php | 5 +- tests/Unit/SymfonyCache/PurgeListenerTest.php | 11 +- .../SymfonyCache/PurgeTagsListenerTest.php | 13 +- .../Unit/SymfonyCache/RefreshListenerTest.php | 11 +- .../SymfonyCache/UserContextListenerTest.php | 8 +- tests/Unit/Test/NginxTestTest.php | 2 +- .../Test/PHPUnit/IsCacheHitConstraintTest.php | 16 +- .../PHPUnit/IsCacheMissConstraintTest.php | 10 +- tests/Unit/Test/Proxy/AbstractProxyTest.php | 12 +- tests/Unit/Test/Proxy/SymfonyProxyTest.php | 4 +- tests/Unit/Test/Proxy/VarnishProxyTest.php | 13 +- tests/Unit/Test/VarnishTestTest.php | 2 +- tests/Unit/UserContext/HashGeneratorTest.php | 5 +- 37 files changed, 321 insertions(+), 175 deletions(-) create mode 100644 src/Test/Legacy/WebServerListener6.php diff --git a/.travis.yml b/.travis.yml index 62c3c2df..20b5b41c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,19 +8,18 @@ cache: env: global: - VARNISH_VERSION=5.1 + - SYMFONY_PHPUNIT_VERSION=8 - DEPENDENCIES="toflar/psr6-symfony-http-cache-store:^2.2.0" matrix: fast_finish: true include: # Minimum supported versions - - php: 5.6 - env: VARNISH_VERSION=3.0 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES="" - - php: 7.0 - env: VARNISH_VERSION=3.0 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES="" + - php: 7.1 + env: VARNISH_VERSION=3.0 SYMFONY_PHPUNIT_VERSION=5.7 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES="" - - php: 5.6 - php: 7.1 + env: SYMFONY_PHPUNIT_VERSION=7 - php: 7.2 - php: 7.3 - php: 7.4 @@ -30,7 +29,11 @@ matrix: - php: 7.4 env: VARNISH_VERSION=4.1 VARNISH_MODULES_VERSION=0.9.1 - # Test Symfony LTS versions + # Test PHPUnit versions + - php: 7.4 + env: SYMFONY_PHPUNIT_VERSION=6 + + # Test SYMFONY LTS versions - php: 7.4 env: DEPENDENCIES="symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^2.2.0" - php: 7.4 @@ -76,7 +79,7 @@ before_script: script: - composer validate --strict --no-check-lock - - vendor/bin/phpunit $PHPUNIT_FLAGS + - vendor/bin/simple-phpunit $PHPUNIT_FLAGS - if [[ "$DOCCHECK" = true ]]; then make -C doc SPHINXOPTS='-nW' html; fi - if [[ "$DOCCHECK" = true ]]; then make -C doc spelling; fi diff --git a/CHANGELOG.md b/CHANGELOG.md index a4c6c66c..4752f3c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,13 @@ Changelog See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpCache/releases). -2.8.1 +2.9.0 ----- ### General -* Removed PHP 7.0 compatibility +* Raised minimal PHP version to 7.1 +* Test helper classes upgraded to support PHPUnit 7/8 ### Symfony HttpCache @@ -98,7 +99,7 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC * Added: `CleanupCacheTagsListener` to remove the cache tags header from the final response that is sent to the client. Add this listener to your cache kernel. - + ### Cache Tagging * Improved: The `ResponseTagger` does now remove duplicate tags. @@ -256,7 +257,7 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC * Varnish configuration are now files that you can directly include from your .vcl and call custom functions to avoid copy-pasting VCL code. -* Added support for and changed default to Varnish version 5. +* Added support for and changed default to Varnish version 5. * Moved Varnish 4 and 5 configuration files from `resources/config/varnish-4/` to `resources/config/varnish/`. * Changed default Varnish version to 5. @@ -280,7 +281,7 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC `AppCache extends EventDispatchingHttpInterface` with a `use EventDispatchingHttpCache;` statement. * The user context by default does not use a hardcoded hash for anonymous users - but does a hash lookup. You can still configure a hardcoded hash. + but does a hash lookup. You can still configure a hardcoded hash. ### Testing diff --git a/composer.json b/composer.json index 390fcafe..51b064ca 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } ], "require": { - "php": "^5.6 || ^7.1.0", + "php": "^7.1", "symfony/event-dispatcher": "^3.4 || ^4.3 || ^5.0", "symfony/options-resolver": "^3.4 || ^4.3 || ^5.0", "php-http/client-implementation": "^1.0 || ^2.0", @@ -30,20 +30,21 @@ "php-http/discovery": "^1.0" }, "require-dev": { - "mockery/mockery": "~0.9.5", + "mockery/mockery": "^1.3.1", "monolog/monolog": "^1.0", "php-http/guzzle6-adapter": "^1.0 || ^2.0", "php-http/mock-client": "^1.2", - "phpunit/phpunit": "^5.7 || ^6.0", "symfony/process": "^3.4 || ^4.3 || ^5.0", - "symfony/http-kernel": "^3.4 || ^4.3 || ^5.0" + "symfony/http-kernel": "^3.4 || ^4.3 || ^5.0", + "symfony/phpunit-bridge": "^5.0" }, "conflict": { "toflar/psr6-symfony-http-cache-store": "<2.2.1" }, "suggest": { "friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework", - "monolog/monolog": "For logging issues while invalidating" + "monolog/monolog": "For logging issues while invalidating", + "phpunit/phpunit": "Functional tests for your cache invalidation system, 5.7 || 6.0 || 7.0 || 8.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c26221ba..30158d09 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,7 +5,7 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" - syntaxCheck="true"> +> ./tests/ diff --git a/src/Test/CacheAssertions.php b/src/Test/CacheAssertions.php index fd1a6bca..63cbe714 100644 --- a/src/Test/CacheAssertions.php +++ b/src/Test/CacheAssertions.php @@ -34,7 +34,7 @@ trait CacheAssertions * @param ResponseInterface $response * @param string $message Test failure message (optional) */ - public function assertMiss(ResponseInterface $response, $message = null) + public function assertMiss(ResponseInterface $response, $message = '') { TestCase::assertThat($response, self::isCacheMiss(), $message); } @@ -45,7 +45,7 @@ public function assertMiss(ResponseInterface $response, $message = null) * @param ResponseInterface $response * @param string $message Test failure message (optional) */ - public function assertHit(ResponseInterface $response, $message = null) + public function assertHit(ResponseInterface $response, $message = '') { TestCase::assertThat($response, self::isCacheHit(), $message); } diff --git a/src/Test/Legacy/WebServerListener6.php b/src/Test/Legacy/WebServerListener6.php new file mode 100644 index 00000000..d59b63b4 --- /dev/null +++ b/src/Test/Legacy/WebServerListener6.php @@ -0,0 +1,153 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\HttpCache\Test\Legacy; + +use FOS\HttpCache\Test\WebServerListenerTrait; +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Test; +use PHPUnit\Framework\TestListener; +use PHPUnit\Framework\TestSuite; +use PHPUnit\Framework\Warning; + +/** + * A PHPUnit test listener that starts and stops the PHP built-in web server. + * + * This legacy version is for PHPUnit 6.x. + * + * This listener is configured with a couple of constants from the phpunit.xml + * file. To define constants in the phpunit file, use this syntax: + * + * + * + * + * WEB_SERVER_HOSTNAME host name of the web server (required) + * WEB_SERVER_PORT port to listen on (required) + * WEB_SERVER_DOCROOT path to the document root for the server (required) + */ +class WebServerListener6 implements TestListener +{ + /** @var WebServerListenerTrait */ + private $trait; + + public function __construct() + { + $this->trait = new WebServerListenerTrait(); + } + + /** + * Make sure the PHP built-in web server is running for tests with group + * 'webserver'. + */ + public function startTestSuite(TestSuite $suite) + { + $this->trait->startTestSuite($suite); + } + + /** + * We don't need these. + */ + public function endTestSuite(TestSuite $suite) + { + } + + public function addError(Test $test, \Exception $e, $time) + { + } + + public function addFailure(Test $test, AssertionFailedError $e, $time) + { + } + + public function addIncompleteTest(Test $test, \Exception $e, $time) + { + } + + public function addSkippedTest(Test $test, \Exception $e, $time) + { + } + + public function startTest(Test $test) + { + } + + public function endTest(Test $test, $time) + { + } + + public function addRiskyTest(Test $test, \Exception $e, $time) + { + } + + public function addWarning(Test $test, Warning $e, $time) + { + } + + /** + * Get web server hostname. + * + * @throws \Exception + * + * @return string + */ + protected function getHostName() + { + return $this->trait->getHostName(); + } + + /** + * Get web server port. + * + * @throws \Exception + * + * @return int + */ + protected function getPort() + { + return $this->trait->getPort(); + } + + /** + * Get web server port. + * + * @throws \Exception + * + * @return int + */ + protected function getDocRoot() + { + return $this->trait->getDocRoot(); + } + + /** + * Start PHP built-in web server. + * + * @return int PID + */ + protected function startPhpWebServer() + { + return $this->trait->startPhpWebServer(); + } + + /** + * Wait for caching proxy to be started up and reachable. + * + * @param string $ip + * @param int $port + * @param int $timeout Timeout in milliseconds + * + * @throws \RuntimeException If proxy is not reachable within timeout + */ + protected function waitFor($ip, $port, $timeout) + { + $this->trait->waitFor($ip, $port, $timeout); + } +} diff --git a/src/Test/NginxTest.php b/src/Test/NginxTest.php index 0c1e453c..76e4c594 100644 --- a/src/Test/NginxTest.php +++ b/src/Test/NginxTest.php @@ -51,12 +51,12 @@ trait NginxTest */ protected $proxy; - protected function setUp() + protected function setUp(): void { $this->getProxy()->clear(); } - protected function tearDown() + protected function tearDown(): void { $this->getProxy()->stop(); } diff --git a/src/Test/PHPUnit/AbstractCacheConstraintTrait.php b/src/Test/PHPUnit/AbstractCacheConstraintTrait.php index 48bff880..8390d03f 100644 --- a/src/Test/PHPUnit/AbstractCacheConstraintTrait.php +++ b/src/Test/PHPUnit/AbstractCacheConstraintTrait.php @@ -11,6 +11,7 @@ namespace FOS\HttpCache\Test\PHPUnit; +use PHPUnit\Runner\Version; use Psr\Http\Message\ResponseInterface; /** @@ -31,7 +32,9 @@ public function __construct($header = null) $this->header = $header; } - parent::__construct(); + if (version_compare(Version::id(), '8.0.0', '<')) { + parent::__construct(); + } } /** @@ -39,7 +42,7 @@ public function __construct($header = null) * * @param ResponseInterface $other The guzzle response object */ - public function matches($other) + public function matches($other): bool { if (!$other instanceof ResponseInterface) { throw new \RuntimeException(sprintf('Expected a GuzzleHttp\Psr7\Response but got %s', get_class($other))); @@ -75,7 +78,7 @@ public function matches($other) /** * {@inheritdoc} */ - public function failureDescription($other) + public function failureDescription($other): string { return sprintf( 'response (with status code %s) %s', diff --git a/src/Test/PHPUnit/IsCacheHitConstraint.php b/src/Test/PHPUnit/IsCacheHitConstraint.php index 1c034b70..b4322f4c 100644 --- a/src/Test/PHPUnit/IsCacheHitConstraint.php +++ b/src/Test/PHPUnit/IsCacheHitConstraint.php @@ -16,7 +16,7 @@ class IsCacheHitConstraint extends AbstractCacheConstraint /** * {@inheritdoc} */ - public function toString() + public function toString(): string { return 'is a cache hit'; } diff --git a/src/Test/PHPUnit/IsCacheMissConstraint.php b/src/Test/PHPUnit/IsCacheMissConstraint.php index 6ee7a8cf..7b79b16c 100644 --- a/src/Test/PHPUnit/IsCacheMissConstraint.php +++ b/src/Test/PHPUnit/IsCacheMissConstraint.php @@ -16,7 +16,7 @@ class IsCacheMissConstraint extends AbstractCacheConstraint /** * {@inheritdoc} */ - public function toString() + public function toString(): string { return 'is a cache miss'; } diff --git a/src/Test/SymfonyTest.php b/src/Test/SymfonyTest.php index 3197a55b..15a7d890 100644 --- a/src/Test/SymfonyTest.php +++ b/src/Test/SymfonyTest.php @@ -50,7 +50,7 @@ trait SymfonyTest * * @throws \Exception */ - protected function setUp() + protected function setUp(): void { $this->getProxy()->clear(); } diff --git a/src/Test/VarnishTest.php b/src/Test/VarnishTest.php index d4d2d1e4..9883cf02 100644 --- a/src/Test/VarnishTest.php +++ b/src/Test/VarnishTest.php @@ -59,7 +59,7 @@ trait VarnishTest /** * Start Varnish and discard any cached content. */ - protected function setUp() + protected function setUp(): void { $this->getProxy()->clear(); } @@ -67,7 +67,7 @@ protected function setUp() /** * Stop Varnish. */ - protected function tearDown() + protected function tearDown(): void { $this->getProxy()->stop(); } diff --git a/src/Test/WebServerListener.php b/src/Test/WebServerListener.php index 68b6e952..e628d337 100644 --- a/src/Test/WebServerListener.php +++ b/src/Test/WebServerListener.php @@ -11,18 +11,22 @@ namespace FOS\HttpCache\Test; +use FOS\HttpCache\Test\Legacy\WebServerListener6; use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\Test; use PHPUnit\Framework\TestListener as TestListenerInterface; use PHPUnit\Framework\TestSuite; use PHPUnit\Framework\Warning; +use PHPUnit\Runner\Version; -if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { +if (class_exists(\PHPUnit_Runner_Version::class) && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { /* * Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior * (the class gets defined without executing the code before it and so the definition is not properly conditional) */ class_alias('FOS\HttpCache\Test\Legacy\WebServerListener', 'FOS\HttpCache\Test\WebServerListener'); +} elseif (version_compare(Version::id(), '7.0.0', '<')) { + class_alias(WebServerListener6::class, 'FOS\HttpCache\Test\WebServerListener'); } else { /** * A PHPUnit test listener that starts and stops the PHP built-in web server. @@ -51,7 +55,7 @@ public function __construct() * Make sure the PHP built-in web server is running for tests with group * 'webserver'. */ - public function startTestSuite(TestSuite $suite) + public function startTestSuite(TestSuite $suite): void { $this->trait->startTestSuite($suite); } @@ -59,39 +63,39 @@ public function startTestSuite(TestSuite $suite) /** * We don't need these. */ - public function endTestSuite(TestSuite $suite) + public function endTestSuite(TestSuite $suite): void { } - public function addError(Test $test, \Exception $e, $time) + public function addError(Test $test, \Throwable $e, float $time): void { } - public function addFailure(Test $test, AssertionFailedError $e, $time) + public function addFailure(Test $test, AssertionFailedError $e, float $time): void { } - public function addIncompleteTest(Test $test, \Exception $e, $time) + public function addIncompleteTest(Test $test, \Throwable $e, float $time): void { } - public function addSkippedTest(Test $test, \Exception $e, $time) + public function addSkippedTest(Test $test, \Throwable $e, float $time): void { } - public function startTest(Test $test) + public function startTest(Test $test): void { } - public function endTest(Test $test, $time) + public function endTest(Test $test, float $time): void { } - public function addRiskyTest(Test $test, \Exception $e, $time) + public function addRiskyTest(Test $test, \Throwable $e, float $time): void { } - public function addWarning(Test $test, Warning $e, $time) + public function addWarning(Test $test, Warning $e, float $time): void { } diff --git a/tests/Functional/ProxyClient/PurgeAssertions.php b/tests/Functional/ProxyClient/PurgeAssertions.php index c35d2c7f..39468891 100644 --- a/tests/Functional/ProxyClient/PurgeAssertions.php +++ b/tests/Functional/ProxyClient/PurgeAssertions.php @@ -60,7 +60,7 @@ protected function assertPurgeContentType(PurgeCapable $proxyClient, $path = '/n $this->assertHit($this->getResponse($path, $json)); $response = $this->getResponse($path, $html); - $this->assertContains('text/html', $response->getHeaderLine('Content-Type')); + $this->assertStringContainsString('text/html', $response->getHeaderLine('Content-Type')); $this->assertMiss($response); $this->assertHit($this->getResponse($path, $html)); diff --git a/tests/Functional/Varnish/UserContextFailureTest.php b/tests/Functional/Varnish/UserContextFailureTest.php index ad72cc2e..fbfca479 100644 --- a/tests/Functional/Varnish/UserContextFailureTest.php +++ b/tests/Functional/Varnish/UserContextFailureTest.php @@ -28,7 +28,7 @@ class UserContextFailureTest extends VarnishTestCase */ private $mode = 'cache'; - public function setUp() + public function setUp(): void { // needs to be decided before doing the setup $this->mode = 'testHashRequestFailure' === $this->getName() ? 'failure' : 'cache'; diff --git a/tests/Unit/CacheInvalidatorTest.php b/tests/Unit/CacheInvalidatorTest.php index c4f8e5d4..d12ad9a8 100644 --- a/tests/Unit/CacheInvalidatorTest.php +++ b/tests/Unit/CacheInvalidatorTest.php @@ -40,7 +40,7 @@ class CacheInvalidatorTest extends TestCase public function testSupportsTrue() { - /** @var MockInterface|Varnish $proxyClient */ + /** @var MockInterface&Varnish $proxyClient */ $proxyClient = \Mockery::mock(Varnish::class); $cacheInvalidator = new CacheInvalidator($proxyClient); @@ -53,7 +53,7 @@ public function testSupportsTrue() public function testSupportsFalse() { - /** @var MockInterface|ProxyClient $proxyClient */ + /** @var MockInterface&ProxyClient $proxyClient */ $proxyClient = \Mockery::mock(ProxyClient::class); $cacheInvalidator = new CacheInvalidator($proxyClient); @@ -64,22 +64,20 @@ public function testSupportsFalse() $this->assertFalse($cacheInvalidator->supports(CacheInvalidator::TAGS)); } - /** - * @expectedException \InvalidArgumentException - */ public function testSupportsInvalid() { - /** @var MockInterface|ProxyClient $proxyClient */ + /** @var MockInterface&ProxyClient $proxyClient */ $proxyClient = \Mockery::mock(ProxyClient::class); $cacheInvalidator = new CacheInvalidator($proxyClient); + $this->expectException(\InvalidArgumentException::class); $cacheInvalidator->supports('garbage'); } public function testInvalidatePath() { - /** @var MockInterface|PurgeCapable $purge */ + /** @var MockInterface&PurgeCapable $purge */ $purge = \Mockery::mock(PurgeCapable::class) ->shouldReceive('purge')->once()->with('/my/route', []) ->shouldReceive('purge')->once()->with('/my/route', ['X-Test-Header' => 'xyz']) @@ -98,7 +96,7 @@ public function testInvalidatePath() public function testRefreshPath() { $headers = ['X' => 'Y']; - /** @var MockInterface|RefreshCapable $refresh */ + /** @var MockInterface&RefreshCapable $refresh */ $refresh = \Mockery::mock(RefreshCapable::class) ->shouldReceive('refresh')->once()->with('/my/route', $headers) ->shouldReceive('flush')->never() @@ -118,7 +116,7 @@ public function testInvalidate() 'Other-Header' => '^a|b|c$', ]; - /** @var MockInterface|BanCapable $ban */ + /** @var MockInterface&BanCapable $ban */ $ban = \Mockery::mock(BanCapable::class) ->shouldReceive('ban') ->with($headers) @@ -136,7 +134,7 @@ public function testInvalidateTags() 'post-type-2', ]; - /** @var MockInterface|TagCapable $tagHandler */ + /** @var MockInterface&TagCapable $tagHandler */ $tagHandler = \Mockery::mock(TagCapable::class) ->shouldReceive('invalidateTags') ->with($tags) @@ -149,7 +147,7 @@ public function testInvalidateTags() public function testInvalidateRegex() { - /** @var MockInterface|BanCapable $ban */ + /** @var MockInterface&BanCapable $ban */ $ban = \Mockery::mock(BanCapable::class) ->shouldReceive('banPath') ->with('/a', 'b', ['example.com']) @@ -162,7 +160,7 @@ public function testInvalidateRegex() public function testMethodException() { - /** @var MockInterface|ProxyClient $proxyClient */ + /** @var MockInterface&ProxyClient $proxyClient */ $proxyClient = \Mockery::mock(ProxyClient::class); $cacheInvalidator = new CacheInvalidator($proxyClient); @@ -202,12 +200,9 @@ public function testMethodException() } } - /** - * @expectedException \FOS\HttpCache\Exception\ExceptionCollection - */ public function testProxyClientExceptionsAreLogged() { - /** @var MockInterface|RequestInterface $failedRequest */ + /** @var MockInterface&RequestInterface $failedRequest */ $failedRequest = \Mockery::mock(RequestInterface::class) ->shouldReceive('getHeaderLine')->with('Host')->andReturn('127.0.0.1') ->getMock(); @@ -224,7 +219,7 @@ public function testProxyClientExceptionsAreLogged() $exceptions = new ExceptionCollection(); $exceptions->add($unreachableException)->add($responseException); - /** @var MockInterface|ProxyClient $proxyClient */ + /** @var MockInterface&ProxyClient $proxyClient */ $proxyClient = \Mockery::mock(ProxyClient::class) ->shouldReceive('flush')->once()->andThrow($exceptions) ->getMock(); @@ -248,6 +243,7 @@ public function testProxyClientExceptionsAreLogged() $cacheInvalidator->getEventDispatcher()->addSubscriber(new LogListener($logger)); + $this->expectException(ExceptionCollection::class); $cacheInvalidator ->flush() ; @@ -255,7 +251,7 @@ public function testProxyClientExceptionsAreLogged() public function testEventDispatcher() { - /** @var MockInterface|Varnish $proxyClient */ + /** @var MockInterface&Varnish $proxyClient */ $proxyClient = \Mockery::mock(Varnish::class); if (class_exists(LegacyEventDispatcherProxy::class)) { @@ -271,7 +267,7 @@ public function testEventDispatcher() public function testEventDispatcherImmutable() { - /** @var MockInterface|Varnish $proxyClient */ + /** @var MockInterface&Varnish $proxyClient */ $proxyClient = \Mockery::mock(Varnish::class); if (class_exists(LegacyEventDispatcherProxy::class)) { diff --git a/tests/Unit/ProxyClient/FastlyTest.php b/tests/Unit/ProxyClient/FastlyTest.php index 5f585d2f..3f90c43d 100644 --- a/tests/Unit/ProxyClient/FastlyTest.php +++ b/tests/Unit/ProxyClient/FastlyTest.php @@ -27,13 +27,13 @@ class FastlyTest extends TestCase */ private $httpDispatcher; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->httpDispatcher = \Mockery::mock(HttpDispatcher::class); } - protected function tearDown() + protected function tearDown(): void { unset($this->httpDispatcher); parent::tearDown(); diff --git a/tests/Unit/ProxyClient/HttpDispatcherTest.php b/tests/Unit/ProxyClient/HttpDispatcherTest.php index 8b41dd85..c90111a3 100644 --- a/tests/Unit/ProxyClient/HttpDispatcherTest.php +++ b/tests/Unit/ProxyClient/HttpDispatcherTest.php @@ -13,6 +13,8 @@ use FOS\HttpCache\Exception\ExceptionCollection; use FOS\HttpCache\Exception\InvalidArgumentException; +use FOS\HttpCache\Exception\InvalidUrlException; +use FOS\HttpCache\Exception\MissingHostException; use FOS\HttpCache\Exception\ProxyResponseException; use FOS\HttpCache\Exception\ProxyUnreachableException; use FOS\HttpCache\ProxyClient\HttpDispatcher; @@ -51,19 +53,18 @@ class HttpDispatcherTest extends TestCase */ private $uriFactory; - protected function setUp() + protected function setUp(): void { $this->httpClient = new Client(); $this->messageFactory = MessageFactoryDiscovery::find(); $this->uriFactory = UriFactoryDiscovery::find(); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage URI parameter must be a string, object given - */ public function testInstantiateWithNonUri() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI parameter must be a string, object given'); + new HttpDispatcher( ['127.0.0.1:123'], $this @@ -78,6 +79,21 @@ public function testInstantiateWithNonUri() * @param string $message Optional exception message to match against */ public function testExceptions(\Exception $exception, $type, $message = null) + { + $this->doTestException($exception, $type, $message); + } + + /** + * Ensure that exceptions by HTTP clients that do not conform to the final standard are nonetheless correctly handled. + * + * @group legacy + */ + public function testLegacyException() + { + $this->doTestException(new \Exception('something went completely wrong'), InvalidArgumentException::class, 'something went completely wrong'); + } + + private function doTestException(\Exception $exception, $type, $message) { $this->httpClient->addException($exception); $httpDispatcher = new HttpDispatcher( @@ -94,10 +110,7 @@ public function testExceptions(\Exception $exception, $type, $message = null) $this->assertCount(1, $exceptions); $this->assertInstanceOf($type, $exceptions->getFirst()); if ($message) { - $this->assertContains( - $message, - $exceptions->getFirst()->getMessage() - ); + $this->assertStringContainsString($message, $exceptions->getFirst()->getMessage()); } } @@ -137,20 +150,14 @@ public function exceptionProvider() ProxyUnreachableException::class, 'bla.com', ], - [ - new \Exception('something went completely wrong'), - InvalidArgumentException::class, - 'something went completely wrong', - ], ]; } - /** - * @expectedException \FOS\HttpCache\Exception\MissingHostException - * @expectedExceptionMessage cannot be invalidated without a host - */ public function testMissingHostExceptionIsThrown() { + $this->expectException(MissingHostException::class); + $this->expectExceptionMessage('cannot be invalidated without a host'); + $httpDispatcher = new HttpDispatcher( ['127.0.0.1:123'], '', @@ -239,30 +246,27 @@ public function testPortIsAdded() $this->assertEquals('http://127.0.0.1:8080/some/path', $requests[0]->getUri()); } - /** - * @expectedException \FOS\HttpCache\Exception\InvalidUrlException - * @expectedExceptionMessage URL "http:///this is no url" is invalid. - */ public function testSetServersThrowsInvalidUrlException() { + $this->expectException(InvalidUrlException::class); + $this->expectExceptionMessage('URL "http:///this is no url" is invalid.'); + new HttpDispatcher(['http:///this is no url']); } - /** - * @expectedException \FOS\HttpCache\Exception\InvalidUrlException - * @expectedExceptionMessage URL "this ://is no url" is invalid. - */ public function testSetServersThrowsWeirdInvalidUrlException() { + $this->expectException(InvalidUrlException::class); + $this->expectExceptionMessage('URL "this ://is no url" is invalid.'); + new HttpDispatcher(['this ://is no url']); } - /** - * @expectedException \FOS\HttpCache\Exception\InvalidUrlException - * @expectedExceptionMessage Server "http://127.0.0.1:80/some/path" is invalid. Only scheme, host, port URL parts are allowed - */ public function testSetServersThrowsInvalidServerException() { + $this->expectException(InvalidUrlException::class); + $this->expectExceptionMessage('Server "http://127.0.0.1:80/some/path" is invalid. Only scheme, host, port URL parts are allowed'); + new HttpDispatcher(['http://127.0.0.1:80/some/path']); } @@ -357,7 +361,7 @@ function (RequestInterface $request) { } /** - * @return array|RequestInterface[] + * @return RequestInterface[] */ protected function getRequests() { diff --git a/tests/Unit/ProxyClient/MultiplexerClientTest.php b/tests/Unit/ProxyClient/MultiplexerClientTest.php index c2e60862..8911bb7c 100644 --- a/tests/Unit/ProxyClient/MultiplexerClientTest.php +++ b/tests/Unit/ProxyClient/MultiplexerClientTest.php @@ -11,6 +11,7 @@ namespace FOS\HttpCache\Tests\Unit\ProxyClient; +use FOS\HttpCache\Exception\InvalidArgumentException; use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; @@ -174,10 +175,10 @@ public function provideInvalidClient() * @param ProxyClient[] $clients * * @dataProvider provideInvalidClient - * @expectedException \FOS\HttpCache\Exception\InvalidArgumentException */ public function testInvalidClientTest(array $clients) { + $this->expectException(InvalidArgumentException::class); new MultiplexerClient($clients); } } diff --git a/tests/Unit/ProxyClient/NoopTest.php b/tests/Unit/ProxyClient/NoopTest.php index 955bedb8..eb1ca760 100644 --- a/tests/Unit/ProxyClient/NoopTest.php +++ b/tests/Unit/ProxyClient/NoopTest.php @@ -21,7 +21,7 @@ class NoopTest extends TestCase */ private $noop; - protected function setUp() + protected function setUp(): void { $this->noop = new Noop(); } diff --git a/tests/Unit/ProxyClient/SymfonyTest.php b/tests/Unit/ProxyClient/SymfonyTest.php index 464c101f..0821c9d5 100644 --- a/tests/Unit/ProxyClient/SymfonyTest.php +++ b/tests/Unit/ProxyClient/SymfonyTest.php @@ -27,7 +27,7 @@ class SymfonyTest extends TestCase */ private $httpDispatcher; - protected function setUp() + protected function setUp(): void { $this->httpDispatcher = \Mockery::mock(HttpDispatcher::class); } @@ -62,7 +62,7 @@ function (RequestInterface $request) { $this->assertEquals('PURGETAGS', $request->getMethod()); $this->assertEquals('/', $request->getUri()); - $this->assertContains('foobar,other tag', $request->getHeaderLine('X-Cache-Tags')); + $this->assertStringContainsString('foobar,other tag', $request->getHeaderLine('X-Cache-Tags')); return true; } @@ -173,7 +173,7 @@ function (RequestInterface $request) { $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/fresh', $request->getUri()); - $this->assertContains('no-cache', $request->getHeaderLine('Cache-Control')); + $this->assertStringContainsString('no-cache', $request->getHeaderLine('Cache-Control')); return true; } diff --git a/tests/Unit/ProxyClient/VarnishTest.php b/tests/Unit/ProxyClient/VarnishTest.php index d4974d41..3d3e0716 100644 --- a/tests/Unit/ProxyClient/VarnishTest.php +++ b/tests/Unit/ProxyClient/VarnishTest.php @@ -11,6 +11,7 @@ namespace FOS\HttpCache\Tests\Unit\ProxyClient; +use FOS\HttpCache\Exception\InvalidArgumentException; use FOS\HttpCache\ProxyClient\HttpDispatcher; use FOS\HttpCache\ProxyClient\Varnish; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; @@ -27,7 +28,7 @@ class VarnishTest extends TestCase */ private $httpDispatcher; - protected function setUp() + protected function setUp(): void { $this->httpDispatcher = \Mockery::mock(HttpDispatcher::class); } @@ -127,14 +128,12 @@ function (RequestInterface $request) { $varnish->invalidateTags(['post-1', 'post,type-3']); } - /** - * @expectedException \FOS\HttpCache\Exception\InvalidArgumentException - */ public function testBanPathEmptyHost() { $varnish = new Varnish($this->httpDispatcher); $hosts = []; + $this->expectException(InvalidArgumentException::class); $varnish->banPath('/articles/.*', 'text/html', $hosts); } @@ -223,7 +222,7 @@ public function testRefresh() function (RequestInterface $request) { $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/fresh', $request->getUri()); - $this->assertContains('no-cache', $request->getHeaderLine('Cache-Control')); + $this->assertStringContainsString('no-cache', $request->getHeaderLine('Cache-Control')); return true; } diff --git a/tests/Unit/SymfonyCache/CacheEventTest.php b/tests/Unit/SymfonyCache/CacheEventTest.php index c41bf28d..54507307 100644 --- a/tests/Unit/SymfonyCache/CacheEventTest.php +++ b/tests/Unit/SymfonyCache/CacheEventTest.php @@ -13,6 +13,7 @@ use FOS\HttpCache\SymfonyCache\CacheEvent; use FOS\HttpCache\SymfonyCache\CacheInvalidation; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -21,11 +22,11 @@ class CacheEventTest extends TestCase { /** - * @var CacheInvalidation|\PHPUnit_Framework_MockObject_MockObject + * @var CacheInvalidation&MockObject */ private $kernel; - public function setUp() + public function setUp(): void { $this->kernel = $this->createMock(CacheInvalidation::class); } diff --git a/tests/Unit/SymfonyCache/CustomTtlListenerTest.php b/tests/Unit/SymfonyCache/CustomTtlListenerTest.php index da50f023..7c86198d 100644 --- a/tests/Unit/SymfonyCache/CustomTtlListenerTest.php +++ b/tests/Unit/SymfonyCache/CustomTtlListenerTest.php @@ -25,11 +25,11 @@ class CustomTtlListenerTest extends TestCase use MockeryPHPUnitIntegration; /** - * @var CacheInvalidation|MockInterface + * @var CacheInvalidation&MockInterface */ private $kernel; - public function setUp() + public function setUp(): void { $this->kernel = \Mockery::mock(CacheInvalidation::class); } diff --git a/tests/Unit/SymfonyCache/DebugListenerTest.php b/tests/Unit/SymfonyCache/DebugListenerTest.php index e8107f79..7ae21deb 100644 --- a/tests/Unit/SymfonyCache/DebugListenerTest.php +++ b/tests/Unit/SymfonyCache/DebugListenerTest.php @@ -15,6 +15,7 @@ use FOS\HttpCache\SymfonyCache\CacheInvalidation; use FOS\HttpCache\SymfonyCache\DebugListener; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -24,11 +25,11 @@ class DebugListenerTest extends TestCase use MockeryPHPUnitIntegration; /** - * @var CacheInvalidation|\PHPUnit_Framework_MockObject_MockObject + * @var CacheInvalidation&MockObject */ private $kernel; - public function setUp() + public function setUp(): void { $this->kernel = \Mockery::mock(CacheInvalidation::class); } diff --git a/tests/Unit/SymfonyCache/PurgeListenerTest.php b/tests/Unit/SymfonyCache/PurgeListenerTest.php index 27795103..6eea81e5 100644 --- a/tests/Unit/SymfonyCache/PurgeListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeListenerTest.php @@ -29,12 +29,11 @@ class PurgeListenerTest extends TestCase /** * This tests a sanity check in the AbstractControlledListener. - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage You may not set both a request matcher and an IP */ public function testConstructorOverspecified() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('You may not set both a request matcher and an IP'); new PurgeListener([ 'client_matcher' => new RequestMatcher('/forbidden'), 'client_ips' => ['1.2.3.4'], @@ -178,12 +177,10 @@ public function testOtherMethod() $this->assertNull($event->getResponse()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage does not exist - */ public function testInvalidConfiguration() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('does not exist'); new PurgeListener(['stuff' => '1.2.3.4']); } diff --git a/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php b/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php index ca18c7e4..205850b9 100644 --- a/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php @@ -27,7 +27,7 @@ class PurgeTagsListenerTest extends TestCase { use MockeryPHPUnitIntegration; - public function setUp() + public function setUp(): void { if (!class_exists(Psr6StoreInterface::class)) { $this->markTestSkipped('toflar/psr6-symfony-http-cache-store not available'); @@ -36,12 +36,11 @@ public function setUp() /** * This tests a sanity check in the AbstractControlledListener. - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage You may not set both a request matcher and an IP */ public function testConstructorOverspecified() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('You may not set both a request matcher and an IP'); new PurgeTagsListener([ 'client_matcher' => new RequestMatcher('/forbidden'), 'client_ips' => ['1.2.3.4'], @@ -170,12 +169,10 @@ public function testOtherMethod() $this->assertNull($event->getResponse()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage does not exist - */ public function testInvalidConfiguration() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('does not exist'); new PurgeTagsListener(['stuff' => '1.2.3.4']); } diff --git a/tests/Unit/SymfonyCache/RefreshListenerTest.php b/tests/Unit/SymfonyCache/RefreshListenerTest.php index f911f906..aa19a5c2 100644 --- a/tests/Unit/SymfonyCache/RefreshListenerTest.php +++ b/tests/Unit/SymfonyCache/RefreshListenerTest.php @@ -14,6 +14,7 @@ use FOS\HttpCache\SymfonyCache\CacheEvent; use FOS\HttpCache\SymfonyCache\CacheInvalidation; use FOS\HttpCache\SymfonyCache\RefreshListener; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcher; @@ -22,11 +23,11 @@ class RefreshListenerTest extends TestCase { /** - * @var CacheInvalidation|\PHPUnit_Framework_MockObject_MockObject + * @var CacheInvalidation&MockObject */ private $kernel; - public function setUp() + public function setUp(): void { $this->kernel = $this->createMock(CacheInvalidation::class); } @@ -119,12 +120,10 @@ public function testNoRefresh() $this->assertNull($event->getResponse()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage does not exist - */ public function testInvalidConfiguration() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('does not exist'); new RefreshListener(['stuff' => '1.2.3.4']); } } diff --git a/tests/Unit/SymfonyCache/UserContextListenerTest.php b/tests/Unit/SymfonyCache/UserContextListenerTest.php index aaacba30..4c94c1a3 100644 --- a/tests/Unit/SymfonyCache/UserContextListenerTest.php +++ b/tests/Unit/SymfonyCache/UserContextListenerTest.php @@ -29,7 +29,7 @@ class UserContextListenerTest extends TestCase */ private $kernel; - public function setUp() + public function setUp(): void { $this->kernel = \Mockery::mock(CacheInvalidation::class); } @@ -305,12 +305,10 @@ function (Request $request) use ($that, $hashRequest) { $this->assertSame($expectedContextHash, $request->headers->get($options['user_hash_header'])); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage does not exist - */ public function testInvalidConfiguration() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('does not exist'); new UserContextListener(['foo' => 'bar']); } diff --git a/tests/Unit/Test/NginxTestTest.php b/tests/Unit/Test/NginxTestTest.php index 1c187b4c..719d7b92 100644 --- a/tests/Unit/Test/NginxTestTest.php +++ b/tests/Unit/Test/NginxTestTest.php @@ -19,7 +19,7 @@ class NginxTestTest extends TestCase { use NginxTest; - protected function setUp() + protected function setUp(): void { // do not try to set up proxy } diff --git a/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php b/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php index f223d391..f01ce617 100644 --- a/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php +++ b/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php @@ -13,6 +13,7 @@ use FOS\HttpCache\Test\PHPUnit\IsCacheHitConstraint; use GuzzleHttp\Psr7\Stream; +use PHPUnit\Framework\ExpectationFailedException; // phpunit 5 has forward compatibility classes but missed this one if (!class_exists('\PHPUnit\Framework\ExpectationFailedException')) { @@ -26,15 +27,11 @@ class IsCacheHitConstraintTest extends AbstractCacheConstraintTest */ private $constraint; - public function setUp() + public function setUp(): void { $this->constraint = new IsCacheHitConstraint('cache-header'); } - /** - * @expectedException \PHPUnit\Framework\ExpectationFailedException - * @expectedExceptionMessage Failed asserting that response (with status code 500) is a cache hit - */ public function testMatches() { $response = $this->getResponseMock() @@ -45,15 +42,16 @@ public function testMatches() ->shouldReceive('getBody')->andReturn(new Stream(fopen('php://temp', 'r+'))) ->getMock(); + $this->expectException(ExpectationFailedException::class); + $this->expectExceptionMessage('Failed asserting that response (with status code 500) is a cache hit'); $this->constraint->evaluate($response); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Response has no "cache-header" header - */ public function testMatchesThrowsExceptionIfHeaderIsMissing() { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Response has no "cache-header" header'); + $response = $this->getResponseMock() ->shouldReceive('hasHeader')->with('cache-header')->once()->andReturn(false) ->shouldReceive('getStatusCode')->andReturn(200) diff --git a/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php b/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php index efdc5f9f..6ab50169 100644 --- a/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php +++ b/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php @@ -12,6 +12,7 @@ namespace FOS\HttpCache\Tests\Unit\Test\PHPUnit; use FOS\HttpCache\Test\PHPUnit\IsCacheMissConstraint; +use PHPUnit\Framework\ExpectationFailedException; // phpunit 5 has forward compatibility classes but missed this one if (!class_exists('\PHPUnit\Framework\ExpectationFailedException')) { @@ -25,15 +26,11 @@ class IsCacheMissConstraintTest extends AbstractCacheConstraintTest */ private $constraint; - public function setUp() + public function setUp(): void { $this->constraint = new IsCacheMissConstraint('cache-header'); } - /** - * @expectedException \PHPUnit\Framework\ExpectationFailedException - * @expectedExceptionMessage Failed asserting that response (with status code 200) is a cache miss - */ public function testMatches() { $response = $this->getResponseMock() @@ -42,6 +39,9 @@ public function testMatches() ->shouldReceive('getStatusCode')->andReturn(200) ->getMock(); + $this->expectException(ExpectationFailedException::class); + $this->expectExceptionMessage('Failed asserting that response (with status code 200) is a cache miss'); + $this->constraint->evaluate($response); } } diff --git a/tests/Unit/Test/Proxy/AbstractProxyTest.php b/tests/Unit/Test/Proxy/AbstractProxyTest.php index 9543f4a6..083ac61d 100644 --- a/tests/Unit/Test/Proxy/AbstractProxyTest.php +++ b/tests/Unit/Test/Proxy/AbstractProxyTest.php @@ -16,23 +16,19 @@ class AbstractProxyTest extends TestCase { - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Caching proxy still up at - */ public function testWaitTimeout() { $proxy = new ProxyPartial(); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Caching proxy still up at'); $proxy->start(); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage /path/to/not/exists - */ public function testRunFailure() { $proxy = new ProxyPartial(); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('/path/to/not/exists'); $proxy->run(); } } diff --git a/tests/Unit/Test/Proxy/SymfonyProxyTest.php b/tests/Unit/Test/Proxy/SymfonyProxyTest.php index b5e613a8..ccfffdc0 100644 --- a/tests/Unit/Test/Proxy/SymfonyProxyTest.php +++ b/tests/Unit/Test/Proxy/SymfonyProxyTest.php @@ -23,13 +23,11 @@ public function testStart() $proxy->stop(); } - /** - * @expectedException \RuntimeException - */ public function testInvalidDirectoryThrowsException() { define('SYMFONY_CACHE_DIR', '/'); $proxy = new SymfonyProxy(); + $this->expectException(\RuntimeException::class); $proxy->getCacheDir(); } } diff --git a/tests/Unit/Test/Proxy/VarnishProxyTest.php b/tests/Unit/Test/Proxy/VarnishProxyTest.php index ac3f008b..287e0b42 100644 --- a/tests/Unit/Test/Proxy/VarnishProxyTest.php +++ b/tests/Unit/Test/Proxy/VarnishProxyTest.php @@ -16,12 +16,11 @@ class VarnishProxyTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Cannot find config file: nope.vcl - */ public function testInvalidConfigFileThrowsException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Cannot find config file: nope.vcl'); + new VarnishProxy('nope.vcl'); } @@ -62,15 +61,13 @@ public function testStart($inlineC) $this->assertEquals($arguments, $proxy->arguments); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Caching proxy cannot be reached at 127.0.0.1:6181 - */ public function testWaitThrowsException() { $proxy = new VarnishProxyMock('config.vcl'); $proxy->wait = false; + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Caching proxy cannot be reached at 127.0.0.1:6181'); $proxy->start(); } } diff --git a/tests/Unit/Test/VarnishTestTest.php b/tests/Unit/Test/VarnishTestTest.php index edfddeec..69c27229 100644 --- a/tests/Unit/Test/VarnishTestTest.php +++ b/tests/Unit/Test/VarnishTestTest.php @@ -19,7 +19,7 @@ class VarnishTestTest extends TestCase { use VarnishTest; - protected function setUp() + protected function setUp(): void { // do not try to set up proxy } diff --git a/tests/Unit/UserContext/HashGeneratorTest.php b/tests/Unit/UserContext/HashGeneratorTest.php index c4b5fa36..3926f642 100644 --- a/tests/Unit/UserContext/HashGeneratorTest.php +++ b/tests/Unit/UserContext/HashGeneratorTest.php @@ -11,6 +11,7 @@ namespace FOS\HttpCache\Tests\Unit\UserContext; +use FOS\HttpCache\Exception\InvalidArgumentException; use FOS\HttpCache\UserContext\ContextProvider; use FOS\HttpCache\UserContext\DefaultHashGenerator; use FOS\HttpCache\UserContext\UserContext; @@ -27,11 +28,9 @@ public function testGenerateHash() $this->assertEquals($expectedHash, $hashGenerator->generateHash()); } - /** - * @expectedException \FOS\HttpCache\Exception\InvalidArgumentException - */ public function testConstructorError() { + $this->expectException(InvalidArgumentException::class); new DefaultHashGenerator([]); } } From e25654ec3a2c80bfb0e837a55bc511a9cbba05c4 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 5 Feb 2020 09:42:00 +0100 Subject: [PATCH 3/3] fix test to avoid deprecation warning and ignore indirect deprecations --- .travis.yml | 1 + tests/Unit/ProxyClient/HttpDispatcherTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 20b5b41c..04a900c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ env: global: - VARNISH_VERSION=5.1 - SYMFONY_PHPUNIT_VERSION=8 + - SYMFONY_DEPRECATIONS_HELPER="max[self]=0" - DEPENDENCIES="toflar/psr6-symfony-http-cache-store:^2.2.0" matrix: diff --git a/tests/Unit/ProxyClient/HttpDispatcherTest.php b/tests/Unit/ProxyClient/HttpDispatcherTest.php index c90111a3..162de5e5 100644 --- a/tests/Unit/ProxyClient/HttpDispatcherTest.php +++ b/tests/Unit/ProxyClient/HttpDispatcherTest.php @@ -203,7 +203,7 @@ public function testSetBasePathWithPath() 'http://fos.lo/my/path', $this->httpClient ); - $request = $this->messageFactory->createRequest('PURGE', 'append'); + $request = $this->messageFactory->createRequest('PURGE', '/append'); $httpDispatcher->invalidate($request); $httpDispatcher->flush();