Skip to content

Commit

Permalink
phpstan level 2 for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 3, 2025
1 parent 6113fec commit 57d78d5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion phpstan.tests.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
parameters:
level: 1
level: 2
paths:
- tests
includes:
- vendor/phpstan/phpstan-mockery/extension.neon
2 changes: 2 additions & 0 deletions tests/Functional/Symfony/EventDispatchingHttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/CacheInvalidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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()
Expand Down Expand Up @@ -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')
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/ResponseTaggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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'])
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Test/PHPUnit/IsCacheHitConstraintTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Test/PHPUnit/IsCacheMissConstraintTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 57d78d5

Please sign in to comment.