Skip to content
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

refactor to phpunit 10 event system #565

Merged
merged 1 commit into from
Mar 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

It is strange that I can not use the 3.x package when my PHPUnit version is 9.6 which is still a widely. used version of PHPUnit.

I would like to avoid this conflict think most of the people will not require a test besed on the WebServerSubscriber and so this should only be a softrequirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think you are right.

fixed in 24a47d5

},
"suggest": {
"friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework",
Expand Down
12 changes: 6 additions & 6 deletions doc/testing-your-application.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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.