From 9d2377cdb7f07d6a8d587fecc79fecf5eb9eac00 Mon Sep 17 00:00:00 2001 From: Wiktor Ramut Date: Fri, 27 Sep 2024 15:26:00 +0200 Subject: [PATCH] Update to symfony 7 --- .github/workflows/phpunit.yml | 1 - .github/workflows/static-analysis.yml | 1 - .gitignore | 1 + .php-cs-fixer.php | 2 +- composer.json | 22 ++++++------- phpunit.xml.dist | 16 ++-------- src/Client/RequestTransformer.php | 6 ++-- src/DTO/PickupPointDTO.php | 30 +++++++++--------- src/Service/AuthorizationService.php | 8 ++--- src/Service/PickupPointService.php | 6 ++-- .../DependencyInjection/ConfigurationTest.php | 31 +++++++------------ .../Service/AuthorizationServiceTest.php | 16 +++------- .../Service/PickupPointServiceTest.php | 17 +++------- 13 files changed, 62 insertions(+), 95 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 1179be060a..780727ebca 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -11,7 +11,6 @@ jobs: strategy: matrix: php-version: - - "8.1" - "8.2" deps: - "normal" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 931cc12d3d..1eced8a466 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,7 +11,6 @@ jobs: strategy: matrix: php-version: - - "8.1" - "8.2" steps: - name: "Checkout" diff --git a/.gitignore b/.gitignore index c4e8084187..adbc2ea9be 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.lock /.idea /.env* +/.phpunit.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index c51474ee60..2393b5a05d 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -20,7 +20,7 @@ 'strict_param' => false, 'array_syntax' => ['syntax' => 'short'], 'concat_space' => ['spacing' => 'one'], - 'phpdoc_align' => [], + 'phpdoc_align' => ['align' => 'left'], 'phpdoc_summary' => false, 'void_return' => false, 'phpdoc_var_without_name' => false, diff --git a/composer.json b/composer.json index 78bc5558b9..0708e4ed0d 100755 --- a/composer.json +++ b/composer.json @@ -4,25 +4,25 @@ "type": "symfony-bundle", "license": "MIT", "require": { - "php": ">=8.1", + "php": "^8.2", "ext-json": "*", "guzzlehttp/guzzle": "^6.0 || ^7.0", "psr/log": "^1.1", - "symfony/http-kernel": "^6.1", - "symfony/property-info": "^6.1", - "symfony/serializer": "^6.1", + "symfony/http-kernel": "^6.1|^7.0", + "symfony/property-info": "^6.1|^7.0", + "symfony/serializer": "^6.1|^7.0", "symfony/serializer-pack": "^1.3", - "webmozart/assert": "^1.3" + "webmozart/assert": "^1.11" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.4", - "matthiasnoback/symfony-config-test": "^4.3", - "phpro/grumphp": "^1.5.0", - "phpstan/phpstan": "^1.4", + "friendsofphp/php-cs-fixer": "^3.64", + "phpro/grumphp": "^2.8", + "phpstan/phpstan": "^1.12", + "matthiasnoback/symfony-config-test": "^5.2", "phpstan/phpstan-webmozart-assert": "^1.2", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^10.5", "roave/security-advisories": "dev-master", - "symfony/phpunit-bridge": "6.2.*" + "symfony/phpunit-bridge": "6.2.*|^7.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d5e3d2be34..a073152ad0 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,19 @@ + cacheDirectory=".phpunit.cache" + beStrictAboutCoverageMetadata="true"> - ./tests - - - - diff --git a/src/Client/RequestTransformer.php b/src/Client/RequestTransformer.php index eab724b76d..329356c24b 100644 --- a/src/Client/RequestTransformer.php +++ b/src/Client/RequestTransformer.php @@ -11,11 +11,11 @@ use GuzzleHttp\Psr7\Uri; use Psr\Http\Message\RequestInterface as PsrRequestInterface; -class RequestTransformer implements RequestTransformerInterface +readonly class RequestTransformer implements RequestTransformerInterface { public function __construct( - private readonly Serializer $serializer, - private readonly ConfigProvider $configProvider, + private Serializer $serializer, + private ConfigProvider $configProvider, ) { } diff --git a/src/DTO/PickupPointDTO.php b/src/DTO/PickupPointDTO.php index 401752ad3a..b0529d4298 100644 --- a/src/DTO/PickupPointDTO.php +++ b/src/DTO/PickupPointDTO.php @@ -2,23 +2,23 @@ namespace Answear\BoxNowBundle\DTO; -class PickupPointDTO +readonly class PickupPointDTO { public function __construct( - public readonly string $id, - public readonly string $type, - public readonly string $name, - public readonly string $address, - public readonly ?string $title = null, - public readonly ?string $image = null, - public readonly ?float $latitude = null, - public readonly ?float $longitude = null, - public readonly ?string $postalCode = null, - public readonly ?string $country = null, - public readonly ?string $note = null, - public readonly ?string $additionalAddress = null, - public readonly ?string $expectedDeliveryTime = null, - public readonly ?string $region = null, + public string $id, + public string $type, + public string $name, + public string $address, + public ?string $title = null, + public ?string $image = null, + public ?float $latitude = null, + public ?float $longitude = null, + public ?string $postalCode = null, + public ?string $country = null, + public ?string $note = null, + public ?string $additionalAddress = null, + public ?string $expectedDeliveryTime = null, + public ?string $region = null, ) { } diff --git a/src/Service/AuthorizationService.php b/src/Service/AuthorizationService.php index 8f4e04899a..58b54b1815 100644 --- a/src/Service/AuthorizationService.php +++ b/src/Service/AuthorizationService.php @@ -8,12 +8,12 @@ use Answear\BoxNowBundle\Response\AuthorizationResponse; use Answear\BoxNowBundle\Serializer\Serializer; -class AuthorizationService +readonly class AuthorizationService { public function __construct( - private readonly ConfigProvider $configProvider, - private readonly Serializer $serializer, - private readonly Client $client, + private ConfigProvider $configProvider, + private Serializer $serializer, + private Client $client, ) { } diff --git a/src/Service/PickupPointService.php b/src/Service/PickupPointService.php index 2a259525f5..f62b195976 100644 --- a/src/Service/PickupPointService.php +++ b/src/Service/PickupPointService.php @@ -8,11 +8,11 @@ use Answear\BoxNowBundle\Response\GetPickupPointsResponse; use Answear\BoxNowBundle\Serializer\Serializer; -class PickupPointService +readonly class PickupPointService { public function __construct( - private readonly Client $client, - private readonly Serializer $serializer, + private Client $client, + private Serializer $serializer, ) { } diff --git a/tests/Acceptance/DependencyInjection/ConfigurationTest.php b/tests/Acceptance/DependencyInjection/ConfigurationTest.php index 0a19c961a5..d13008446b 100644 --- a/tests/Acceptance/DependencyInjection/ConfigurationTest.php +++ b/tests/Acceptance/DependencyInjection/ConfigurationTest.php @@ -8,6 +8,8 @@ use Answear\BoxNowBundle\DependencyInjection\AnswearBoxNowExtension; use Answear\BoxNowBundle\DependencyInjection\Configuration; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; @@ -16,11 +18,8 @@ class ConfigurationTest extends TestCase { use ConfigurationTestCaseTrait; - /** - * @test - * - * @dataProvider provideValidConfig - */ + #[Test] + #[DataProvider('provideValidConfig')] public function validTest(array $configs): void { $this->assertConfigurationIsValid($configs); @@ -40,12 +39,9 @@ public function validTest(array $configs): void } } - /** - * @test - * - * @dataProvider provideInvalidConfig - */ - public function invalidConfig(array $config, string|null $expectedMessage = null): void + #[Test] + #[DataProvider('provideInvalidConfig')] + public function invalidConfig(array $config, ?string $expectedMessage = null): void { $this->assertConfigurationIsInvalid( $config, @@ -53,11 +49,8 @@ public function invalidConfig(array $config, string|null $expectedMessage = null ); } - /** - * @test - * - * @dataProvider provideInvalidLogger - */ + #[Test] + #[DataProvider('provideInvalidLogger')] public function invalidLogger(array $configs, \Throwable $expectedException): void { $this->expectException(get_class($expectedException)); @@ -71,7 +64,7 @@ public function invalidLogger(array $configs, \Throwable $expectedException): vo $extension->load($configs, $builder); } - public function provideInvalidConfig(): iterable + public static function provideInvalidConfig(): iterable { yield [ [ @@ -99,7 +92,7 @@ public function provideInvalidConfig(): iterable ]; } - public function provideInvalidLogger(): iterable + public static function provideInvalidLogger(): iterable { yield [ [ @@ -113,7 +106,7 @@ public function provideInvalidLogger(): iterable ]; } - public function provideValidConfig(): iterable + public static function provideValidConfig(): iterable { yield [ [ diff --git a/tests/Integration/Service/AuthorizationServiceTest.php b/tests/Integration/Service/AuthorizationServiceTest.php index 6073128011..944c52fd8f 100644 --- a/tests/Integration/Service/AuthorizationServiceTest.php +++ b/tests/Integration/Service/AuthorizationServiceTest.php @@ -5,17 +5,15 @@ namespace Answear\BoxNowBundle\Tests\Integration\Service; use Answear\BoxNowBundle\Exception\RequestException; -use Answear\BoxNowBundle\Response\AuthorizationResponse; use Answear\BoxNowBundle\Service\AuthorizationService; use Answear\BoxNowBundle\Tests\Util\FileTestUtil; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class AuthorizationServiceTest extends ServiceTestCase { - /** - * @test - */ + #[Test] public function successfulAuthorization(): void { $this->setClient(withLogger: true); @@ -30,16 +28,12 @@ public function successfulAuthorization(): void $response = $service->authorize(); - $this->assertInstanceOf(AuthorizationResponse::class, $response); - $this->assertSame('--access-token--', $response->getAccessToken()); $this->assertSame('Bearer', $response->getTokenType()); $this->assertSame(3600, $response->getExpiresIn()); } - /** - * @test - */ + #[Test] public function wrongCredentialsAuthorization(): void { $this->expectException(RequestException::class); @@ -57,9 +51,7 @@ public function wrongCredentialsAuthorization(): void $service->authorize(); } - /** - * @test - */ + #[Test] public function invalidBodyAuthorization(): void { $this->expectException(RequestException::class); diff --git a/tests/Integration/Service/PickupPointServiceTest.php b/tests/Integration/Service/PickupPointServiceTest.php index 845ed86544..5fd40e18df 100644 --- a/tests/Integration/Service/PickupPointServiceTest.php +++ b/tests/Integration/Service/PickupPointServiceTest.php @@ -7,14 +7,13 @@ use Answear\BoxNowBundle\Service\PickupPointService; use Answear\BoxNowBundle\Tests\Util\FileTestUtil; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Webmozart\Assert\InvalidArgumentException; class PickupPointServiceTest extends ServiceTestCase { - /** - * @test - */ + #[Test] public function successfulListAllPickupPoints(): void { $this->setClient(withLogger: true); @@ -60,9 +59,7 @@ public function successfulListAllPickupPoints(): void ); } - /** - * @test - */ + #[Test] public function invalidPickupPointIdFieldValue(): void { $this->expectException(InvalidArgumentException::class); @@ -81,9 +78,7 @@ public function invalidPickupPointIdFieldValue(): void $service->getAll('token'); } - /** - * @test - */ + #[Test] public function invalidPickupPointNameFieldValue(): void { $this->expectException(InvalidArgumentException::class); @@ -102,9 +97,7 @@ public function invalidPickupPointNameFieldValue(): void $service->getAll('token'); } - /** - * @test - */ + #[Test] public function invalidPickupPointAddressFieldValue(): void { $this->expectException(InvalidArgumentException::class);