From 0cfdf82a5ce70f9ab1192d408b09ecd12dc8857e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 2 Sep 2022 09:02:56 +0200 Subject: [PATCH] Aligning `DateTimeImmutable` usages to `vimeo/psalm:^4.27.0` See https://github.com/vimeo/psalm/pull/8350 --- src/Payment/Domain/Aggregate/Payment.php | 8 ++++++-- src/TimeTracking/Domain/Date.php | 8 +------- test/Payment/Unit/Domain/Aggregate/PaymentTest.php | 9 +++++++-- .../HandleSendNotificationsForLatePaymentsTest.php | 5 +++++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Payment/Domain/Aggregate/Payment.php b/src/Payment/Domain/Aggregate/Payment.php index 5b9e122..0925869 100644 --- a/src/Payment/Domain/Aggregate/Payment.php +++ b/src/Payment/Domain/Aggregate/Payment.php @@ -49,12 +49,16 @@ public static function requestPayment( ): AggregateChanged { $id = PaymentId::generate(); + // We hardcode the deadline, for now: good enough for us + $deadline = $time->modify('+5 day'); + + assert($deadline !== false); + return AggregateChanged::created( PaymentId::generate(), [ new PaymentRequested($id, $debtor, $amount, $time), - // We hardcode the deadline, for now: good enough for us - new PaymentDeadlineSet($id, $time->modify('+5 day'), $time), + new PaymentDeadlineSet($id, $deadline, $time), ], ); } diff --git a/src/TimeTracking/Domain/Date.php b/src/TimeTracking/Domain/Date.php index bbed847..b785cf1 100644 --- a/src/TimeTracking/Domain/Date.php +++ b/src/TimeTracking/Domain/Date.php @@ -7,7 +7,6 @@ use DateTimeImmutable; use Psl\Exception\InvariantViolationException; -use function assert; use function Psl\invariant; /** @psalm-immutable */ @@ -36,11 +35,6 @@ public function __construct(string $date) /** @return non-empty-string */ public function toString(): string { - $date = $this->date->format('Y-m-d'); - - // Until https://github.com/vimeo/psalm/pull/8350 released, `DateTimeImmutable#format()` produces `string` - assert($date !== ''); - - return $date; + return $this->date->format('Y-m-d'); } } diff --git a/test/Payment/Unit/Domain/Aggregate/PaymentTest.php b/test/Payment/Unit/Domain/Aggregate/PaymentTest.php index c536983..b53329e 100644 --- a/test/Payment/Unit/Domain/Aggregate/PaymentTest.php +++ b/test/Payment/Unit/Domain/Aggregate/PaymentTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use function array_map; +use function assert; use function get_class; /** @covers \EventSourcingWorkshop\Payment\Domain\Aggregate\Payment */ @@ -41,7 +42,11 @@ public function testWillAllowRequestingAPayment(): void public function testWillAllowMarkingAPaymentAsPaid(): void { - $id = PaymentId::generate(); + $deadline = (new DateTimeImmutable())->modify('+50 day'); + $id = PaymentId::generate(); + + assert($deadline !== false); + $payment = Payment::fromHistory( $id, [ @@ -53,7 +58,7 @@ public function testWillAllowMarkingAPaymentAsPaid(): void ), new PaymentDeadlineSet( $id, - (new DateTimeImmutable())->modify('+50 day'), + $deadline, new DateTimeImmutable(), ), ], diff --git a/test/Payment/Unit/Infrastructure/CommandHandler/HandleSendNotificationsForLatePaymentsTest.php b/test/Payment/Unit/Infrastructure/CommandHandler/HandleSendNotificationsForLatePaymentsTest.php index b859b44..45be526 100644 --- a/test/Payment/Unit/Infrastructure/CommandHandler/HandleSendNotificationsForLatePaymentsTest.php +++ b/test/Payment/Unit/Infrastructure/CommandHandler/HandleSendNotificationsForLatePaymentsTest.php @@ -11,6 +11,8 @@ use EventSourcingWorkshopTest\EventSourcing\Integration\Support\EventSourcingTestHelper; use PHPUnit\Framework\TestCase; +use function assert; + /** @covers \EventSourcingWorkshop\Payment\Infrastructure\CommandHandler\HandleSendNotificationsForLatePayments */ final class HandleSendNotificationsForLatePaymentsTest extends TestCase { @@ -25,6 +27,9 @@ public function testWillFindLatePaymentsToProcess(): void $lateButNoDebtor = PaymentId::generate(); $db = EventSourcingTestHelper::freshDatabase(); + assert($notLateDate !== false); + assert($lateDate !== false); + $db->executeStatement(<<<'SQL' CREATE TABLE projection_pending_payments ( payment VARCHAR(1024) PRIMARY KEY NOT NULL,