Skip to content

Commit

Permalink
Merge pull request #565 from FriendsOfSymfony/refactor-to-phpunit-10-…
Browse files Browse the repository at this point in the history
…eventsystem

refactor to phpunit 10 event system
  • Loading branch information
dbu committed Mar 27, 2024
2 parents ce639ba + d06ce3f commit 4b4751b
Show file tree
Hide file tree
Showing 29 changed files with 168 additions and 650 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -37,11 +37,11 @@
"php-http/mock-client": "^1.6.0",
"symfony/process": "^6.4|| ^7.0",
"symfony/http-kernel": "^6.4|| ^7.0",
"phpunit/phpunit": "^9"
"phpunit/phpunit": "^10.5"
},
"conflict": {
"toflar/psr6-symfony-http-cache-store": "<2.2.1",
"phpunit/phpunit": "<8"
"phpunit/phpunit": "<10"
},
"suggest": {
"friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework",
Expand Down
12 changes: 6 additions & 6 deletions doc/testing-your-application.rst
Expand Up @@ -36,19 +36,19 @@ Web Server

You will need to run a web server to provide the PHP application you want to
test. The test cases only handle running the proxy server. It’s easiest to
use PHP’s built in web server. Include the WebServerListener in your
``phpunit.xml``:
use PHP’s built in web server. Include the WebServerSubscriber in your
``phpunit.xml``, either using the extension provided by this package or your own:

.. literalinclude:: ../phpunit.xml.dist
:prepend:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
<listeners>
<extensions>
:language: xml
:start-after: <listeners>
:end-before: </listeners>
:start-after: <extensions>
:end-before: </extensions>
:append:
</listeners>
</extensions>
</phpunit>

Then set the ``webserver`` group on your test to start PHP’s web server before
Expand Down
48 changes: 24 additions & 24 deletions phpunit.xml.dist
@@ -1,31 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
>
<testsuites>
<testsuite name="FOSHttpCache tests">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="FOSHttpCache tests">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="\FOS\HttpCache\Test\WebServerListener" />
</listeners>
<extensions>
<bootstrap class="FOS\HttpCache\Test\WebServerSubscriberExtension"/>
</extensions>

<php>
<const name="NGINX_FILE" value="./tests/Functional/Fixtures/nginx/fos.conf" />
<const name="WEB_SERVER_HOSTNAME" value="localhost" />
<const name="WEB_SERVER_PORT" value="8080" />
<const name="WEB_SERVER_DOCROOT" value="./tests/Functional/Fixtures/web" />
</php>
<const name="NGINX_FILE" value="./tests/Functional/Fixtures/nginx/fos.conf"/>
<const name="WEB_SERVER_HOSTNAME" value="localhost"/>
<const name="WEB_SERVER_PORT" value="8080"/>
<const name="WEB_SERVER_DOCROOT" value="./tests/Functional/Fixtures/web"/>
</php>

<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
18 changes: 10 additions & 8 deletions src/Test/EventDispatchingHttpCacheTestCase.php
Expand Up @@ -13,7 +13,6 @@

use FOS\HttpCache\SymfonyCache\CacheEvent;
use FOS\HttpCache\SymfonyCache\CacheInvalidation;
use FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache;
use FOS\HttpCache\SymfonyCache\Events;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -41,14 +40,9 @@ abstract protected function getCacheClass(): string;
*
* @param string[] $mockedMethods List of methods to mock
*/
protected function getHttpCachePartialMock(?array $mockedMethods = null): MockObject|CacheInvalidation|EventDispatchingHttpCache
protected function getHttpCachePartialMock(array $mockedMethods = []): MockObject&CacheInvalidation
{
$mock = $this
->getMockBuilder($this->getCacheClass())
->setMethods($mockedMethods)
->disableOriginalConstructor()
->getMock()
;
$mock = $this->createPartialMock($this->getCacheClass(), $mockedMethods);

$this->assertInstanceOf(CacheInvalidation::class, $mock);

Expand Down Expand Up @@ -103,6 +97,7 @@ public function testHandleCalled(): void

$httpCache = $this->getHttpCachePartialMock(['lookup']);
$testListener = new TestListener($this, $httpCache, $request);
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache->addSubscriber($testListener);
$httpCache
->method('lookup')
Expand All @@ -128,6 +123,7 @@ public function testPreHandleReturnEarly(): void
$httpCache = $this->getHttpCachePartialMock(['lookup']);
$testListener = new TestListener($this, $httpCache, $request);
$testListener->preHandleResponse = $response;
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache->addSubscriber($testListener);
$httpCache
->expects($this->never())
Expand All @@ -154,6 +150,7 @@ public function testPostHandleReturn(): void
$httpCache = $this->getHttpCachePartialMock(['lookup']);
$testListener = new TestListener($this, $httpCache, $request);
$testListener->postHandleResponse = $postResponse;
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache->addSubscriber($testListener);
$httpCache
->method('lookup')
Expand Down Expand Up @@ -182,6 +179,7 @@ public function testPostHandleAfterPreHandle(): void
$testListener = new TestListener($this, $httpCache, $request);
$testListener->preHandleResponse = $preResponse;
$testListener->postHandleResponse = $postResponse;
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache->addSubscriber($testListener);
$httpCache
->expects($this->never())
Expand All @@ -203,6 +201,7 @@ public function testPreStoreCalled(): void

$httpCache = $this->getHttpCachePartialMock();
$testListener = new TestListener($this, $httpCache, $request);
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache->addSubscriber($testListener);

$this->setStoreMock($httpCache, $request, $response);
Expand All @@ -225,6 +224,7 @@ public function testPreStoreResponse(): void
$httpCache = $this->getHttpCachePartialMock();
$testListener = new TestListener($this, $httpCache, $request);
$testListener->preStoreResponse = $preStoreResponse;
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache->addSubscriber($testListener);

$this->setStoreMock($httpCache, $request, $preStoreResponse);
Expand All @@ -247,6 +247,7 @@ public function testPreInvalidateCalled(): void
$httpCache = $this->getHttpCachePartialMock(['pass']);
$testListener = new TestListener($this, $httpCache, $request);
$httpCache->addSubscriber($testListener);
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache
->method('pass')
->with($request)
Expand Down Expand Up @@ -274,6 +275,7 @@ public function testPreInvalidateReturnEarly(): void
$testListener = new TestListener($this, $httpCache, $request);
$testListener->preInvalidateResponse = $response;
$httpCache->addSubscriber($testListener);
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
$httpCache
->expects($this->never())
->method('pass')
Expand Down
145 changes: 0 additions & 145 deletions src/Test/Legacy/WebServerListener.php

This file was deleted.

0 comments on commit 4b4751b

Please sign in to comment.