From ea21156fadae5cd9f8ec222987f5d4db5a66e590 Mon Sep 17 00:00:00 2001 From: lotyp Date: Thu, 13 Jun 2024 22:05:17 +0300 Subject: [PATCH] ci: apply rector/rector upgrades --- psalm-baseline.xml | 42 ++++++++++++++++++- src/ResponseFactory.php | 2 +- tests/app/Item.php | 2 +- .../SerializerServiceProviderTest.php | 17 +++----- tests/src/Functional/EncodersRegistryTest.php | 20 +++------ .../Normalizers/RamseyUuidNormalizerTest.php | 9 ++-- .../Functional/NormalizersRegistryTest.php | 13 +++--- tests/src/Functional/ResponseFactoryTest.php | 21 +++------- .../src/Functional/SerializerManagerTest.php | 17 +++----- tests/src/Functional/SerializerTest.php | 25 ++++------- 10 files changed, 80 insertions(+), 88 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 347d240c..03e37337 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -103,7 +103,7 @@ - + @@ -149,6 +149,21 @@ + + + + + + + + + + + + + + + @@ -167,13 +182,21 @@ + + + + + + + + @@ -183,6 +206,13 @@ + + + + + + + @@ -192,7 +222,11 @@ + + + + @@ -227,7 +261,13 @@ + + + + + + diff --git a/src/ResponseFactory.php b/src/ResponseFactory.php index 6fd78eb2..568afed9 100644 --- a/src/ResponseFactory.php +++ b/src/ResponseFactory.php @@ -12,7 +12,7 @@ final class ResponseFactory /** * @property SerializerInterface $serializer */ - private SerializerInterface $serializer; + private readonly SerializerInterface $serializer; private array $context = []; diff --git a/tests/app/Item.php b/tests/app/Item.php index 2480fd8a..c41bbd6d 100644 --- a/tests/app/Item.php +++ b/tests/app/Item.php @@ -11,7 +11,7 @@ final class Item { #[Groups(['default', 'private'])] - private UuidInterface $id; + private readonly UuidInterface $id; #[Groups(['default'])] private string $key = 'magic_number'; diff --git a/tests/src/Functional/Bridge/Laravel/Providers/SerializerServiceProviderTest.php b/tests/src/Functional/Bridge/Laravel/Providers/SerializerServiceProviderTest.php index ca0958b8..cc3ac2f7 100644 --- a/tests/src/Functional/Bridge/Laravel/Providers/SerializerServiceProviderTest.php +++ b/tests/src/Functional/Bridge/Laravel/Providers/SerializerServiceProviderTest.php @@ -4,6 +4,7 @@ namespace WayOfDev\Tests\Functional\Bridge\Laravel\Providers; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; use WayOfDev\Serializer\Config; @@ -16,36 +17,28 @@ final class SerializerServiceProviderTest extends TestCase { - /** - * @test - */ + #[Test] public function it_registers_config(): void { self::assertTrue($this->app->bound(ConfigRepository::class)); self::assertInstanceOf(Config::class, $this->app->make(ConfigRepository::class)); } - /** - * @test - */ + #[Test] public function it_registers_normalizers_registry(): void { self::assertTrue($this->app->bound(NormalizersRegistryInterface::class)); self::assertInstanceOf(NormalizersRegistry::class, $this->app->make(NormalizersRegistryInterface::class)); } - /** - * @test - */ + #[Test] public function it_registers_encoders_registry(): void { self::assertTrue($this->app->bound(EncodersRegistryInterface::class)); self::assertInstanceOf(EncodersRegistry::class, $this->app->make(EncodersRegistryInterface::class)); } - /** - * @test - */ + #[Test] public function it_registers_serializer(): void { self::assertTrue($this->app->bound(SerializerInterface::class)); diff --git a/tests/src/Functional/EncodersRegistryTest.php b/tests/src/Functional/EncodersRegistryTest.php index 2cf23bce..43f2c3df 100644 --- a/tests/src/Functional/EncodersRegistryTest.php +++ b/tests/src/Functional/EncodersRegistryTest.php @@ -4,6 +4,7 @@ namespace WayOfDev\Tests\Functional; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\Exception; use Symfony\Component\Serializer\Encoder\CsvEncoder; use Symfony\Component\Serializer\Encoder\EncoderInterface; @@ -14,9 +15,7 @@ final class EncodersRegistryTest extends TestCase { - /** - * @test - */ + #[Test] public function construct_with_default_encoders(): void { $registry = new EncodersRegistry(); @@ -29,9 +28,7 @@ public function construct_with_default_encoders(): void self::assertTrue($registry->has(YamlEncoder::class)); } - /** - * @test - */ + #[Test] public function construct_with_encoders(): void { $registry = new EncodersRegistry([new JsonEncoder(), new CsvEncoder()]); @@ -44,9 +41,7 @@ public function construct_with_encoders(): void self::assertFalse($registry->has(YamlEncoder::class)); } - /** - * @test - */ + #[Test] public function register(): void { $registry = new EncodersRegistry(); @@ -63,9 +58,7 @@ public function register(): void self::assertTrue($registry->has($encoder::class)); } - /** - * @test - */ + #[Test] public function all(): void { $json = new JsonEncoder(); @@ -76,10 +69,9 @@ public function all(): void } /** - * @test - * * @throws Exception */ + #[Test] public function has(): void { $encoder = $this->createMock(EncoderInterface::class); diff --git a/tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php b/tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php index 6d83b640..de8787bb 100644 --- a/tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php +++ b/tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php @@ -5,6 +5,7 @@ namespace WayOfDev\Tests\Functional\Normalizers; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Ramsey\Uuid\Uuid; use Traversable; use WayOfDev\App\Object\Author; @@ -34,10 +35,8 @@ public static function serializeDataProvider(): Traversable ]; } - /** - * @test - */ #[DataProvider('serializeDataProvider')] + #[Test] public function serialize(string $expected, mixed $payload, string $format): void { $manager = $this->app->get(SerializerManager::class); @@ -45,9 +44,7 @@ public function serialize(string $expected, mixed $payload, string $format): voi self::assertSame($expected, preg_replace('/\s+/', '', $manager->serialize($payload, $format))); } - /** - * @test - */ + #[Test] public function unserialize(): void { $manager = $this->app->get(SerializerManager::class); diff --git a/tests/src/Functional/NormalizersRegistryTest.php b/tests/src/Functional/NormalizersRegistryTest.php index d0955a24..9192e444 100644 --- a/tests/src/Functional/NormalizersRegistryTest.php +++ b/tests/src/Functional/NormalizersRegistryTest.php @@ -4,6 +4,7 @@ namespace WayOfDev\Tests\Functional; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\Exception; use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface; use Symfony\Component\Serializer\Normalizer; @@ -34,10 +35,9 @@ public static function assertContainsInstanceOf(string $className, array $array) } /** - * @test - * * @throws Exception */ + #[Test] public function construct_with_default_normalizers(): void { $registry = new NormalizersRegistry( @@ -65,10 +65,9 @@ public function construct_with_default_normalizers(): void } /** - * @test - * * @throws Exception */ + #[Test] public function register(): void { $registry = new NormalizersRegistry( @@ -92,10 +91,9 @@ public function register(): void } /** - * @test - * * @throws Exception */ + #[Test] public function all(): void { $registry = new NormalizersRegistry( @@ -111,10 +109,9 @@ public function all(): void } /** - * @test - * * @throws Exception */ + #[Test] public function has(): void { $normalizer = $this->createMock(Normalizer\NormalizerInterface::class); diff --git a/tests/src/Functional/ResponseFactoryTest.php b/tests/src/Functional/ResponseFactoryTest.php index a468bbf1..a4405dd3 100644 --- a/tests/src/Functional/ResponseFactoryTest.php +++ b/tests/src/Functional/ResponseFactoryTest.php @@ -4,6 +4,7 @@ namespace WayOfDev\Tests\Functional; +use PHPUnit\Framework\Attributes\Test; use WayOfDev\App\Item; use WayOfDev\App\Object\Post; use WayOfDev\App\Response; @@ -12,9 +13,7 @@ final class ResponseFactoryTest extends TestCase { - /** - * @test - */ + #[Test] public function it_creates_response(): void { $responseFactory = new ResponseFactory(app(SerializerManager::class)); @@ -29,9 +28,7 @@ public function it_creates_response(): void self::assertEquals('{"id":1,"text":"Some text","active":true,"views":777}', $response->getContent()); } - /** - * @test - */ + #[Test] public function it_creates_from_array_iterator(): void { $responseFactory = new ResponseFactory(app(SerializerManager::class)); @@ -42,9 +39,7 @@ public function it_creates_from_array_iterator(): void self::assertEquals('[{"id":"0cd74c72-8920-4e4e-86c3-19fdd5103514","key":"magic_number","value":12}]', $response->getContent()); } - /** - * @test - */ + #[Test] public function it_creates_response_from_array(): void { $responseFactory = new ResponseFactory(app(SerializerManager::class)); @@ -57,9 +52,7 @@ public function it_creates_response_from_array(): void ); } - /** - * @test - */ + #[Test] public function it_sets_non_default_status_code(): void { $responseFactory = new ResponseFactory(app(SerializerManager::class)); @@ -71,9 +64,7 @@ public function it_sets_non_default_status_code(): void self::assertEquals('{"id":"0cd74c72-8920-4e4e-86c3-19fdd5103514","key":"magic_number","value":12}', $response->getContent()); } - /** - * @test - */ + #[Test] public function it_uses_given_context(): void { $responseFactory = new ResponseFactory(app(SerializerManager::class)); diff --git a/tests/src/Functional/SerializerManagerTest.php b/tests/src/Functional/SerializerManagerTest.php index 8af45a0f..c4c45fb1 100644 --- a/tests/src/Functional/SerializerManagerTest.php +++ b/tests/src/Functional/SerializerManagerTest.php @@ -5,6 +5,7 @@ namespace WayOfDev\Tests\Functional; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Stringable; use Traversable; use WayOfDev\Serializer\Exceptions\SerializerNotFoundException; @@ -48,9 +49,7 @@ protected function setUp(): void $this->serializer = $this->app->make(SerializerManager::class); } - /** - * @test - */ + #[Test] public function get_serializer(): void { self::assertInstanceOf( @@ -72,18 +71,14 @@ public function get_serializer(): void $this->serializer->getSerializer('bad'); } - /** - * @test - */ #[DataProvider('serializeDataProvider')] + #[Test] public function serialize(mixed $payload, string $expected, ?string $format = null): void { self::assertSame($expected, $this->serializer->serialize($payload, $format)); } - /** - * @test - */ + #[Test] public function bad_serializer(): void { $this->expectException(SerializerNotFoundException::class); @@ -93,10 +88,8 @@ public function bad_serializer(): void $this->serializer->unserialize('payload', 'bad'); } - /** - * @test - */ #[DataProvider('unserializeDataProvider')] + #[Test] public function unserialize(string|Stringable $payload, mixed $expected, ?string $format = null): void { self::assertSame($expected, $this->serializer->unserialize($payload, format: $format)); diff --git a/tests/src/Functional/SerializerTest.php b/tests/src/Functional/SerializerTest.php index 04bf14fd..dbd5d186 100644 --- a/tests/src/Functional/SerializerTest.php +++ b/tests/src/Functional/SerializerTest.php @@ -7,6 +7,7 @@ use DateTimeImmutable; use DateTimeZone; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Traversable; use WayOfDev\App\NestedObjects\City; use WayOfDev\App\NestedObjects\Country; @@ -76,10 +77,8 @@ public static function serializeDataProvider(): Traversable ]; } - /** - * @test - */ #[DataProvider('serializeDataProvider')] + #[Test] public function serialize(string $expected, mixed $payload, string $format): void { $manager = $this->app->get(SerializerManager::class); @@ -87,9 +86,7 @@ public function serialize(string $expected, mixed $payload, string $format): voi self::assertSame($expected, preg_replace('/\s+/', '', $manager->serialize($payload, $format))); } - /** - * @test - */ + #[Test] public function unserialize(): void { $manager = $this->app->get(SerializerManager::class); @@ -111,9 +108,7 @@ public function unserialize(): void self::assertFalse($result->active); } - /** - * @test - */ + #[Test] public function unserialize_with_attributes(): void { $manager = $this->app->get(SerializerManager::class); @@ -131,9 +126,7 @@ public function unserialize_with_attributes(): void self::assertSame(5, $result->views); } - /** - * @test - */ + #[Test] public function unserialize_nested_objects(): void { $manager = $this->app->get(SerializerManager::class); @@ -150,9 +143,7 @@ public function unserialize_nested_objects(): void self::assertSame('NewYork', $result->cities[1]->name); } - /** - * @test - */ + #[Test] public function unserialize_date_time_interface(): void { $manager = $this->app->get(SerializerManager::class); @@ -169,9 +160,7 @@ public function unserialize_date_time_interface(): void self::assertSame('2023-06-05T22:12:55+00:00', $result->registeredAt->format('c')); } - /** - * @test - */ + #[Test] public function group_normalize(): void { // dd($this->app->make(SerializerManager::class));