GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EventsTrackerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 2
b 0
f 0
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpDependencies() 0 8 1
A releaseShouldReturnTheEventsAndResetTheInternalState() 0 6 1
A settingAggregateShouldCorrectlySetTheProperty() 0 5 1
A assertAttributeSame() 0 9 1
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
Documentation Bug introduced by
It seems like array($event1, $event2) of type array<integer,PHPUnit\Fr...\MockObject\MockObject> is incompatible with the declared type Dsantang\DomainEvents\DomainEvent[] of property $events.

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..

Loading history...
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