dsantang /
domain-events-doctrine
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Dsantang\DomainEventsDoctrine\Tests\Unit; |
||
| 6 | |||
| 7 | use Dsantang\DomainEvents\DomainEvent; |
||
| 8 | use Dsantang\DomainEventsDoctrine\EventsTracker; |
||
| 9 | use PHPUnit\Framework\TestCase; |
||
| 10 | use ReflectionClass; |
||
| 11 | |||
| 12 | final class EventsTrackerTest extends TestCase |
||
| 13 | { |
||
| 14 | private EventsTracker $tracker; |
||
| 15 | |||
| 16 | /** @var DomainEvent[] */ |
||
| 17 | private array $events; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @before |
||
| 21 | */ |
||
| 22 | public function setUpDependencies(): void |
||
| 23 | { |
||
| 24 | $event1 = $this->createMock(DomainEvent::class); |
||
| 25 | $event2 = $this->createMock(DomainEvent::class); |
||
| 26 | |||
| 27 | $this->events = [$event1, $event2]; |
||
|
0 ignored issues
–
show
|
|||
| 28 | |||
| 29 | $this->tracker = new EventsTracker(); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @test |
||
| 34 | */ |
||
| 35 | public function settingAggregateShouldCorrectlySetTheProperty(): void |
||
| 36 | { |
||
| 37 | $this->tracker->aggregate(...$this->events); |
||
| 38 | |||
| 39 | self::assertAttributeSame($this->events, 'events', $this->tracker); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @test |
||
| 44 | */ |
||
| 45 | public function releaseShouldReturnTheEventsAndResetTheInternalState(): void |
||
| 46 | { |
||
| 47 | $this->tracker->aggregate(...$this->events); |
||
| 48 | |||
| 49 | self::assertSame($this->events, $this->tracker->release()); |
||
| 50 | self::assertAttributeSame([], 'events', $this->tracker); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param array<DomainEvent> $expectedDomainEvents |
||
| 55 | */ |
||
| 56 | private static function assertAttributeSame( |
||
| 57 | array $expectedDomainEvents, |
||
| 58 | string $propertyName, |
||
| 59 | EventsTracker $eventsTracker |
||
| 60 | ): void { |
||
| 61 | $refl = (new ReflectionClass($eventsTracker))->getProperty($propertyName); |
||
| 62 | $refl->setAccessible(true); |
||
| 63 | |||
| 64 | self::assertSame($expectedDomainEvents, $refl->getValue($eventsTracker)); |
||
| 65 | } |
||
| 66 | } |
||
| 67 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..