Skip to content

Commit

Permalink
Aligning DateTimeImmutable usages to vimeo/psalm:^4.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Sep 2, 2022
1 parent 8ac3c9b commit 0cfdf82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/Payment/Domain/Aggregate/Payment.php
Expand Up @@ -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),
],
);
}
Expand Down
8 changes: 1 addition & 7 deletions src/TimeTracking/Domain/Date.php
Expand Up @@ -7,7 +7,6 @@
use DateTimeImmutable;
use Psl\Exception\InvariantViolationException;

use function assert;
use function Psl\invariant;

/** @psalm-immutable */
Expand Down Expand Up @@ -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');
}
}
9 changes: 7 additions & 2 deletions test/Payment/Unit/Domain/Aggregate/PaymentTest.php
Expand Up @@ -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 */
Expand All @@ -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,
[
Expand All @@ -53,7 +58,7 @@ public function testWillAllowMarkingAPaymentAsPaid(): void
),
new PaymentDeadlineSet(
$id,
(new DateTimeImmutable())->modify('+50 day'),
$deadline,
new DateTimeImmutable(),
),
],
Expand Down
Expand Up @@ -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
{
Expand All @@ -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,
Expand Down

0 comments on commit 0cfdf82

Please sign in to comment.