From 2e8af172c3e7b66879cb089e7d763b6d49393b63 Mon Sep 17 00:00:00 2001 From: Christian Kolb Date: Sun, 9 Jun 2024 20:41:13 +0200 Subject: [PATCH] Add test for normalizer --- tests/Serializer/WeekdaysNormalizerTest.php | 121 ++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tests/Serializer/WeekdaysNormalizerTest.php diff --git a/tests/Serializer/WeekdaysNormalizerTest.php b/tests/Serializer/WeekdaysNormalizerTest.php new file mode 100644 index 0000000..dc7d643 --- /dev/null +++ b/tests/Serializer/WeekdaysNormalizerTest.php @@ -0,0 +1,121 @@ +normalize($weekdays); + $denormalizedData = $normalizer->denormalize($normalizedData, Weekdays::class); + + // -- Assert + self::assertEquals($weekdays, $denormalizedData); + } + + /** + * @test + * + * @covers ::normalize + */ + public function weekday_normalization_with_null_works(): void + { + // -- Arrange + $normalizer = new WeekdaysNormalizer(); + + // -- Act + $normalizedData = $normalizer->normalize(null); + + // -- Assert + self::assertNull($normalizedData); + } + + /** + * @test + * + * @covers ::denormalize + */ + public function weekdays_denormalization_with_null_works(): void + { + // -- Arrange + $normalizer = new WeekdaysNormalizer(); + + // -- Act + $denormalizedData = $normalizer->denormalize(null, Weekdays::class); + + // -- Assert + self::assertNull($denormalizedData); + } + + /** + * @test + * + * @covers ::supportsNormalization + */ + public function supports_normalization(): void + { + // -- Arrange + $weekdays = new Weekdays([ + Weekday::MONDAY, + Weekday::SATURDAY, + ]); + + $normalizer = new WeekdaysNormalizer(); + + // -- Act & Assert + self::assertTrue($normalizer->supportsNormalization($weekdays)); + } + + /** + * @test + * + * @covers ::supportsNormalization + */ + public function supports_normalization_fails(): void + { + // -- Arrange + $year = Year::fromString('2022'); + + $normalizer = new WeekdaysNormalizer(); + + // -- Act & Assert + self::assertFalse($normalizer->supportsNormalization($year)); + } + + /** + * @test + * + * @covers ::supportsDenormalization + */ + public function supports_denormalization(): void + { + // -- Arrange + $normalizer = new WeekdaysNormalizer(); + + // -- Act & Assert + self::assertTrue($normalizer->supportsDenormalization(null, Weekdays::class)); + } +}