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.

DoctrineEventsRecorderTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 32
c 2
b 0
f 0
dl 0
loc 66
rs 10

4 Methods

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