| 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 |  |  |             [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 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 = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             (new SecondOutboxConverter())->convert(new SecondDomainEvent()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         self::assertEquals($expectedOutboxEvents, $returnedOutboxEvents); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |  | 
            
                        
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..