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:54
created

StubMapBasedTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 67
rs 10
c 0
b 0
f 0
eloc 21

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpDependencies() 0 4 1
A testPersist() 0 11 1
A persistDataProvider() 0 12 1
A testGetDomainsEvents() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\UnitOfWork;
9
use Dsantang\DomainEvents\Counter;
10
use Dsantang\DomainEventsDoctrine\Tests\OutboxSubClass;
11
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\FirstDomainEvent;
12
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\SecondDomainEvent;
13
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent;
14
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\OutboxEntries\FirstOutboxEntry;
15
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\OutboxEntries\SecondOutboxEntry;
16
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\OutboxEntries\ThirdOutboxEntry;
17
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\StubMapBased;
18
use PHPUnit\Framework\TestCase;
19
use function array_values;
20
21
final class StubMapBasedTest extends TestCase
22
{
23
    use EventArgsProvider;
24
25
    /**
26
     * @before
27
     */
28
    public function setUpDependencies() : void
29
    {
30
        $this->entityManager = $this->createMock(EntityManagerInterface::class);
31
        $this->unitOfWork    = $this->createMock(UnitOfWork::class);
32
    }
33
34
    public function testGetDomainsEvents() : void
35
    {
36
        Counter::reset();
37
38
        $eventArgs = $this->getEventArgs();
39
40
        self::assertEquals(3, Counter::getNext());
41
42
        $mapBasedEventsHandler = new StubMapBased(new OutboxSubClass());
43
44
        $eventsResult = $mapBasedEventsHandler->getDomainEvents($eventArgs);
45
46
        self::assertEquals(0, Counter::getNext());
47
48
        $eventsExpected = [new FirstDomainEvent(), new SecondDomainEvent(), new ThirdDomainEvent()];
49
50
        self::assertEquals(array_values($eventsResult), array_values($eventsExpected));
51
    }
52
53
    /**
54
     * @return mixed[] array
55
     */
56
    public function persistDataProvider() : array
57
    {
58
        return [
59
            [[], 0, 0],
60
            [[new FirstOutboxEntry(new FirstDomainEvent())], 1, 1],
61
            [
62
                [
63
                    new ThirdOutboxEntry(new ThirdDomainEvent()),
64
                    new FirstOutboxEntry(new FirstDomainEvent()),
65
                    new SecondOutboxEntry(new SecondDomainEvent()),
66
                ], 3,
67
                1,
68
            ],
69
        ];
70
    }
71
72
    /**
73
     * @param mixed[] $outboxEvents
74
     *
75
     * @dataProvider persistDataProvider
76
     */
77
    public function testPersist(array $outboxEvents, int $persistCalls, int $computeChangeSetsCalls) : void
78
    {
79
        $eventArgs = $this->getEventArgs();
80
81
        $mapBasedEventsHandler = new StubMapBased(new OutboxSubClass());
82
83
        $this->entityManager->expects(self::exactly($persistCalls))->method('persist');
84
85
        $this->unitOfWork->expects(self::exactly($computeChangeSetsCalls))->method('computeChangeSets');
86
87
        $mapBasedEventsHandler->persist($eventArgs->getEntityManager(), ...$outboxEvents);
88
    }
89
}
90