From 57d78d573d8665a1128b2da7b87300c36f28a7d7 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 3 Jan 2025 09:56:37 +0100 Subject: [PATCH] phpstan level 2 for tests --- .github/workflows/static.yml | 3 ++- phpstan.tests.neon.dist | 4 +++- .../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, 27 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..2bc9af34 100644 --- a/phpstan.tests.neon.dist +++ b/phpstan.tests.neon.dist @@ -1,4 +1,6 @@ parameters: - level: 1 + level: 2 paths: - tests +includes: + - vendor/phpstan/phpstan-mockery/extension.neon 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')