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
03:01 queued 55s
created

MapBasedTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 39
dl 0
loc 92
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvert() 0 15 1
A testConvertWithANonOutboxEntryDomainEvent() 0 15 1
A testDealWithInvalidValueConversionMap() 0 10 1
A testDealWithInvalidKeyConversionMap() 0 10 1
A setUpDependencies() 0 12 1
A testConvertANonOutboxRelatedDomainEvent() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox;
6
7
use Dsantang\DomainEventsDoctrine\Outbox\MapBased;
8
use Dsantang\DomainEventsDoctrine\Tests\OutboxSubClass;
9
use Dsantang\DomainEventsDoctrine\Tests\RandomDomainEvent;
10
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\Converters\FirstOutboxConverter;
11
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\Converters\SecondOutboxConverter;
12
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\Converters\ThirdOutboxConverter;
13
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\FirstDomainEvent;
14
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\SecondDomainEvent;
15
use Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent;
16
use InvalidArgumentException;
17
use PHPUnit\Framework\TestCase;
18
use stdClass;
19
use function array_pop;
20
21
final class MapBasedTest extends TestCase
22
{
23
    /** @var converter[] */
24
    private $conversionMap;
25
26
    /**
27
     * @before
28
     */
29
    public function setUpDependencies() : void
30
    {
31
        $this->conversionMap =
32
            [
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...
33
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\FirstDomainEvent'  =>
34
                new FirstOutboxConverter(),
35
36
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\SecondDomainEvent' =>
37
                new SecondOutboxConverter(),
38
39
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent'  =>
40
                new ThirdOutboxConverter(),
41
            ];
42
    }
43
44
    public function testDealWithInvalidKeyConversionMap() : void
45
    {
46
        $this->expectException(InvalidArgumentException::class);
47
48
        $this->conversionMap = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Dsantang\DomainEv...FirstOutboxConverter()) of type array<string,Dsantang\Do...s\FirstOutboxConverter> 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...
49
            'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\NonExistentDomainEvent'  =>
50
                new FirstOutboxConverter(),
51
        ];
52
53
        new MapBased(new OutboxSubClass(), $this->conversionMap);
54
    }
55
56
    public function testDealWithInvalidValueConversionMap() : void
57
    {
58
        $this->expectException(InvalidArgumentException::class);
59
60
        $this->conversionMap = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Dsantang\DomainEv...ent' => new stdClass()) of type array<string,stdClass> 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...
61
            'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent'  =>
62
                new stdClass(),
63
        ];
64
65
        new MapBased(new OutboxSubClass(), $this->conversionMap);
66
    }
67
68
    public function testConvert() : void
69
    {
70
        $mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
71
72
        $domainEvents = [new ThirdDomainEvent(), new FirstDomainEvent(), new SecondDomainEvent()];
73
74
        $returnedOutboxEvents = $mapBasedEventsHandler->convert(...$domainEvents);
75
76
        $expectedOutboxEvents = [
77
            (new ThirdOutboxConverter())->convert(new ThirdDomainEvent()),
78
            (new FirstOutboxConverter())->convert(new FirstDomainEvent()),
79
            (new SecondOutboxConverter())->convert(new SecondDomainEvent()),
80
        ];
81
82
        self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents);
83
    }
84
85
    public function testConvertWithANonOutboxEntryDomainEvent() : void
86
    {
87
        array_pop($this->conversionMap);
88
        $mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
89
90
        $domainEvents = [new FirstDomainEvent(), new SecondDomainEvent(), new ThirdDomainEvent()];
91
92
        $returnedOutboxEvents = $mapBasedEventsHandler->convert(...$domainEvents);
93
94
        $expectedOutboxEvents = [
95
            (new FirstOutboxConverter())->convert(new FirstDomainEvent()),
96
            (new SecondOutboxConverter())->convert(new SecondDomainEvent()),
97
        ];
98
99
        self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents);
100
    }
101
102
    public function testConvertANonOutboxRelatedDomainEvent() : void
103
    {
104
        $mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
105
106
        $domainEvents = [new RandomDomainEvent(), new SecondDomainEvent()];
107
108
        $returnedOutboxEvents = $mapBasedEventsHandler->convert(...$domainEvents);
109
110
        $expectedOutboxEvents = [(new SecondOutboxConverter())->convert(new SecondDomainEvent())];
111
112
        self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents);
113
    }
114
}
115