Skip to content

Commit

Permalink
Add test for normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kolb committed Jun 9, 2024
1 parent 30f19b1 commit 2e8af17
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions tests/Serializer/WeekdaysNormalizerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

declare(strict_types=1);

namespace DigitalCraftsman\DateTimePrecision\Serializer;

use DigitalCraftsman\DateTimePrecision\Weekday;
use DigitalCraftsman\DateTimePrecision\Weekdays;
use DigitalCraftsman\DateTimePrecision\Year;
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimePrecision\Serializer\WeekdaysNormalizer */
final class WeekdaysNormalizerTest extends TestCase
{
/**
* @test
*
* @covers ::normalize
* @covers ::denormalize
*/
public function weekdays_normalization_and_denormalization_works(): void
{
// -- Arrange
$weekdays = new Weekdays([
Weekday::MONDAY,
Weekday::SATURDAY,
]);

$normalizer = new WeekdaysNormalizer();

// -- Act
$normalizedData = $normalizer->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));
}
}

0 comments on commit 2e8af17

Please sign in to comment.