Skip to content

Commit

Permalink
Rename date time tests and move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kolb committed Sep 20, 2023
1 parent 4989c60 commit a2ba0a9
Show file tree
Hide file tree
Showing 34 changed files with 146 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeCompareToTest extends TestCase
final class CompareToTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
namespace DigitalCraftsman\DateTimeParts\DateTime;

use DigitalCraftsman\DateTimeParts\DateTime;
use DigitalCraftsman\DateTimeParts\Time;
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeTest extends TestCase
final class ConstructionTest extends TestCase
{
// -- Construction

/**
* @test
*
Expand Down Expand Up @@ -58,47 +55,4 @@ public function from_string_in_time_zone_works(): void
// -- Assert
self::assertEquals(new \DateTimeImmutable('2022-10-08 13:00:00'), $dateTime->dateTime);
}

/**
* @test
*
* @covers ::__toString
*/
public function to_string_works(): void
{
// -- Arrange & Act
$dateTime = DateTime::fromStringInTimeZone('2022-10-08 15:00:00', new \DateTimeZone('Europe/Berlin'));

// -- Assert
self::assertEquals('2022-10-08T13:00:00+00:00', (string) $dateTime);
}

// -- Mutations

/**
* @test
*
* @covers ::toUTC
* @covers ::timezone
*/
public function to_utc_works(): void
{
// -- Arrange
$dateTime = new DateTime(new \DateTimeImmutable(
'2022-10-07 14:39:24',
new \DateTimeZone('Europe/Berlin'),
));

// -- Act
$dateTimeInUTC = $dateTime->toUTC();

// -- Assert
self::assertEquals(
$dateTimeInUTC->timezone(),
new \DateTimeZone('UTC'),
);
self::assertTrue(
$dateTimeInUTC->time()->isEqualTo(Time::fromString('12:39:24')),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,8 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeDateTest extends TestCase
final class DateInTimeZoneTest extends TestCase
{
/**
* @test
*
* @dataProvider dataProviderForDate
*
* @covers ::date
*/
public function date_works(
Date $expectedResult,
DateTime $dateTime,
): void {
// -- Act & Assert
self::assertEquals($expectedResult, $dateTime->date());
}

/**
* @return array<string, array{
* 0: Date,
* 1: DateTime,
* }>
*/
public function dataProviderForDate(): array
{
return [
'same date in UTC' => [
Date::fromString('2022-10-08'),
DateTime::fromString('2022-10-08 00:00:00'),
],
'date the same with same time zone' => [
Date::fromString('2022-10-08'),
DateTime::fromStringInTimeZone('2022-10-08 01:00:00', new \DateTimeZone('Europe/Berlin'))
->toTimeZone(new \DateTimeZone('Europe/Berlin')),
],
];
}

/**
* @test
*
Expand Down
49 changes: 49 additions & 0 deletions tests/DateTime/DateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace DigitalCraftsman\DateTimeParts\DateTime;

use DigitalCraftsman\DateTimeParts\Date;
use DigitalCraftsman\DateTimeParts\DateTime;
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTest extends TestCase
{
/**
* @test
*
* @dataProvider dataProviderForDate
*
* @covers ::date
*/
public function date_works(
Date $expectedResult,
DateTime $dateTime,
): void {
// -- Act & Assert
self::assertEquals($expectedResult, $dateTime->date());
}

/**
* @return array<string, array{
* 0: Date,
* 1: DateTime,
* }>
*/
public function dataProviderForDate(): array
{
return [
'same date in UTC' => [
Date::fromString('2022-10-08'),
DateTime::fromString('2022-10-08 00:00:00'),
],
'date the same with same time zone' => [
Date::fromString('2022-10-08'),
DateTime::fromStringInTimeZone('2022-10-08 01:00:00', new \DateTimeZone('Europe/Berlin'))
->toTimeZone(new \DateTimeZone('Europe/Berlin')),
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeFormatInTimeZoneTest extends TestCase
final class FormatInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeFormatTest extends TestCase
final class FormatTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsAfterOrEqualToTest extends TestCase
final class IsAfterOrEqualToTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsAfterTest extends TestCase
final class IsAfterTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsAtMidnightInTimeZoneTest extends TestCase
final class IsAtMidnightInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsAtMidnightTest extends TestCase
final class IsAtMidnightTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsBeforeOrEqualToTest extends TestCase
final class IsBeforeOrEqualToTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsBeforeTest extends TestCase
final class IsBeforeTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsDateAfterInTimeZoneTest extends TestCase
final class IsDateAfterInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsDateAfterOrEqualToInTimeZoneTest extends TestCase
final class IsDateAfterOrEqualToInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsDateBeforeInTimeZoneTest extends TestCase
final class IsDateBeforeInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsDateBeforeOrEqualToInTimeZoneTest extends TestCase
final class IsDateBeforeOrEqualToInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsDateEqualToInTimeZoneTest extends TestCase
final class IsDateEqualToInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsDateNotEqualToInTimeZoneTest extends TestCase
final class IsDateNotEqualToInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsEqualToTest extends TestCase
final class IsEqualToTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsNotAtMidnightInTimeZoneTest extends TestCase
final class IsNotAtMidnightInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsNotAtMidnightTest extends TestCase
final class IsNotAtMidnightTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeIsNotEqualToTest extends TestCase
final class IsNotEqualToTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeMidnightInTimeZoneTest extends TestCase
final class MidnightInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeMidnightTest extends TestCase
final class MidnightTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeModifyInTimeZoneTest extends TestCase
final class ModifyInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeModifyTest extends TestCase
final class ModifyTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeMonthTest extends TestCase
final class MonthTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeSetTimeInTimeZoneTest extends TestCase
final class SetTimeInTimeZoneTest extends TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PHPUnit\Framework\TestCase;

/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */
final class DateTimeSetTimeTest extends TestCase
final class SetTimeTest extends TestCase
{
/**
* @test
Expand Down
Loading

0 comments on commit a2ba0a9

Please sign in to comment.