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.
Passed
Pull Request — master (#7)
by Fábio Tadeu da
02:28
created

StubMapBasedTest::testPersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox;
6
7
use Doctrine\Common\EventArgs;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Doctrine\ORM\Event\OnFlushEventArgs;
10
use Doctrine\ORM\UnitOfWork;
11
use Dsantang\DomainEvents\Counter;
12
use Dsantang\DomainEvents\DomainEvent;
13
use Dsantang\DomainEvents\EventAware;
14
use Dsantang\DomainEvents\Registry\OrderedEventRegistry;
15
use Dsantang\DomainEventsDoctrine\Tests\OutboxSubClass;
16
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\Converters\FirstOutboxConverter;
17
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\Converters\SecondOutboxConverter;
18
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\Converters\ThirdOutboxConverter;
19
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\FirstDomainEvent;
20
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\SecondDomainEvent;
21
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent;
22
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\OutboxEntries\FirstOutboxEntry;
23
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\OutboxEntries\SecondOutboxEntry;
24
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\OutboxEntries\ThirdOutboxEntry;
25
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\StubMapBased;
26
use PHPUnit\Framework\TestCase;
27
use function array_values;
28
29
final class StubMapBasedTest extends TestCase
30
{
31
    /** @var converter[] */
32
    private $conversionMap;
33
34
    /** @var StubMapBased */
35
    private $mapBasedEventsHandler;
36
37
    /**
38
     * @before
39
     */
40
    public function setUpDependencies() : void
41
    {
42
        $this->conversionMap =
43
            [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Dsantang\DomainEv...ThirdOutboxConverter()) of type array<string,Dsantang\Do...s\ThirdOutboxConverter> is incompatible with the declared type Dsantang\DomainEventsDoc...Unit\Outbox\converter[] of property $conversionMap.

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...
44
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\FirstDomainEvent'  =>
45
                new FirstOutboxConverter(),
46
47
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\SecondDomainEvent' =>
48
                new SecondOutboxConverter(),
49
50
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent'  =>
51
                new ThirdOutboxConverter(),
52
            ];
53
    }
54
55
    public function testGetDomainsEvents() : void
56
    {
57
        Counter::reset();
58
59
        $eventArgs = $this->getEventArgs();
60
61
        self::assertEquals(3, Counter::getNext());
62
63
        $this->mapBasedEventsHandler = new StubMapBased(new OutboxSubClass(), $this->conversionMap);
64
65
        $eventsResult = $this->mapBasedEventsHandler->getDomainEvents($eventArgs);
66
67
        self::assertEquals(0, Counter::getNext());
68
69
        $eventsExpected = [new FirstDomainEvent(), new SecondDomainEvent(), new ThirdDomainEvent()];
70
71
        $this->assertEquals(array_values($eventsResult), array_values($eventsExpected));
72
    }
73
74
    public function testPersist() : void
75
    {
76
        $eventArgs      = $this->getEventArgs();
77
        $outboxSubClass = new OutboxSubClass();
78
79
        $this->mapBasedEventsHandler = new StubMapBased($outboxSubClass, $this->conversionMap);
80
        $this->mapBasedEventsHandler->getDomainEvents($eventArgs);
81
82
        $outboxEvents = [
83
            new ThirdOutboxEntry(new ThirdDomainEvent()),
84
            new FirstOutboxEntry(new FirstDomainEvent()),
85
            new SecondOutboxEntry(new SecondDomainEvent()),
86
        ];
87
88
        $eventArgs->getEntityManager()->getUnitOfWork()->expects(self::once())
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not exist on Doctrine\Common\EventArgs. It seems like you code against a sub-type of Doctrine\Common\EventArgs such as Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs or Doctrine\ORM\Event\OnFlushEventArgs or Doctrine\ORM\Event\OnClearEventArgs or Doctrine\ORM\Event\PostFlushEventArgs or Doctrine\ORM\Event\PreFlushEventArgs or Doctrine\ORM\Event\LoadClassMetadataEventArgs or Doctrine\ORM\Event\LifecycleEventArgs. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
        $eventArgs->/** @scrutinizer ignore-call */ 
89
                    getEntityManager()->getUnitOfWork()->expects(self::once())
Loading history...
89
            ->method('computeChangeSets');
90
91
        $eventArgs->getEntityManager()->expects(self::exactly(3))
92
            ->method('persist');
93
94
        $this->mapBasedEventsHandler->persist(
95
            $eventArgs->getEntityManager(),
96
            ...$outboxEvents
97
        );
98
    }
99
100
    private function getEventArgs() : EventArgs
101
    {
102
        $entity1 = $this->getEntityClass();
103
        $entity2 = $this->getEntityClass();
104
        $entity3 = $this->getEntityClass();
105
106
        $domainEvent1 = new FirstDomainEvent();
107
        $domainEvent2 = new SecondDomainEvent();
108
        $domainEvent3 = new ThirdDomainEvent();
109
110
        $entity1->trigger($domainEvent1);
111
        $entity2->trigger($domainEvent2);
112
        $entity3->trigger($domainEvent3);
113
114
        $unitOfWork = $this->createMock(UnitOfWork::class);
115
        $unitOfWork->expects(self::once())->method('getScheduledEntityInsertions')->willReturn([]);
116
        $unitOfWork->expects(self::once())->method('getScheduledEntityUpdates')->willReturn([$entity3]);
117
        $unitOfWork->expects(self::once())->method('getScheduledEntityDeletions')->willReturn([$entity2, $entity1]);
118
119
        $entityManager = $this->createMock(EntityManagerInterface::class);
120
        $entityManager->expects(self::any())->method('getUnitOfWork')->willReturn($unitOfWork);
121
122
        $eventArgs = $this->createMock(OnFlushEventArgs::class);
123
        $eventArgs->expects(self::any())->method('getEntityManager')->willReturn($entityManager);
124
125
        return $eventArgs;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $eventArgs returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Doctrine\Common\EventArgs.
Loading history...
126
    }
127
128
    private function getEntityClass() : EventAware
129
    {
130
        return new class() implements EventAware {
131
            use OrderedEventRegistry;
132
133
            public function trigger(DomainEvent $event) : void
134
            {
135
                $this->triggeredA($event);
136
            }
137
        };
138
    }
139
}
140