From 4715d02ae0baf2dc8268ac84476020b7019099e8 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 11 Jun 2025 09:46:17 +0100 Subject: [PATCH] Refactor --- .../src/Functional/Entity/PresentationTest.php | 7 +++---- .../src/Traits/PresentationCreationTrait.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php b/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php index 478f06b69..a6f54ca00 100644 --- a/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php +++ b/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Drupal\opd_presentations\Functional\Entity; -use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait; use weitzman\DrupalTestTraits\ExistingSiteBase; @@ -15,9 +14,9 @@ final class PresentationTest extends ExistingSiteBase { public function test_only_past_events_are_returned(): void { $presentation = $this->createPresentation( events: [ - $this->createEvent(['field_date' => (new DrupalDateTime('now'))->getTimestamp()]), - $this->createEvent(['field_date' => (new DrupalDateTime('yesterday'))->getTimestamp()]), - $this->createEvent(['field_date' => (new DrupalDateTime('tomorrow'))->getTimestamp()]), + $this->createEvent(eventDate: 'now'), + $this->createEvent(eventDate: 'yesterday'), + $this->createEvent(eventDate: 'tomorrow'), ], ); diff --git a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php index 8db6d43d0..561c7681b 100644 --- a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php +++ b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Drupal\Tests\opd_presentations\Traits; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\opd_presentations\Entity\Presentation; use Drupal\paragraphs\Entity\Paragraph; @@ -27,14 +28,13 @@ trait PresentationCreationTrait { return $presentation; } - /** - * @param array $values - */ - private function createEvent(array $values = []): ParagraphInterface { - return Paragraph::create(array_merge( - ['type' => 'event'], - $values, - )); + private function createEvent(string $eventDate): ParagraphInterface { + return Paragraph::create( + [ + 'field_date' => (new DrupalDateTime($eventDate))->getTimestamp(), + 'type' => 'event', + ], + ); } }