Skip to content

Commit

Permalink
Use PHPUnit 11 attributes for testing helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Apr 26, 2024
1 parent ec15218 commit 372a987
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v0.31.1

### Added

- Use PHPUnit 11 attributes for testing helpers

## v0.31.0

### Fixed
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Expand Up @@ -25,7 +25,7 @@
"webonyx/graphql-php": "^14.11.3 || ^15"
},
"require-dev": {
"bensampo/laravel-enum": "^3 || ^4.1",
"bensampo/laravel-enum": "^3 || ^4.1 || ^5 || ^6",
"composer/composer": "^2",
"ergebnis/composer-normalize": "^2.13",
"guzzlehttp/guzzle": "^7",
Expand All @@ -37,11 +37,10 @@
"php-http/mock-client": "^1.4",
"phpstan/extension-installer": "^1",
"phpstan/phpstan": "^1",
"phpstan/phpstan-deprecation-rules": "^1",
"phpstan/phpstan-mockery": "^1",
"phpstan/phpstan-phpunit": "^1",
"phpstan/phpstan-strict-rules": "^1",
"phpunit/phpunit": "^9.5.2",
"phpunit/phpunit": "^9.5.2 || ^10 || ^11",
"spawnia/phpunit-assert-directory": "^2",
"symfony/var-dumper": "^5.2.3",
"thecodingmachine/phpstan-safe-rule": "^1.1"
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Expand Up @@ -10,9 +10,20 @@ parameters:
- src
- tests
tmpDir: .build/phpstan
reportUnmatchedIgnoredErrors: false # As long as we support multiple PHP versions at once, there will be some dead spots
ignoreErrors:
# Required in different versions
- '#Call to deprecated method getNamespace\(\) of class Nette\\PhpGenerator\\ClassType#'
# Necessary when calling into generated client code, we know how it looks like
- '#Unsafe usage of new static.*#'
# @property on interfaces or abstract classes
- '#Access to an undefined property GraphQL\\Type\\Definition\\NamedType&GraphQL\\Type\\Definition\\Type::\$name\.#'
- '#Access to an undefined property Spawnia\\Sailor\\Result::\$data\.#'
- '#Access to an undefined property Spawnia\\Sailor\\ErrorFreeResult::\$data\.#'
# Due to different versions of bensampo/laravel-enum
- '#extends generic class BenSampo\\Enum\\Enum but does not specify its types: TValue#'
# Due to different versions of PHPUnit, attributes are backwards-compatible though
- '#Attribute class PHPUnit\\Framework\\Attributes\\After does not exist\.#'
# Due to the workaround with ObjectLike::UNDEFINED
- '#Default value of the parameter .+ \(string\) of method .+::make\(\) is incompatible with type .+#'
- '#Default value of the parameter .+ \(string\) of method .+::execute\(\) is incompatible with type .+#'
Expand Down
4 changes: 2 additions & 2 deletions src/Operation.php
Expand Up @@ -68,7 +68,7 @@ protected static function executeOperation(...$args): Result
/**
* Send an operation through the client and return the response.
*
* @param array<int, mixed> $args
* @param array<mixed> $args
*/
protected static function fetchResponse(array $args): Response
{
Expand All @@ -87,7 +87,7 @@ protected static function fetchResponse(array $args): Response
return $response;
}

/** @param array<int, mixed> $args */
/** @param array<mixed> $args */
protected static function variables(array $args): \stdClass
{
$variables = new \stdClass();
Expand Down
2 changes: 2 additions & 0 deletions src/Testing/ClearsSailorClients.php
Expand Up @@ -2,11 +2,13 @@

namespace Spawnia\Sailor\Testing;

use PHPUnit\Framework\Attributes\After;
use Spawnia\Sailor\Operation;

trait ClearsSailorClients
{
/** @after */
#[After]
protected function tearDownSailorClients(): void
{
Operation::clearClients();
Expand Down
2 changes: 2 additions & 0 deletions src/Testing/UsesSailorMocks.php
Expand Up @@ -2,11 +2,13 @@

namespace Spawnia\Sailor\Testing;

use PHPUnit\Framework\Attributes\After;
use Spawnia\Sailor\Operation;

trait UsesSailorMocks
{
/** @after */
#[After]
protected function tearDownSailorMocks(): void
{
Operation::clearMocks();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/IntrospectorTest.php
Expand Up @@ -56,7 +56,7 @@ public function testFailsIntrospectionIfFallbackAlsoThrows(): void
}

/** @return iterable<array{Request}> */
public function validRequests(): iterable
public static function validRequests(): iterable
{
yield [
static fn (): Response => self::successfulIntrospectionMock(),
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ResultTest.php
Expand Up @@ -41,7 +41,7 @@ public function testThrowErrors(bool $isClientSafe): void
}

/** @return iterable<array{bool}> */
public function isClientSafe(): iterable
public static function isClientSafe(): iterable
{
yield [true];
yield [false];
Expand Down

0 comments on commit 372a987

Please sign in to comment.