From 8fae90373ce300df0adea989978e1ee1463caeab Mon Sep 17 00:00:00 2001 From: Koldo Picaza <1093654+kpicaza@users.noreply.github.com> Date: Sun, 3 Dec 2023 13:16:26 +0100 Subject: [PATCH] update psalm to 5.16 --- composer.json | 2 +- src/Read/ChainSegmentFactory.php | 10 ++++++++-- src/Read/ChainToggleStrategyFactory.php | 1 + test/Read/ChainSegmentFactoryTest.php | 20 +++++++++++++++++++ test/Read/ChainToggleStrategyFactoryTest.php | 21 ++++++++++++++++++++ test/Write/FeatureTest.php | 6 +++--- 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index fe76c1d..8ab7b4a 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "roave/infection-static-analysis-plugin": "^1.18", "squizlabs/php_codesniffer": "^3.4", "symfony/var-dumper": "^4.2 || ^5.0 || ^6.0", - "vimeo/psalm": "^4.4" + "vimeo/psalm": "^4.4|^5.16" }, "autoload": { "psr-4": { diff --git a/src/Read/ChainSegmentFactory.php b/src/Read/ChainSegmentFactory.php index 071c9bf..a9eea38 100644 --- a/src/Read/ChainSegmentFactory.php +++ b/src/Read/ChainSegmentFactory.php @@ -29,8 +29,14 @@ public function create(string $segmentId, string $segmentType, array $criteria): public function types(): array { - return array_merge( - ...array_map(static fn(SegmentFactory $segmentFactory) => $segmentFactory->types(), $this->segmentFactories) + /** @psalm-suppress NamedArgumentNotAllowed */ + return array_unique( + array_merge( + ...array_map( + static fn(SegmentFactory $segmentFactory) => $segmentFactory->types(), + $this->segmentFactories + ) + ) ); } } diff --git a/src/Read/ChainToggleStrategyFactory.php b/src/Read/ChainToggleStrategyFactory.php index 1006e19..92c5ac2 100644 --- a/src/Read/ChainToggleStrategyFactory.php +++ b/src/Read/ChainToggleStrategyFactory.php @@ -57,6 +57,7 @@ public function create(string $strategyId, string $strategyType, ?Segments $segm public function types(): array { + /** @psalm-suppress NamedArgumentNotAllowed */ return array_unique( array_merge( ...array_map( diff --git a/test/Read/ChainSegmentFactoryTest.php b/test/Read/ChainSegmentFactoryTest.php index f0531f0..81e7984 100644 --- a/test/Read/ChainSegmentFactoryTest.php +++ b/test/Read/ChainSegmentFactoryTest.php @@ -45,4 +45,24 @@ public function testItShouldBeCreatedWithAtLeastOneSegmentFactoryInstance(): voi $this->assertSame($expectedSegment, $current); $this->assertSame([self::SEGMENT_TYPE], $chainSegmentFactory->types()); } + + public function testItShouldCorrectlyMergeTheStrategyTypes(): void + { + $segmentFactory = $this->createMock(SegmentFactory::class); + $segmentFactory->expects(self::once()) + ->method('types') + ->willReturn(['a', 'b']); + $otherSegmentFactory = $this->createMock(SegmentFactory::class); + $otherSegmentFactory->expects(self::once()) + ->method('types') + ->willReturn(['c', 'b']); + + $chainSegmentFactory = new ChainSegmentFactory( + $segmentFactory, + $otherSegmentFactory + ); + + $this->assertSame(['a', 'b', 'c'], $chainSegmentFactory->types()); + } + } diff --git a/test/Read/ChainToggleStrategyFactoryTest.php b/test/Read/ChainToggleStrategyFactoryTest.php index 839c902..4a0ae76 100644 --- a/test/Read/ChainToggleStrategyFactoryTest.php +++ b/test/Read/ChainToggleStrategyFactoryTest.php @@ -94,4 +94,25 @@ public function testItShouldBeCreatedWithAtLeastOneToggleStrategyFactoryInstance $this->assertSame($expectedStrategy, $current); $this->assertSame([self::STRATEGY_TYPE, 'other_type'], $chainToggleStrategyFactory->types()); } + + public function testItShouldCorrectlyMergeTheStrategyTypes(): void + { + $segmentFactory = $this->createMock(SegmentFactory::class); + $toggleStrategyFactory = $this->createMock(ToggleStrategyFactory::class); + $toggleStrategyFactory->expects(self::once()) + ->method('types') + ->willReturn(['a', 'b']); + $otherToggleStrategyFactory = $this->createMock(ToggleStrategyFactory::class); + $otherToggleStrategyFactory->expects(self::once()) + ->method('types') + ->willReturn(['c', 'b']); + + $chainToggleStrategyFactory = new ChainToggleStrategyFactory( + $segmentFactory, + $toggleStrategyFactory, + $otherToggleStrategyFactory + ); + + $this->assertSame(['a', 'b', 'c'], $chainToggleStrategyFactory->types()); + } } diff --git a/test/Write/FeatureTest.php b/test/Write/FeatureTest.php index 4ca5356..769c6b8 100644 --- a/test/Write/FeatureTest.php +++ b/test/Write/FeatureTest.php @@ -155,14 +155,14 @@ public function testItShouldStoreAFeatureWasCreatedEventWhenNewFeatureIsCreated( public function testItShouldStoreAFeatureWasRemovedWhenItIsRemoved(): void { - $feature = $this->createFeature(); + $feature = Feature::withId(FeatureId::fromString(self::FEATURE_ID)); $feature->remove(); $events = $feature->release(); - $this->assertCount(1, $events); + $this->assertCount(2, $events); $this->assertEventIsRecorded(FeatureWasRemoved::class, $events); - $featureWasRemovedEvent = $events[0]; + $featureWasRemovedEvent = $events[1]; $this->assertSame(self::FEATURE_ID, $featureWasRemovedEvent->featureId()->value()); $this->assertInstanceOf(DatetimeImmutable::class, $featureWasRemovedEvent->occurredAt()); }