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

MapBasedTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 41
dl 0
loc 97
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvert() 0 15 1
A testDealWithInvalidValueConversionMap() 0 10 1
A testConvertANonOutboxRelatedDomainEvent() 0 13 1
A testConvertWithANonOutboxEntryDomainEvent() 0 15 1
A testDealWithInvalidKeyConversionMap() 0 10 1
A setUpDependencies() 0 12 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
    /** @var MapBased */
27
    private $mapBasedEventsHandler;
28
29
    /**
30
     * @before
31
     */
32
    public function setUpDependencies() : void
33
    {
34
        $this->conversionMap =
35
            [
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...
36
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\FirstDomainEvent'  =>
37
                new FirstOutboxConverter(),
38
39
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\SecondDomainEvent' =>
40
                new SecondOutboxConverter(),
41
42
                'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent'  =>
43
                new ThirdOutboxConverter(),
44
            ];
45
    }
46
47
    public function testDealWithInvalidKeyConversionMap() : void
48
    {
49
        $this->expectException(InvalidArgumentException::class);
50
51
        $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...
52
            'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\NonExistentDomainEvent'  =>
53
                new FirstOutboxConverter()
54
        ];
55
56
        $this->mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
57
    }
58
59
    public function testDealWithInvalidValueConversionMap() : void
60
    {
61
        $this->expectException(InvalidArgumentException::class);
62
63
        $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...
64
            'Dsantang\DomainEventsDoctrine\Tests\Unit\Outbox\Stub\DomainEvents\ThirdDomainEvent'  =>
65
                new stdClass()
66
        ];
67
68
        $this->mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
69
    }
70
71
    public function testConvert() : void
72
    {
73
        $this->mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
74
75
        $domainEvents = [new ThirdDomainEvent(), new FirstDomainEvent(), new SecondDomainEvent()];
76
77
        $returnedOutboxEvents = $this->mapBasedEventsHandler->convert(...$domainEvents);
78
79
        $expectedOutboxEvents = [
80
            (new ThirdOutboxConverter())->convert(new ThirdDomainEvent()),
81
            (new FirstOutboxConverter())->convert(new FirstDomainEvent()),
82
            (new SecondOutboxConverter())->convert(new SecondDomainEvent()),
83
        ];
84
85
        self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents);
86
    }
87
88
    public function testConvertWithANonOutboxEntryDomainEvent() : void
89
    {
90
        array_pop($this->conversionMap);
91
        $this->mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
92
93
        $domainEvents = [new FirstDomainEvent(), new SecondDomainEvent(), new ThirdDomainEvent()];
94
95
        $returnedOutboxEvents = $this->mapBasedEventsHandler->convert(...$domainEvents);
96
97
        $expectedOutboxEvents = [
98
            (new FirstOutboxConverter())->convert(new FirstDomainEvent()),
99
            (new SecondOutboxConverter())->convert(new SecondDomainEvent()),
100
        ];
101
102
        self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents);
103
    }
104
105
    public function testConvertANonOutboxRelatedDomainEvent() : void
106
    {
107
        $this->mapBasedEventsHandler = new MapBased(new OutboxSubClass(), $this->conversionMap);
108
109
        $domainEvents = [new RandomDomainEvent(), new SecondDomainEvent()];
110
111
        $returnedOutboxEvents = $this->mapBasedEventsHandler->convert(...$domainEvents);
112
113
        $expectedOutboxEvents = [
114
            (new SecondOutboxConverter())->convert(new SecondDomainEvent())
115
        ];
116
117
        self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents);
118
    }
119
}
120