From c5e8e227e8a6bd837b963653f002a5a7d9be1f65 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 1 Jan 2025 18:24:37 +0100 Subject: [PATCH 1/7] fix whitespace --- doc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Makefile b/doc/Makefile index 1a35bb06..d3813085 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -154,5 +154,5 @@ doctest: "results in $(BUILDDIR)/doctest/output.txt." spelling: - $(SPHINXBUILD) -b spelling $(ALLSPHINXOPTS) -w $(BUILDDIR)/spelling/output.txt $(BUILDDIR)/spelling + $(SPHINXBUILD) -b spelling $(ALLSPHINXOPTS) -w $(BUILDDIR)/spelling/output.txt $(BUILDDIR)/spelling @echo "Spelling report generated in $(BUILDDIR)/spelling/output.txt" From 919509c9dc883e6e77febb3c9df4539c12e6b634 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 2 Jan 2025 20:14:19 +0100 Subject: [PATCH 2/7] phpstan level 2 --- composer.json | 6 ++++-- phpstan.neon.dist | 3 ++- src/SymfonyCache/PurgeTagsListener.php | 2 +- src/Test/EventDispatchingHttpCacheTestCase.php | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2210731c..35ed9375 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "php-http/discovery": "^1.12", "php-http/async-client-implementation": "^1.1.0 || ^2.0", "psr/http-client-implementation": "^1.0 || ^2.0", - "psr/http-factory": "^1.0" + "psr/http-factory": "^1.0", + "toflar/psr6-symfony-http-cache-store": "^4.2" }, "require-dev": { "mockery/mockery": "^1.6.0", @@ -37,7 +38,8 @@ "php-http/mock-client": "^1.6.0", "symfony/process": "^6.4|| ^7.0", "symfony/http-kernel": "^6.4|| ^7.0", - "phpunit/phpunit": "^10.5" + "phpunit/phpunit": "^10.5", + "http-interop/http-factory-guzzle": "^0.1.0" }, "conflict": { "toflar/psr6-symfony-http-cache-store": "<2.2.1" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 77c3651a..cd728031 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,4 +1,5 @@ parameters: - level: 1 + level: 2 paths: - src + diff --git a/src/SymfonyCache/PurgeTagsListener.php b/src/SymfonyCache/PurgeTagsListener.php index acf863c8..7ed4c2ec 100644 --- a/src/SymfonyCache/PurgeTagsListener.php +++ b/src/SymfonyCache/PurgeTagsListener.php @@ -118,7 +118,7 @@ public function handlePurgeTags(CacheEvent $event): void if (1 === $reflection->getMethod('all')->getNumberOfParameters()) { $headers = $request->headers->all($this->tagsHeader); } else { - $headers = $request->headers->get($this->tagsHeader, '', false); + $headers = $request->headers->get($this->tagsHeader, ''); } $tags = $this->tagsParser->parseTagsHeaderValue($headers); diff --git a/src/Test/EventDispatchingHttpCacheTestCase.php b/src/Test/EventDispatchingHttpCacheTestCase.php index 99a4a59e..0794e444 100644 --- a/src/Test/EventDispatchingHttpCacheTestCase.php +++ b/src/Test/EventDispatchingHttpCacheTestCase.php @@ -251,6 +251,7 @@ public function testPreStoreResponseNoStore() $httpCache = $this->getHttpCachePartialMock(); $testListener = new TestListener($this, $httpCache, $request); $testListener->preStoreResponse = $preStoreResponse; + $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache->addSubscriber($testListener); $store = $this->createMock(StoreInterface::class); @@ -279,6 +280,7 @@ public function testPreInvalidateCalled(): void $httpCache = $this->getHttpCachePartialMock(['pass']); $testListener = new TestListener($this, $httpCache, $request); + $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache->addSubscriber($testListener); $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache @@ -307,6 +309,7 @@ public function testPreInvalidateReturnEarly(): void $httpCache = $this->getHttpCachePartialMock(['pass']); $testListener = new TestListener($this, $httpCache, $request); $testListener->preInvalidateResponse = $response; + $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache->addSubscriber($testListener); $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache @@ -327,6 +330,7 @@ public function testAddListener(): void $httpCache = $this->getHttpCachePartialMock(['lookup']); $simpleListener = new SimpleListener($this, $httpCache, $request); + $this->assertTrue(method_exists($httpCache, 'addListener')); $httpCache->addListener(Events::PRE_HANDLE, [$simpleListener, 'callback']); $httpCache From 6113fec3622b93d328fb3efc495b72cd89f91e46 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 2 Jan 2025 20:15:07 +0100 Subject: [PATCH 3/7] phpstan level 3 --- composer.json | 6 ++---- phpstan.neon.dist | 2 +- src/Test/EventDispatchingHttpCacheTestCase.php | 2 -- src/Test/WebServerSubscriber.php | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 35ed9375..2210731c 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,7 @@ "php-http/discovery": "^1.12", "php-http/async-client-implementation": "^1.1.0 || ^2.0", "psr/http-client-implementation": "^1.0 || ^2.0", - "psr/http-factory": "^1.0", - "toflar/psr6-symfony-http-cache-store": "^4.2" + "psr/http-factory": "^1.0" }, "require-dev": { "mockery/mockery": "^1.6.0", @@ -38,8 +37,7 @@ "php-http/mock-client": "^1.6.0", "symfony/process": "^6.4|| ^7.0", "symfony/http-kernel": "^6.4|| ^7.0", - "phpunit/phpunit": "^10.5", - "http-interop/http-factory-guzzle": "^0.1.0" + "phpunit/phpunit": "^10.5" }, "conflict": { "toflar/psr6-symfony-http-cache-store": "<2.2.1" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index cd728031..43924227 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 2 + level: 3 paths: - src diff --git a/src/Test/EventDispatchingHttpCacheTestCase.php b/src/Test/EventDispatchingHttpCacheTestCase.php index 0794e444..8cc80dad 100644 --- a/src/Test/EventDispatchingHttpCacheTestCase.php +++ b/src/Test/EventDispatchingHttpCacheTestCase.php @@ -282,7 +282,6 @@ public function testPreInvalidateCalled(): void $testListener = new TestListener($this, $httpCache, $request); $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache->addSubscriber($testListener); - $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache ->method('pass') ->with($request) @@ -311,7 +310,6 @@ public function testPreInvalidateReturnEarly(): void $testListener->preInvalidateResponse = $response; $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache->addSubscriber($testListener); - $this->assertTrue(method_exists($httpCache, 'addSubscriber')); $httpCache ->expects($this->never()) ->method('pass') diff --git a/src/Test/WebServerSubscriber.php b/src/Test/WebServerSubscriber.php index 8d25bb19..3e26b49f 100644 --- a/src/Test/WebServerSubscriber.php +++ b/src/Test/WebServerSubscriber.php @@ -83,7 +83,7 @@ public function startPhpWebServer(): int $this->waitFor($this->getHostName(), (int) $this->getPort(), 2000); - return $output[0]; + return (int) $output[0]; } public function getHostName(): string From fa7742a9e4f016debaf20046c26d7f75f8313c58 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 3 Jan 2025 09:56:37 +0100 Subject: [PATCH 4/7] phpstan level 2 for tests --- .github/workflows/static.yml | 3 ++- phpstan.tests.neon.dist | 3 ++- .../Functional/Symfony/EventDispatchingHttpCacheTest.php | 2 ++ tests/Unit/CacheInvalidatorTest.php | 8 ++++++++ tests/Unit/ResponseTaggerTest.php | 6 ++++++ tests/Unit/Test/PHPUnit/IsCacheHitConstraintTestCase.php | 4 ++++ tests/Unit/Test/PHPUnit/IsCacheMissConstraintTestCase.php | 2 ++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 89c48eb1..970bf8fb 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -41,7 +41,8 @@ jobs: uses: actions/checkout@v4 - name: Pull in optional dependencies - run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 + run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 phpstan/phpstan-mockery + - name: Cache Vendor id: cache-vendor diff --git a/phpstan.tests.neon.dist b/phpstan.tests.neon.dist index 0efe94d4..bcef90bc 100644 --- a/phpstan.tests.neon.dist +++ b/phpstan.tests.neon.dist @@ -1,4 +1,5 @@ parameters: - level: 1 + level: 2 paths: - tests + diff --git a/tests/Functional/Symfony/EventDispatchingHttpCacheTest.php b/tests/Functional/Symfony/EventDispatchingHttpCacheTest.php index e2c1bafa..ef76c7e4 100644 --- a/tests/Functional/Symfony/EventDispatchingHttpCacheTest.php +++ b/tests/Functional/Symfony/EventDispatchingHttpCacheTest.php @@ -44,6 +44,8 @@ public function testEventListeners(): void ->shouldReceive('handle') ->andReturn($expectedResponse) ->getMock(); + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $store = \Mockery::mock(StoreInterface::class) ->shouldReceive('lookup')->andReturn(null)->times(1) ->shouldReceive('write')->times(1) diff --git a/tests/Unit/CacheInvalidatorTest.php b/tests/Unit/CacheInvalidatorTest.php index 71becd08..db50f578 100644 --- a/tests/Unit/CacheInvalidatorTest.php +++ b/tests/Unit/CacheInvalidatorTest.php @@ -78,6 +78,8 @@ public function testSupportsInvalid(): void public function testInvalidatePath(): void { /** @var MockInterface&PurgeCapable $purge */ + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $purge = \Mockery::mock(PurgeCapable::class) ->shouldReceive('purge')->once()->with('/my/route', []) ->shouldReceive('purge')->once()->with('/my/route', ['X-Test-Header' => 'xyz']) @@ -97,6 +99,8 @@ public function testRefreshPath(): void { $headers = ['X' => 'Y']; /** @var MockInterface&RefreshCapable $refresh */ + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $refresh = \Mockery::mock(RefreshCapable::class) ->shouldReceive('refresh')->once()->with('/my/route', $headers) ->shouldReceive('flush')->never() @@ -190,6 +194,8 @@ public function testProxyClientExceptionsAreLogged(): void $unreachableException = ProxyUnreachableException::proxyUnreachable($clientException); + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $response = \Mockery::mock(ResponseInterface::class) ->shouldReceive('getStatusCode')->andReturn(403) ->shouldReceive('getReasonPhrase')->andReturn('Forbidden') @@ -206,6 +212,8 @@ public function testProxyClientExceptionsAreLogged(): void $cacheInvalidator = new CacheInvalidator($proxyClient); + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $logger = \Mockery::mock(LoggerInterface::class) ->shouldReceive('log')->once() ->with( diff --git a/tests/Unit/ResponseTaggerTest.php b/tests/Unit/ResponseTaggerTest.php index d87537f2..a8309624 100644 --- a/tests/Unit/ResponseTaggerTest.php +++ b/tests/Unit/ResponseTaggerTest.php @@ -48,6 +48,8 @@ public function testGetTagsHeaderValue(): void public function testTagResponseReplace(): void { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $headerFormatter = \Mockery::mock(TagHeaderFormatter::class) ->shouldReceive('getTagsHeaderValue') ->with(['tag-1', 'tag-2']) @@ -73,6 +75,8 @@ public function testTagResponseReplace(): void public function testTagResponseAdd(): void { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $headerFormatter = \Mockery::mock(TagHeaderFormatter::class) ->shouldReceive('getTagsHeaderValue') ->with(['tag-1', 'tag-2']) @@ -105,6 +109,8 @@ public function testTagResponseNoTags(): void $tagger = new ResponseTagger(['header_formatter' => $headerFormatter]); + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $response = \Mockery::mock(ResponseInterface::class) ->shouldReceive('withHeader')->never() ->shouldReceive('withAddedHeader')->never() diff --git a/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTestCase.php b/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTestCase.php index 195df43a..58bda109 100644 --- a/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTestCase.php +++ b/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTestCase.php @@ -26,6 +26,8 @@ public function setUp(): void public function testMatches(): void { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $response = $this->getResponseMock() ->shouldReceive('hasHeader')->with('cache-header')->andReturn(true) ->shouldReceive('getHeaderLine')->with('cache-header')->once()->andReturn('MISS') @@ -44,6 +46,8 @@ public function testMatchesThrowsExceptionIfHeaderIsMissing(): void $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Response has no "cache-header" header'); + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $response = $this->getResponseMock() ->shouldReceive('hasHeader')->with('cache-header')->once()->andReturn(false) ->shouldReceive('getStatusCode')->andReturn(200) diff --git a/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTestCase.php b/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTestCase.php index e86c3051..4f4133bc 100644 --- a/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTestCase.php +++ b/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTestCase.php @@ -25,6 +25,8 @@ public function setUp(): void public function testMatches(): void { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ $response = $this->getResponseMock() ->shouldReceive('hasHeader')->with('cache-header')->andReturn(true) ->shouldReceive('getHeaderLine')->with('cache-header')->once()->andReturn('HIT') From 2b8f87e1e48dcd1e8c64fb32712691037a6ffdca Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 3 Jan 2025 10:00:28 +0100 Subject: [PATCH 5/7] phpstan level 3 for tests --- phpstan.tests.neon.dist | 3 +-- tests/Unit/SymfonyCache/PurgeListenerTest.php | 4 ++++ tests/Unit/SymfonyCache/PurgeTagsListenerTest.php | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/phpstan.tests.neon.dist b/phpstan.tests.neon.dist index bcef90bc..1a7201ba 100644 --- a/phpstan.tests.neon.dist +++ b/phpstan.tests.neon.dist @@ -1,5 +1,4 @@ parameters: - level: 2 + level: 3 paths: - tests - diff --git a/tests/Unit/SymfonyCache/PurgeListenerTest.php b/tests/Unit/SymfonyCache/PurgeListenerTest.php index a8396bd3..f682abce 100644 --- a/tests/Unit/SymfonyCache/PurgeListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeListenerTest.php @@ -187,6 +187,8 @@ public function testInvalidConfiguration(): void private function getKernelMock(StoreInterface $store): MockInterface&CacheInvalidation { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldReceive('getStore') ->once() @@ -196,6 +198,8 @@ private function getKernelMock(StoreInterface $store): MockInterface&CacheInvali private function getUnusedKernelMock(): CacheInvalidation&MockInterface { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldNotReceive('getStore') ->getMock(); diff --git a/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php b/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php index 8e06ff30..086102fa 100644 --- a/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php @@ -180,6 +180,8 @@ public function testInvalidConfiguration(): void private function getKernelMock(StoreInterface $store): CacheInvalidation&MockInterface { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldReceive('getStore') ->once() @@ -189,6 +191,8 @@ private function getKernelMock(StoreInterface $store): CacheInvalidation&MockInt private function getUnusedKernelMock(): CacheInvalidation&MockInterface { + // https://github.com/phpstan/phpstan-mockery/issues/8 + /** @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldNotReceive('getStore') ->getMock(); From 0ea68447333ebdaadbc94fe836b3db497085de17 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 3 Jan 2025 10:12:00 +0100 Subject: [PATCH 6/7] phpstan level 4, merge src and tests phpstan --- .github/workflows/static.yml | 28 +--------------- phpstan.neon.dist | 5 ++- phpstan.tests.neon.dist | 4 --- src/ProxyClient/Cloudflare.php | 16 ++------- tests/Unit/SymfonyCache/CacheAwareTest.php | 39 ++++++++++++++++++++++ 5 files changed, 47 insertions(+), 45 deletions(-) delete mode 100644 phpstan.tests.neon.dist create mode 100644 tests/Unit/SymfonyCache/CacheAwareTest.php diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 970bf8fb..6aa269f7 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v4 - name: Pull in optional dependencies - run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 symfony/process + run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 symfony/process phpstan/phpstan-mockery - name: Cache Vendor id: cache-vendor @@ -30,32 +30,6 @@ jobs: with: args: analyze --no-progress - phpstan-tests: - name: PHPStan tests - runs-on: ubuntu-latest - env: - REQUIRE_DEV: "true" - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Pull in optional dependencies - run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 phpstan/phpstan-mockery - - - - name: Cache Vendor - id: cache-vendor - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-vendor - - - name: PHPStan - uses: docker://oskarstark/phpstan-ga - with: - args: analyze --no-progress -c phpstan.tests.neon.dist - php-cs-fixer: name: PHP-CS-Fixer runs-on: ubuntu-latest diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 43924227..74898875 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,8 @@ parameters: - level: 3 + level: 4 paths: - src + - tests +includes: + - vendor/phpstan/phpstan-mockery/extension.neon diff --git a/phpstan.tests.neon.dist b/phpstan.tests.neon.dist deleted file mode 100644 index 1a7201ba..00000000 --- a/phpstan.tests.neon.dist +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - level: 3 - paths: - - tests diff --git a/src/ProxyClient/Cloudflare.php b/src/ProxyClient/Cloudflare.php index 8f9bad97..785a7bf4 100644 --- a/src/ProxyClient/Cloudflare.php +++ b/src/ProxyClient/Cloudflare.php @@ -81,7 +81,7 @@ public function invalidateTags(array $tags): static sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']), [], false, - $this->json_encode(['tags' => $tags]) + json_encode(['tags' => $tags], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES) ); return $this; @@ -115,7 +115,7 @@ public function clear(): static sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']), ['Accept' => 'application/json'], false, - $this->json_encode(['purge_everything' => true]) + json_encode(['purge_everything' => true], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES) ); return $this; @@ -130,7 +130,7 @@ public function flush(): int sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']), [], false, - $this->json_encode(['files' => $urlChunk]) + json_encode(['files' => $urlChunk], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES) ); } $this->purgeByUrlsData = []; @@ -165,14 +165,4 @@ protected function configureOptions(): OptionsResolver return $resolver; } - - private function json_encode(array $data): string - { - $json = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES); - if (false === $json) { - throw new \InvalidArgumentException(sprintf('Cannot encode "$data": %s', json_last_error_msg())); - } - - return $json; - } } diff --git a/tests/Unit/SymfonyCache/CacheAwareTest.php b/tests/Unit/SymfonyCache/CacheAwareTest.php new file mode 100644 index 00000000..f8f9cbfb --- /dev/null +++ b/tests/Unit/SymfonyCache/CacheAwareTest.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\HttpCache\Tests\Unit\SymfonyCache; + +use FOS\HttpCache\SymfonyCache\HttpCacheAware; +use FOS\HttpCache\SymfonyCache\HttpCacheProvider; +use PHPUnit\Framework\TestCase; + use Symfony\Component\HttpKernel\HttpKernelInterface; + +class CacheAwareTest extends TestCase +{ + private HttpKernelInterface $cacheKernel; + + protected function setUp(): void + { + $this->cacheKernel = $this->createMock(HttpKernelInterface::class); + } + + public function testCacheGetterSetter(): void + { + $aware = new AppHttpCacheAware(); + $aware->setHttpCache($this->cacheKernel); + $this->assertSame($this->cacheKernel, $aware->getHttpCache()); + } +} + +class AppHttpCacheAware implements HttpCacheProvider +{ + use HttpCacheAware; +} From 50de1fa7df0dafce9e3d0ea926912157c0cbdacd Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 3 Jan 2025 10:25:16 +0100 Subject: [PATCH 7/7] phpstan level 4 --- .github/workflows/static.yml | 4 ++-- phpstan.neon.dist | 3 +-- src/ProxyClient/MultiplexerClient.php | 6 ++++-- src/Test/WebServerSubscriber.php | 3 --- tests/Functional/ProxyClient/NginxProxyClientTest.php | 4 ++-- tests/Unit/SymfonyCache/CacheAwareTest.php | 2 +- tests/Unit/SymfonyCache/KernelDispatcherTest.php | 3 +-- tests/Unit/SymfonyCache/PurgeListenerTest.php | 4 ++-- tests/Unit/SymfonyCache/PurgeTagsListenerTest.php | 4 ++-- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 6aa269f7..9b07dcc9 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -8,7 +8,7 @@ on: jobs: phpstan-src: - name: PHPStan src + name: PHPStan runs-on: ubuntu-latest steps: @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v4 - name: Pull in optional dependencies - run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 symfony/process phpstan/phpstan-mockery + run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 symfony/process mockery/mockery phpstan/phpstan-mockery guzzlehttp/guzzle php-http/mock-client - name: Cache Vendor id: cache-vendor diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 74898875..e03bb8ad 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,5 +4,4 @@ parameters: - src - tests -includes: - - vendor/phpstan/phpstan-mockery/extension.neon + treatPhpDocTypesAsCertain: false diff --git a/src/ProxyClient/MultiplexerClient.php b/src/ProxyClient/MultiplexerClient.php index e31d5bc5..896fbbe1 100644 --- a/src/ProxyClient/MultiplexerClient.php +++ b/src/ProxyClient/MultiplexerClient.php @@ -133,7 +133,7 @@ public function clear(): static * Invoke the given $method on all available ProxyClients implementing the * given $interface. * - * @param string $interface The FQN of the interface + * @param class-string $interface The FQN of the interface * @param string $method The method to invoke * @param array $arguments The arguments to be passed to the method */ @@ -155,7 +155,9 @@ private function getProxyClients(string $interface): array { return array_filter( $this->proxyClients, - static function ($proxyClient) use ($interface) { + static function (ProxyClient $proxyClient) use ($interface) { + // https://github.com/phpstan/phpstan/issues/8464 + // @phpstan-ignore-next-line return is_subclass_of($proxyClient, $interface); } ); diff --git a/src/Test/WebServerSubscriber.php b/src/Test/WebServerSubscriber.php index 3e26b49f..82b9aca2 100644 --- a/src/Test/WebServerSubscriber.php +++ b/src/Test/WebServerSubscriber.php @@ -11,7 +11,6 @@ namespace FOS\HttpCache\Test; -use PHPUnit\Event\Code\TestMethod; use PHPUnit\Event\TestRunner\ExecutionStarted; use PHPUnit\Event\TestRunner\ExecutionStartedSubscriber; use PHPUnit\Event\TestSuite\TestSuite; @@ -52,8 +51,6 @@ private function hasTestsWithGroup(TestSuite $testSuite, string $group): bool continue; } - assert($test instanceof TestMethod); - foreach ($test->metadata()->isGroup() as $testGroup) { assert($testGroup instanceof Group); diff --git a/tests/Functional/ProxyClient/NginxProxyClientTest.php b/tests/Functional/ProxyClient/NginxProxyClientTest.php index e9ee423f..2df464e0 100644 --- a/tests/Functional/ProxyClient/NginxProxyClientTest.php +++ b/tests/Functional/ProxyClient/NginxProxyClientTest.php @@ -35,7 +35,7 @@ public function testPurgeContentType(): void { $this->markTestSkipped('Not working with nginx, it can only purge one type'); - $this->assertPurgeContentType($this->getProxyClient()); + // $this->assertPurgeContentType($this->getProxyClient()); } public function testPurgeSeparateLocationHost(): void @@ -57,6 +57,6 @@ public function testRefreshContentType(): void { $this->markTestSkipped('TODO: is nginx mixing up variants?'); - $this->assertRefreshContentType($this->getProxyClient()); + // $this->assertRefreshContentType($this->getProxyClient()); } } diff --git a/tests/Unit/SymfonyCache/CacheAwareTest.php b/tests/Unit/SymfonyCache/CacheAwareTest.php index f8f9cbfb..382ab6fc 100644 --- a/tests/Unit/SymfonyCache/CacheAwareTest.php +++ b/tests/Unit/SymfonyCache/CacheAwareTest.php @@ -14,7 +14,7 @@ use FOS\HttpCache\SymfonyCache\HttpCacheAware; use FOS\HttpCache\SymfonyCache\HttpCacheProvider; use PHPUnit\Framework\TestCase; - use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\HttpKernelInterface; class CacheAwareTest extends TestCase { diff --git a/tests/Unit/SymfonyCache/KernelDispatcherTest.php b/tests/Unit/SymfonyCache/KernelDispatcherTest.php index 0008e2d2..8820a109 100644 --- a/tests/Unit/SymfonyCache/KernelDispatcherTest.php +++ b/tests/Unit/SymfonyCache/KernelDispatcherTest.php @@ -33,8 +33,7 @@ public function testFlush(): void ->with($this->callback(function (Request $request) { // Test if the Symfony request contains the relevant information // from the PSR-7 request - $valid = true; - $valid = $valid && 'PURGETAGS' === $request->getMethod(); + $valid = 'PURGETAGS' === $request->getMethod(); $valid = $valid && 'foobar' === $request->headers->get('content-type'); $valid = $valid && 'foo,bar,stuff' === $request->headers->get('x-cache-tags'); $valid = $valid && ['query' => 'string', 'more' => 'stuff'] === $request->query->all(); diff --git a/tests/Unit/SymfonyCache/PurgeListenerTest.php b/tests/Unit/SymfonyCache/PurgeListenerTest.php index f682abce..86b4c9ce 100644 --- a/tests/Unit/SymfonyCache/PurgeListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeListenerTest.php @@ -188,7 +188,7 @@ public function testInvalidConfiguration(): void private function getKernelMock(StoreInterface $store): MockInterface&CacheInvalidation { // https://github.com/phpstan/phpstan-mockery/issues/8 - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldReceive('getStore') ->once() @@ -199,7 +199,7 @@ private function getKernelMock(StoreInterface $store): MockInterface&CacheInvali private function getUnusedKernelMock(): CacheInvalidation&MockInterface { // https://github.com/phpstan/phpstan-mockery/issues/8 - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldNotReceive('getStore') ->getMock(); diff --git a/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php b/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php index 086102fa..9bafeb49 100644 --- a/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeTagsListenerTest.php @@ -181,7 +181,7 @@ public function testInvalidConfiguration(): void private function getKernelMock(StoreInterface $store): CacheInvalidation&MockInterface { // https://github.com/phpstan/phpstan-mockery/issues/8 - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldReceive('getStore') ->once() @@ -192,7 +192,7 @@ private function getKernelMock(StoreInterface $store): CacheInvalidation&MockInt private function getUnusedKernelMock(): CacheInvalidation&MockInterface { // https://github.com/phpstan/phpstan-mockery/issues/8 - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return \Mockery::mock(CacheInvalidation::class) ->shouldNotReceive('getStore') ->getMock();