diff --git a/modules/opd_presentations/src/Date.php b/modules/opd_presentations/src/Date.php new file mode 100644 index 000000000..794a09158 --- /dev/null +++ b/modules/opd_presentations/src/Date.php @@ -0,0 +1,20 @@ +date->getTimestamp(); + } + + public static function fromString(string $date): self { + return new self(new \DateTimeImmutable($date)); + } + + private function __construct(private \DateTimeImmutable $date) { + } + +} diff --git a/modules/opd_presentations/tests/src/Functional/PresentationTest.php b/modules/opd_presentations/tests/src/Functional/PresentationTest.php index bd727fb56..06f10dcb6 100644 --- a/modules/opd_presentations/tests/src/Functional/PresentationTest.php +++ b/modules/opd_presentations/tests/src/Functional/PresentationTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Drupal\opd_presentations\Functional; use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait; +use Drupal\opd_presentations\Date; use weitzman\DrupalTestTraits\ExistingSiteBase; final class PresentationTest extends ExistingSiteBase { @@ -15,17 +16,17 @@ final class PresentationTest extends ExistingSiteBase { $presentation = $this->createPresentation( events: [ $this->createEvent( - eventDate: 'now', + eventDate: Date::fromString('now'), eventName: 'PHP South West', ), $this->createEvent( - eventDate: 'yesterday', + eventDate: Date::fromString('yesterday'), eventName: 'DrupalCon Lille', ), $this->createEvent( - eventDate: 'tomorrow', + eventDate: Date::fromString('tomorrow'), eventName: 'PHP Oxford', ), ], diff --git a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php index 67f554f79..16530e5ab 100644 --- a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php +++ b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\opd_presentations\Traits; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\ctools\Testing\EntityCreationTrait; +use Drupal\opd_presentations\Date; use Drupal\opd_presentations\Event; use Drupal\opd_presentations\Presentation; @@ -29,11 +30,11 @@ trait PresentationCreationTrait { return $presentation; } - private function createEvent(string $eventName, string $eventDate): Event { + private function createEvent(string $eventName, Date $eventDate): Event { $event = $this->createEntity( entity_type: 'paragraph', values: [ - 'field_date' => (new DrupalDateTime($eventDate))->getTimestamp(), + 'field_date' => $eventDate->toTimestamp(), 'field_event_name' => $eventName, 'type' => Event::PARAGRAPH_TYPE, ],