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.

OrderedDoctrineEventsRecorderTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 34
c 1
b 0
f 0
dl 0
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
provideEventAwareChangedEntities() 0 17 ?
A hp$0 ➔ __construct() 0 3 1
A onFlushWillAggregateAllTheEventAwareEntities() 0 39 1
A hp$1 ➔ provideEventAwareChangedEntities() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dsantang\DomainEventsDoctrine\Tests\Unit\EventsRecorder;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Event\OnFlushEventArgs;
9
use Doctrine\ORM\UnitOfWork;
10
use Dsantang\DomainEvents\Counter;
11
use Dsantang\DomainEvents\DomainEvent;
12
use Dsantang\DomainEvents\EventAware;
13
use Dsantang\DomainEvents\Registry\EventsRegistry;
14
use Dsantang\DomainEventsDoctrine\Aggregator;
15
use Dsantang\DomainEventsDoctrine\EventsRecorder\OrderedDoctrineEventsRecorder;
16
use Dsantang\DomainEventsDoctrine\Tests\RandomDomainEvent;
17
use PHPUnit\Framework\TestCase;
18
19
final class OrderedDoctrineEventsRecorderTest extends TestCase
20
{
21
    /**
22
     * @param DomainEvent[] $domainEvents
23
     *
24
     * @dataProvider provideEventAwareChangedEntities
25
     *
26
     * @test
27
     */
28
    public function onFlushWillAggregateAllTheEventAwareEntities(object $eventAwareEntity, array $domainEvents): void
29
    {
30
        $unitOfWork = $this->createMock(UnitOfWork::class);
31
32
        $unitOfWork->expects(self::once())
33
                   ->method('getScheduledEntityDeletions')
34
                   ->willReturn([]);
35
36
        $unitOfWork->expects(self::once())
37
                   ->method('getScheduledEntityInsertions')
38
                   ->willReturn([$eventAwareEntity]);
39
40
        $unitOfWork->expects(self::once())
41
                   ->method('getScheduledEntityUpdates')
42
                   ->willReturn([$eventAwareEntity]);
43
44
        $entityManager = $this->createMock(EntityManagerInterface::class);
45
        $entityManager->expects(self::once())
46
                      ->method('getUnitOfWork')
47
                      ->willReturn($unitOfWork);
48
49
        $aggregator = $this->createMock(Aggregator::class);
50
51
        $aggregator->expects(self::once())
52
                   ->method('aggregate')
53
                   ->with(...$domainEvents);
54
55
        $eventRecorder = new OrderedDoctrineEventsRecorder($aggregator);
56
57
        $eventArgs = $this->createMock(OnFlushEventArgs::class);
58
        $eventArgs->expects(self::once())
59
                  ->method('getEntityManager')
60
                  ->willReturn($entityManager);
61
62
        Counter::getNext();
63
64
        $eventRecorder->onFlush($eventArgs);
65
66
        self::assertEquals(0, Counter::getNext());
67
    }
68
69
    /**
70
     * @return mixed[] array
71
     */
72
    public function provideEventAwareChangedEntities(): array
73
    {
74
        $awareEntity = new class (new RandomDomainEvent()) implements EventAware {
75
            use EventsRegistry;
76
77
            public function __construct(DomainEvent $domainEvent)
78
            {
79
                $this->recordedEvents = [1 => $domainEvent, 0 => $domainEvent];
80
            }
81
        };
82
83
        $object = new class (){
84
        };
85
86
        return [
87
            'with no changed entities' => [$object, []],
88
            'with a changed entity' => [$awareEntity, [new RandomDomainEvent(), new RandomDomainEvent()]],
89
        ];
90
    }
91
}
92