Skip to content

Commit

Permalink
Tests abstract dto object
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 4, 2024
1 parent fbcd832 commit 3a89649
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/DataTransferObject/AbstractDataTransferObjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace Setono\PeakWMS\DataTransferObject;

use PHPUnit\Framework\TestCase;

final class AbstractDataTransferObjectTest extends TestCase
{
/**
* @test
*/
public function it_converts_date_time(): void
{
$dt = AbstractDataTransferObjectTestDummy::convertDateTime('2024-12-04T12:35:29+02:00');

self::assertSame('2024-12-04T12:35:29+02:00', $dt->format(\DATE_ATOM));
}

/**
* @test
*/
public function it_returns_null_if_input_is_null(): void
{
$dt = AbstractDataTransferObjectTestDummy::convertDateTime(null);

self::assertNull($dt);
}

/**
* @test
*/
public function it_returns_same_object_if_input_is_date_time(): void
{
$dt1 = new \DateTimeImmutable('2024-12-04T12:35:29+02:00');
$dt2 = AbstractDataTransferObjectTestDummy::convertDateTime($dt1);

self::assertSame($dt1, $dt2);
}

/**
* @test
*/
public function it_returns_date_time_immutable_if_input_is_not(): void
{
$dt1 = new \DateTime('2024-12-04T12:35:29+02:00');
$dt2 = AbstractDataTransferObjectTestDummy::convertDateTime($dt1);

self::assertSame('2024-12-04T12:35:29+02:00', $dt2->format(\DATE_ATOM));
}

/**
* @test
*/
public function it_throws_if_input_cannot_be_converted(): void
{
$this->expectException(\InvalidArgumentException::class);
AbstractDataTransferObjectTestDummy::convertDateTime('2024-12-04T12:35:29.123456+02:00');
}
}

final class AbstractDataTransferObjectTestDummy extends AbstractDataTransferObject
{
}

0 comments on commit 3a89649

Please sign in to comment.