|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline; |
| 6 | + |
| 7 | +use DateTimeImmutable; |
| 8 | +use Patchlevel\EventSourcing\Aggregate\AggregateChanged; |
| 9 | +use Patchlevel\EventSourcing\Pipeline\EventBucket; |
| 10 | +use Patchlevel\EventSourcing\Pipeline\Middleware\UntilEventMiddleware; |
| 11 | +use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; |
| 12 | +use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class UntilEventMiddlewareTest extends TestCase |
| 16 | +{ |
| 17 | + public function testPositive(): void |
| 18 | + { |
| 19 | + $until = new DateTimeImmutable('2020-02-02 00:00:00'); |
| 20 | + |
| 21 | + $middleware = new UntilEventMiddleware($until); |
| 22 | + |
| 23 | + $bucket = new EventBucket( |
| 24 | + Profile::class, |
| 25 | + AggregateChanged::deserialize([ |
| 26 | + 'aggregateId' => '1', |
| 27 | + 'playhead' => 0, |
| 28 | + 'event' => ProfileCreated::class, |
| 29 | + 'payload' => '{}', |
| 30 | + 'recordedOn' => new DateTimeImmutable('2020-02-01 00:00:00'), |
| 31 | + ]) |
| 32 | + ); |
| 33 | + |
| 34 | + $result = $middleware($bucket); |
| 35 | + |
| 36 | + self::assertEquals([$bucket], $result); |
| 37 | + } |
| 38 | + |
| 39 | + public function testNegative(): void |
| 40 | + { |
| 41 | + $until = new DateTimeImmutable('2020-01-01 00:00:00'); |
| 42 | + |
| 43 | + $middleware = new UntilEventMiddleware($until); |
| 44 | + |
| 45 | + $bucket = new EventBucket( |
| 46 | + Profile::class, |
| 47 | + AggregateChanged::deserialize([ |
| 48 | + 'aggregateId' => '1', |
| 49 | + 'playhead' => 0, |
| 50 | + 'event' => ProfileCreated::class, |
| 51 | + 'payload' => '{}', |
| 52 | + 'recordedOn' => new DateTimeImmutable('2020-02-01 00:00:00'), |
| 53 | + ]) |
| 54 | + ); |
| 55 | + |
| 56 | + $result = $middleware($bucket); |
| 57 | + |
| 58 | + self::assertEquals([], $result); |
| 59 | + } |
| 60 | + |
| 61 | + public function testNullEdgeCase(): void |
| 62 | + { |
| 63 | + $until = new DateTimeImmutable('2020-01-01 00:00:00'); |
| 64 | + |
| 65 | + $middleware = new UntilEventMiddleware($until); |
| 66 | + |
| 67 | + $bucket = new EventBucket( |
| 68 | + Profile::class, |
| 69 | + AggregateChanged::deserialize([ |
| 70 | + 'aggregateId' => '1', |
| 71 | + 'playhead' => 0, |
| 72 | + 'event' => ProfileCreated::class, |
| 73 | + 'payload' => '{}', |
| 74 | + 'recordedOn' => null, |
| 75 | + ]) |
| 76 | + ); |
| 77 | + |
| 78 | + $result = $middleware($bucket); |
| 79 | + |
| 80 | + self::assertEquals([], $result); |
| 81 | + } |
| 82 | +} |
0 commit comments