From 1d78bbd1eeae1dbd565dd0748e0939a33d659cf2 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 4 Oct 2022 10:54:37 +0200 Subject: [PATCH 1/9] Update phpstan and plugins --- .../Model/ContentRichEntityInterface.php | 2 +- .../Model/DimensionContentCollection.php | 17 +- .../DimensionContentCollectionInterface.php | 8 +- Content/Domain/Model/ExcerptInterface.php | 8 +- Content/Domain/Model/ExcerptTrait.php | 8 +- .../Sulu/Structure/ContentStructureBridge.php | 13 +- .../ContentStructureBridgeFactory.php | 2 +- .../Sulu/Teaser/ContentTeaserProvider.php | 19 ++- .../ExampleTestExtension.php | 1 + .../ExampleTestBundle/Entity/Example.php | 4 +- .../Entity/ExampleDimensionContent.php | 2 +- .../Teaser/ExampleTeaserProvider.php | 6 + .../DimensionContentRepositoryTest.php | 5 +- .../Search/ContentReindexProviderTest.php | 25 +-- .../ContentSearchMetadataProviderTest.php | 8 +- .../SmartContent/ContentDataProviderTest.php | 161 ++++++++++-------- .../Sulu/Teaser/ContentTeaserProviderTest.php | 21 +-- .../Integration/ExampleControllerTest.php | 8 +- Tests/Traits/CreateCategoryTrait.php | 4 +- Tests/Traits/CreateExampleTrait.php | 11 +- .../DataMapper/RoutableDataMapperTest.php | 21 ++- .../DataMapper/TemplateDataMapperTest.php | 17 +- .../Model/DimensionContentCollectionTest.php | 4 +- .../Preview/ContentObjectProviderTest.php | 72 ++++---- .../ContentStructureBridgeFactoryTest.php | 2 + .../DimensionContentMockWrapperTrait.php | 5 +- Tests/Unit/Mocks/MockWrapper.php | 10 +- Tests/Unit/Mocks/RoutableMockWrapperTrait.php | 4 + Tests/Unit/Mocks/TemplateMockWrapperTrait.php | 4 + Tests/Unit/Mocks/WorkflowMockWrapperTrait.php | 4 + composer.json | 14 +- phpstan.neon | 3 +- 32 files changed, 284 insertions(+), 209 deletions(-) diff --git a/Content/Domain/Model/ContentRichEntityInterface.php b/Content/Domain/Model/ContentRichEntityInterface.php index ba95aabb..3a431f81 100644 --- a/Content/Domain/Model/ContentRichEntityInterface.php +++ b/Content/Domain/Model/ContentRichEntityInterface.php @@ -18,7 +18,7 @@ interface ContentRichEntityInterface { /** - * @return mixed + * @return int|string */ public function getId(); diff --git a/Content/Domain/Model/DimensionContentCollection.php b/Content/Domain/Model/DimensionContentCollection.php index c38c4f8d..3e6aaa30 100644 --- a/Content/Domain/Model/DimensionContentCollection.php +++ b/Content/Domain/Model/DimensionContentCollection.php @@ -17,22 +17,25 @@ use Doctrine\Common\Collections\Criteria; /** - * @implements \IteratorAggregate + * @template T of DimensionContentInterface + * + * @implements \IteratorAggregate + * @implements DimensionContentCollectionInterface */ class DimensionContentCollection implements \IteratorAggregate, DimensionContentCollectionInterface { /** - * @var ArrayCollection + * @var ArrayCollection */ private $dimensionContents; /** - * @var DimensionContentInterface|null + * @var T|null */ private $unlocalizedDimensionContent; /** - * @var DimensionContentInterface|null + * @var T|null */ private $localizedDimensionContent; @@ -42,7 +45,7 @@ class DimensionContentCollection implements \IteratorAggregate, DimensionContent private $dimensionAttributes; /** - * @var class-string + * @var class-string */ private $dimensionContentClass; @@ -54,9 +57,9 @@ class DimensionContentCollection implements \IteratorAggregate, DimensionContent /** * DimensionContentCollection constructor. * - * @param DimensionContentInterface[] $dimensionContents + * @param T[] $dimensionContents * @param mixed[] $dimensionAttributes - * @param class-string $dimensionContentClass + * @param class-string $dimensionContentClass */ public function __construct( array $dimensionContents, diff --git a/Content/Domain/Model/DimensionContentCollectionInterface.php b/Content/Domain/Model/DimensionContentCollectionInterface.php index 7ed53e14..ecaf873a 100644 --- a/Content/Domain/Model/DimensionContentCollectionInterface.php +++ b/Content/Domain/Model/DimensionContentCollectionInterface.php @@ -14,17 +14,21 @@ namespace Sulu\Bundle\ContentBundle\Content\Domain\Model; /** - * @extends \Traversable + * @template-covariant T of DimensionContentInterface + * + * @extends \Traversable */ interface DimensionContentCollectionInterface extends \Traversable, \Countable { /** * @param mixed[] $dimensionAttributes + * + * @return T|null */ public function getDimensionContent(array $dimensionAttributes): ?DimensionContentInterface; /** - * @return class-string + * @return class-string */ public function getDimensionContentClass(): string; diff --git a/Content/Domain/Model/ExcerptInterface.php b/Content/Domain/Model/ExcerptInterface.php index 6f404983..9f6e2862 100644 --- a/Content/Domain/Model/ExcerptInterface.php +++ b/Content/Domain/Model/ExcerptInterface.php @@ -61,22 +61,22 @@ public function getExcerptTagNames(): array; public function setExcerptTags(array $excerptTags): void; /** - * @return mixed[]|null + * @return array{id: int}|null */ public function getExcerptImage(): ?array; /** - * @param mixed[]|null $excerptImage + * @param array{id: int}|null $excerptImage */ public function setExcerptImage(?array $excerptImage): void; /** - * @return mixed[]|null + * @return array{id: int}|null */ public function getExcerptIcon(): ?array; /** - * @param mixed[]|null $excerptIcon + * @param array{id: int}|null $excerptIcon */ public function setExcerptIcon(?array $excerptIcon): void; } diff --git a/Content/Domain/Model/ExcerptTrait.php b/Content/Domain/Model/ExcerptTrait.php index 89ec9270..7cd35534 100644 --- a/Content/Domain/Model/ExcerptTrait.php +++ b/Content/Domain/Model/ExcerptTrait.php @@ -159,7 +159,7 @@ public function setExcerptTags(array $excerptTags): void } /** - * @return mixed[]|null + * @return array{id: int}|null */ public function getExcerptImage(): ?array { @@ -173,7 +173,7 @@ public function getExcerptImage(): ?array } /** - * @param mixed[]|null $excerptImage + * @param array{id: int}|null $excerptImage */ public function setExcerptImage(?array $excerptImage): void { @@ -181,7 +181,7 @@ public function setExcerptImage(?array $excerptImage): void } /** - * @return mixed[]|null + * @return array{id: int}|null */ public function getExcerptIcon(): ?array { @@ -195,7 +195,7 @@ public function getExcerptIcon(): ?array } /** - * @param mixed[]|null $excerptIcon + * @param array{id: int}|null $excerptIcon */ public function setExcerptIcon(?array $excerptIcon): void { diff --git a/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php b/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php index ef3803e9..59d6b08a 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php +++ b/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php @@ -44,7 +44,7 @@ class ContentStructureBridge implements StructureInterface, RoutableStructureInt protected $content; /** - * @var string + * @var string|int */ protected $id; @@ -58,11 +58,14 @@ class ContentStructureBridge implements StructureInterface, RoutableStructureInt */ private $loadedProperties = []; + /** + * @param string|int $id + */ public function __construct( StructureMetadata $structure, LegacyPropertyFactory $propertyFactory, TemplateInterface $content, - string $id, + $id, string $locale ) { $this->structure = $structure; @@ -108,11 +111,11 @@ public function getWebspaceKey(): ?string } /** - * @return mixed + * @return string */ public function getUuid() { - return $this->id; + return (string) $this->id; } public function setUuid($uuid): void @@ -432,7 +435,7 @@ public function getOriginTemplate(): ?string } /** - * @param mixed $name + * @param string $name * * @return mixed */ diff --git a/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php b/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php index 3a7cc152..ffad46a5 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php +++ b/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php @@ -36,7 +36,7 @@ public function __construct(StructureMetadataFactoryInterface $structureMetadata } /** - * @param mixed $id + * @param string|int $id */ public function getBridge(TemplateInterface $object, $id, string $locale): ContentStructureBridge { diff --git a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php index f6f1afd4..dab6b98b 100644 --- a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php +++ b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php @@ -81,7 +81,7 @@ public function __construct( } /** - * @param mixed[] $ids + * @param array $ids * @param string $locale * * @return Teaser[] @@ -115,7 +115,7 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale): ?Teaser { } /** - * @param mixed[] $data + * @param array $data */ protected function createTeaser(DimensionContentInterface $dimensionContent, array $data, string $locale): ?Teaser { @@ -129,10 +129,10 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr $title = $this->getTitle($dimensionContent, $data); /** @var string $description */ - $description = $this->getDescription($dimensionContent, $data); + $description = $this->getDescription($dimensionContent, $data); // @phpstan-ignore-line /** @var string $moreText */ - $moreText = $this->getMoreText($dimensionContent, $data); + $moreText = $this->getMoreText($dimensionContent, $data); // @phpstan-ignore-line /** @var int $mediaId */ $mediaId = $this->getMediaId($dimensionContent, $data); @@ -195,7 +195,7 @@ protected function getUrl(DimensionContentInterface $dimensionContent, array $da foreach ($metadata->getProperties() as $property) { if ('route' === $property->getType()) { - return $dimensionContent->getTemplateData()[$property->getName()] ?? null; + return $dimensionContent->getTemplateData()[$property->getName()] ?? null; // @phpstan-ignore-line } } @@ -217,7 +217,7 @@ protected function getTitle(DimensionContentInterface $dimensionContent, array $ } /** - * @param mixed[] $data + * @param array{description?: string|null} $data */ protected function getDescription(DimensionContentInterface $dimensionContent, array $data): ?string { @@ -231,7 +231,7 @@ protected function getDescription(DimensionContentInterface $dimensionContent, a } /** - * @param mixed[] $data + * @param array{more?: string|null, moreText?: string|null} $data */ protected function getMoreText(DimensionContentInterface $dimensionContent, array $data): ?string { @@ -252,7 +252,7 @@ protected function getMediaId(DimensionContentInterface $dimensionContent, array if ($dimensionContent instanceof ExcerptInterface) { if ($excerptImage = $dimensionContent->getExcerptImage()) { // TODO FIXME create unit test for this - return $excerptImage['id'] ?? null; // @codeCoverageIgnore + return $excerptImage['id']; // @codeCoverageIgnore } } @@ -270,7 +270,7 @@ protected function getAttributes(DimensionContentInterface $dimensionContent, ar } /** - * @param mixed[] $ids + * @param array $ids * * @return ContentRichEntityInterface[] */ @@ -279,6 +279,7 @@ protected function findEntitiesByIds(array $ids): array $entityIdField = $this->getEntityIdField(); $classMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); + /** @var ContentRichEntityInterface[] $entities */ $entities = $this->entityManager->createQueryBuilder() ->select(self::CONTENT_RICH_ENTITY_ALIAS) ->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS) diff --git a/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php b/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php index 23990293..0dc50db5 100644 --- a/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php +++ b/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php @@ -86,6 +86,7 @@ public function prepend(ContainerBuilder $container): void if ($container->hasExtension('sulu_search')) { $suluSearchConfigs = $container->getExtensionConfig('sulu_search'); + /** @var array{website?: array{ indexes?: array }} $suluSearchConfig */ foreach ($suluSearchConfigs as $suluSearchConfig) { if (isset($suluSearchConfig['website']['indexes'])) { $container->prependExtensionConfig( diff --git a/Tests/Application/ExampleTestBundle/Entity/Example.php b/Tests/Application/ExampleTestBundle/Entity/Example.php index e2d6df30..9c897837 100644 --- a/Tests/Application/ExampleTestBundle/Entity/Example.php +++ b/Tests/Application/ExampleTestBundle/Entity/Example.php @@ -25,12 +25,12 @@ class Example implements ContentRichEntityInterface public const TEMPLATE_TYPE = 'example'; /** - * @var mixed + * @var int|string */ public $id; /** - * @return mixed + * @return int|string */ public function getId() { diff --git a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php index 8e588fab..6a59a41e 100644 --- a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php +++ b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php @@ -89,7 +89,7 @@ public function getTemplateData(): array public function setTemplateData(array $templateData): void { - $this->setTitle($templateData['title']); + $this->setTitle($templateData['title']); // @phpstan-ignore-line unset($templateData['title']); $this->parentSetTemplateData($templateData); } diff --git a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php index a18739ec..caec3fe8 100644 --- a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php +++ b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php @@ -54,6 +54,12 @@ public function getConfiguration(): TeaserConfiguration ); } + /** + * @param array{ + * article?: string|null, + * description?: string|null, + * } $data + */ protected function getDescription(DimensionContentInterface $dimensionContent, array $data): ?string { $article = \strip_tags($data['article'] ?? ''); diff --git a/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php b/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php index bce579c4..9e0033c6 100644 --- a/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php +++ b/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php @@ -116,7 +116,10 @@ private function createContentRichEntity(): Example } /** - * @param mixed[] $dimensionAttributes + * @param array{ + * stage?: string, + * locale?: string, + * } $dimensionAttributes */ private function createContentDimension(Example $example, array $dimensionAttributes = []): ExampleDimensionContent { diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php index b6b0d626..0f89750a 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php @@ -13,7 +13,6 @@ namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Sulu\Search; -use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search\ContentReindexProvider; @@ -26,11 +25,6 @@ class ContentReindexProviderTest extends SuluTestCase { use CreateExampleTrait; - /** - * @var ContentManagerInterface - */ - private $contentManager; - /** * @var ContentReindexProvider */ @@ -50,7 +44,7 @@ public static function setUpBeforeClass(): void { static::purgeDatabase(); - static::$example1 = static::createExample( + self::$example1 = static::createExample( [ 'en' => [ 'draft' => [ @@ -65,7 +59,7 @@ public static function setUpBeforeClass(): void ] ); - static::$example2 = static::createExample( + self::$example2 = static::createExample( [ 'en' => [ 'draft' => [ @@ -80,7 +74,6 @@ public static function setUpBeforeClass(): void protected function setUp(): void { - $this->contentManager = $this->getContainer()->get('sulu_content.content_manager'); $this->reindexProvider = $this->getContainer()->get('example_test.example_reindex_provider'); } @@ -88,8 +81,8 @@ public function testProvide(): void { $examples = $this->reindexProvider->provide(ExampleDimensionContent::class, 0, 10); - $this->assertContains(static::$example1, $examples); - $this->assertContains(static::$example2, $examples); + $this->assertContains(self::$example1, $examples); + $this->assertContains(self::$example2, $examples); $this->assertCount(2, $examples); } @@ -117,7 +110,7 @@ public function testGetClassFqns(): void public function testGetLocalesForObject(): void { - $locales = $this->reindexProvider->getLocalesForObject(static::$example1); + $locales = $this->reindexProvider->getLocalesForObject(self::$example1); $this->assertSame(['en', 'de'], $locales); } @@ -136,14 +129,14 @@ public function testGetLocalesForObjectWebsite(): void $property->setAccessible(true); $property->setValue($this->reindexProvider, SuluKernel::CONTEXT_WEBSITE); - $locales = $this->reindexProvider->getLocalesForObject(static::$example1); + $locales = $this->reindexProvider->getLocalesForObject(self::$example1); $this->assertSame(['de'], $locales); } public function testTranslateObject(): void { - $translatedObject = $this->reindexProvider->translateObject(static::$example1, 'en'); + $translatedObject = $this->reindexProvider->translateObject(self::$example1, 'en'); $this->assertInstanceOf(DimensionContentInterface::class, $translatedObject); @@ -165,7 +158,7 @@ public function testTranslateObjectWebsite(): void $property->setAccessible(true); $property->setValue($this->reindexProvider, SuluKernel::CONTEXT_WEBSITE); - $translatedObject = $this->reindexProvider->translateObject(static::$example1, 'de'); + $translatedObject = $this->reindexProvider->translateObject(self::$example1, 'de'); $this->assertInstanceOf(DimensionContentInterface::class, $translatedObject); @@ -188,7 +181,7 @@ public function testTranslateObjectWebsiteNotPublished(): void $property->setValue($this->reindexProvider, SuluKernel::CONTEXT_WEBSITE); $this->assertNull( - $this->reindexProvider->translateObject(static::$example1, 'en') + $this->reindexProvider->translateObject(self::$example1, 'en') ); } diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php index e9404fb3..07d49256 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php @@ -51,7 +51,7 @@ public static function setUpBeforeClass(): void static::purgeDatabase(); parent::setUpBeforeClass(); - static::$example1 = static::createExample([ + self::$example1 = static::createExample([ 'en' => [ 'draft' => [ 'title' => 'example-1', @@ -71,7 +71,7 @@ protected function setUp(): void public function testGetMetadataForObject(): void { - $dimensionContent = $this->contentManager->resolve(static::$example1, [ + $dimensionContent = $this->contentManager->resolve(self::$example1, [ 'stage' => DimensionContentInterface::STAGE_DRAFT, 'locale' => 'en', ]); @@ -93,7 +93,7 @@ public function testGetMetadataForObjectNotMerged(): void { $this->assertNull( $this->searchMetadataProvider->getMetadataForObject( - (object) static::$example1->getDimensionContents()->first() + (object) self::$example1->getDimensionContents()->first() ) ); } @@ -111,7 +111,7 @@ public function testGetAllMetadata(): void public function testGetMetadataForDocument(): void { - $dimensionContent = $this->contentManager->resolve(static::$example1, [ + $dimensionContent = $this->contentManager->resolve(self::$example1, [ 'stage' => DimensionContentInterface::STAGE_DRAFT, 'locale' => 'en', ]); diff --git a/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php index 70baf04f..d0cdf624 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php @@ -23,6 +23,7 @@ use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Sulu\Component\SmartContent\ArrayAccessItem; use Sulu\Component\SmartContent\DataProviderResult; +use Sulu\Component\SmartContent\ResourceItemInterface; class ContentDataProviderTest extends SuluTestCase { @@ -71,7 +72,7 @@ public static function setUpBeforeClass(): void static::purgeDatabase(); parent::setUpBeforeClass(); - static::$categoryFoo = static::createCategory([ + self::$categoryFoo = static::createCategory([ 'en' => [ 'title' => 'Foo', ], @@ -80,27 +81,27 @@ public static function setUpBeforeClass(): void ], ]); - static::$categoryBar = static::createCategory([ + self::$categoryBar = static::createCategory([ 'en' => [ 'title' => 'Bar', ], ]); - static::$categoryBaz = static::createCategory([ + self::$categoryBaz = static::createCategory([ 'de' => [ 'title' => 'Baz', ], ]); - static::$tagA = static::createTag([ + self::$tagA = static::createTag([ 'name' => 'tagA', ]); - static::$tagB = static::createTag([ + self::$tagB = static::createTag([ 'name' => 'tagB', ]); - static::$tagC = static::createTag([ + self::$tagC = static::createTag([ 'name' => 'tagC', ]); @@ -117,12 +118,12 @@ public static function setUpBeforeClass(): void 'draft' => [ 'title' => 'example without categories without tags draft', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), ], 'excerptTags' => [ - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], 'live' => [ @@ -137,7 +138,7 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with some categories without tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], ], ], @@ -145,7 +146,7 @@ public static function setUpBeforeClass(): void 'draft' => [ 'title' => 'example with some categories without tags unpublished', 'excerptCategories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], 'excerptTags' => [], ], @@ -158,9 +159,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories without tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], ], ], @@ -168,9 +169,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories without tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'excerptTags' => [], ], @@ -183,7 +184,7 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with some tags', 'excerptTags' => [ - static::$tagA->getName(), + self::$tagA->getName(), ], ], ], @@ -191,7 +192,7 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with some tags', 'excerptTags' => [ - static::$tagA->getName(), + self::$tagA->getName(), ], ], ], @@ -203,9 +204,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with all tags', 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -213,9 +214,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with all tags', 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -227,10 +228,10 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with some categories with some tags', 'excerptCategories' => [ - static::$categoryBar->getId(), + self::$categoryBar->getId(), ], 'excerptTags' => [ - static::$tagB->getName(), + self::$tagB->getName(), ], ], ], @@ -238,10 +239,10 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with some categories with some tags', 'excerptCategories' => [ - static::$categoryBar->getId(), + self::$categoryBar->getId(), ], 'excerptTags' => [ - static::$tagB->getName(), + self::$tagB->getName(), ], ], ], @@ -253,14 +254,14 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories with all tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -268,14 +269,14 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories with all tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -306,9 +307,9 @@ public function testResolveDataItems(): void /** @var string $name */ /** @var string $locale */ - /** @var int $page */ - /** @var int $pageSize */ - /** @var int $limit */ + /** @var int|null $page */ + /** @var int|null $pageSize */ + /** @var int|null $limit */ /** @var mixed[] $filters */ /** @var int $expectedCount */ /** @var bool $expectedHasNextPage */ @@ -319,7 +320,7 @@ public function testResolveDataItems(): void 'locale' => $locale, ], $limit, - $page, + $page ?: 1, $pageSize ); @@ -389,7 +390,16 @@ public function testResolveResourceItemsSnapshot(): void /** * This method can't be a phpunit dataProvider, because then it wouldn't be possible to access the categories, because they don't exist at the time a dataProvider is called. * - * @return mixed[] + * @return array */ public function filters(): array { @@ -442,9 +452,9 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'OR', ], @@ -459,9 +469,9 @@ public function filters(): array null, [ 'tags' => [ - static::$tagA, - static::$tagB, - static::$tagC, + self::$tagA, + self::$tagB, + self::$tagC, ], 'tagOperator' => 'OR', ], @@ -476,15 +486,15 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'OR', 'tags' => [ - static::$tagA, - static::$tagB, - static::$tagC, + self::$tagA, + self::$tagB, + self::$tagC, ], 'tagOperator' => 'OR', ], @@ -499,12 +509,12 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], 'categoryOperator' => 'AND', 'websiteCategories' => [ - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'websiteCategoriesOperator' => 'OR', ], @@ -519,11 +529,11 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], 'websiteCategories' => [ - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'AND', 'websiteCategoriesOperator' => 'AND', @@ -539,11 +549,11 @@ public function filters(): array null, [ 'tags' => [ - static::$tagA, - static::$tagB, + self::$tagA, + self::$tagB, ], 'websiteTags' => [ - static::$tagC, + self::$tagC, ], 'tagOperator' => 'AND', 'websiteTagsOperator' => 'AND', @@ -559,15 +569,15 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'AND', 'tags' => [ - static::$tagA, - static::$tagB, - static::$tagC, + self::$tagA, + self::$tagB, + self::$tagC, ], 'tagOperator' => 'AND', ], @@ -611,7 +621,8 @@ public function filters(): array */ private function mapDataProviderResult(DataProviderResult $dataProviderResult): array { - return \array_map(function(ArrayAccessItem $item) { + return \array_map(function(ResourceItemInterface $item) { + /** @var ResourceItemInterface&ArrayAccessItem $item */ return [ 'id' => $item->getId(), 'excerptCategories' => $item['excerptCategories'], diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php index cd068be1..4651d3c7 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php @@ -30,15 +30,10 @@ class ContentTeaserProviderTest extends WebsiteTestCase private $exampleTeaserProvider; /** - * @var mixed[] + * @var array */ private static $exampleIds = []; - /** - * @var mixed - */ - private static $exampleIdNoRoute; - public static function setUpBeforeClass(): void { static::purgeDatabase(); @@ -109,11 +104,11 @@ public static function setUpBeforeClass(): void static::getEntityManager()->flush(); - static::$exampleIds[] = $example1->getId(); - static::$exampleIds[] = $example2->getId(); - static::$exampleIds[] = $example3->getId(); - static::$exampleIds[] = $example4->getId(); - static::$exampleIds[] = $example5->getId(); + self::$exampleIds[] = $example1->getId(); + self::$exampleIds[] = $example2->getId(); + self::$exampleIds[] = $example3->getId(); + self::$exampleIds[] = $example4->getId(); + self::$exampleIds[] = $example5->getId(); } protected function setUp(): void @@ -130,7 +125,7 @@ public function testEmpty(): void public function testFindDE(): void { - $teasers = $this->exampleTeaserProvider->find(static::$exampleIds, 'de'); + $teasers = $this->exampleTeaserProvider->find(self::$exampleIds, 'de'); $teasers = $this->mapTeasers($teasers); @@ -139,7 +134,7 @@ public function testFindDE(): void public function testFindEN(): void { - $teasers = $this->exampleTeaserProvider->find(static::$exampleIds, 'en'); + $teasers = $this->exampleTeaserProvider->find(self::$exampleIds, 'en'); $teasers = $this->mapTeasers($teasers); diff --git a/Tests/Functional/Integration/ExampleControllerTest.php b/Tests/Functional/Integration/ExampleControllerTest.php index 48f83201..0ecfe4b8 100644 --- a/Tests/Functional/Integration/ExampleControllerTest.php +++ b/Tests/Functional/Integration/ExampleControllerTest.php @@ -68,10 +68,11 @@ public function testPostPublish(): int $response = $this->client->getResponse(); $content = \json_decode((string) $response->getContent(), true); - $id = $content['id'] ?? null; + /** @var int $id */ + $id = $content['id'] ?? null; // @phpstan-ignore-line $this->assertResponseSnapshot('example_post_publish.json', $response, 201); - $this->assertNotSame('2020-05-08T00:00:00+00:00', $content['published']); + $this->assertNotSame('2020-05-08T00:00:00+00:00', $content['published']); // @phpstan-ignore-line self::ensureKernelShutdown(); @@ -136,7 +137,8 @@ public function testPost(): int $this->assertResponseSnapshot('example_post.json', $response, 201); - $id = \json_decode((string) $response->getContent(), true)['id'] ?? null; + /** @var int $id */ + $id = \json_decode((string) $response->getContent(), true)['id'] ?? null; // @phpstan-ignore-line return $id; } diff --git a/Tests/Traits/CreateCategoryTrait.php b/Tests/Traits/CreateCategoryTrait.php index 6e6b4745..74aa8cea 100644 --- a/Tests/Traits/CreateCategoryTrait.php +++ b/Tests/Traits/CreateCategoryTrait.php @@ -21,7 +21,7 @@ trait CreateCategoryTrait { /** - * @param array{de?: mixed, en?: mixed} $dataSet + * @param array $dataSet */ protected static function createCategory(array $dataSet = []): CategoryInterface { @@ -34,7 +34,7 @@ protected static function createCategory(array $dataSet = []): CategoryInterface $translation = new CategoryTranslation(); $translation->setCategory($category); $translation->setLocale($locale); - $translation->setTranslation($data['title'] ?? null); + $translation->setTranslation($data['title'] ?? ''); $category->addTranslation($translation); $entityManager->persist($translation); } diff --git a/Tests/Traits/CreateExampleTrait.php b/Tests/Traits/CreateExampleTrait.php index 759d1152..9a31850c 100644 --- a/Tests/Traits/CreateExampleTrait.php +++ b/Tests/Traits/CreateExampleTrait.php @@ -29,7 +29,7 @@ trait CreateExampleTrait { /** - * @param array{de?: mixed, en?: mixed} $dataSet + * @param array, live?: array }> $dataSet * @param array{create_route?: bool} $options */ protected static function createExample(array $dataSet = [], array $options = []): Example @@ -82,7 +82,7 @@ protected static function createExample(array $dataSet = [], array $options = [] foreach ($dataSet as $locale => $data) { // draft data - $draftData = $data['draft'] ?? $data['live']; + $draftData = $data['draft'] ?? $data['live'] ?? []; $liveData = $data['live'] ?? null; // create localized draft dimension @@ -139,8 +139,11 @@ protected static function createExample(array $dataSet = [], array $options = [] if ($options['create_route'] ?? false) { $route = new Route(); $route->setLocale($locale); - $route->setPath($draftLocalizedDimension->getTemplateData()['url']); - $route->setEntityId($example->getId()); + + /** @var array{url: string} $draftTemplateData */ + $draftTemplateData = $draftLocalizedDimension->getTemplateData(); + $route->setPath($draftTemplateData['url']); + $route->setEntityId($example->getId()); // @phpstan-ignore-line $route->setEntityClass(\get_class($example)); $entityManager->persist($route); diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php index dfb4eabd..be6e8de6 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php @@ -64,7 +64,7 @@ protected function createRouteDataMapperInstance( } /** - * @param ObjectProphecy $routableMock + * @param ObjectProphecy $routableMock */ protected function wrapRoutableMock(ObjectProphecy $routableMock): RoutableInterface { @@ -72,6 +72,12 @@ protected function wrapRoutableMock(ObjectProphecy $routableMock): RoutableInter DimensionContentInterface, TemplateInterface, RoutableInterface { + + /** + * @var DimensionContentInterface&TemplateInterface&RoutableInterface + */ + protected $instance; + use DimensionContentMockWrapperTrait, RoutableMockWrapperTrait { RoutableMockWrapperTrait::getLocale insteadof DimensionContentMockWrapperTrait; RoutableMockWrapperTrait::getResourceKey insteadof DimensionContentMockWrapperTrait; @@ -202,6 +208,7 @@ public function testMapNoTemplate(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -244,6 +251,7 @@ public function testMapNoMetadata(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -286,6 +294,7 @@ public function testMapNoRouteProperty(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -337,6 +346,7 @@ public function testMapNoRoutePropertyData(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -389,6 +399,7 @@ public function testMapNoRoutePropertyDataAndNoOldRoute(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); @@ -457,6 +468,7 @@ public function testMapNoRoutePropertyDataAndNoOldRouteIgnoreSlash(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); @@ -517,6 +529,7 @@ public function testMapNoContentId(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -564,6 +577,7 @@ public function testMapNoLocale(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -613,6 +627,7 @@ public function testMapNoRoutePath(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); @@ -681,6 +696,7 @@ public function testMap(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -742,6 +758,7 @@ public function testMapConflictingRoute(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -803,6 +820,7 @@ public function testMapNoTemplateWithDefaultTemplate(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -865,6 +883,7 @@ public function testMapCustomRoute(): void $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(RoutableInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php index 45b441ce..c2240263 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php @@ -39,13 +39,14 @@ protected function createTemplateDataMapperInstance( } /** - * @param ObjectProphecy $tempplateMock + * @param ObjectProphecy $templateMock */ - protected function wrapTemplateMock(ObjectProphecy $tempplateMock): TemplateInterface + protected function wrapTemplateMock(ObjectProphecy $templateMock): TemplateInterface { - return new class($tempplateMock) extends MockWrapper implements + return new class($templateMock) extends MockWrapper implements DimensionContentInterface, TemplateInterface { + use DimensionContentMockWrapperTrait; use TemplateMockWrapperTrait; }; @@ -86,6 +87,7 @@ public function testMapLocalizedNoTemplateKey(): void $structureMetadataFactory = $this->prophesize(StructureMetadataFactoryInterface::class); $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); @@ -127,6 +129,7 @@ public function testMapLocalizedNoTemplateInstance(): void )->willReturn($structureMetadata->reveal())->shouldBeCalled(); $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); @@ -157,6 +160,7 @@ public function testMapLocalizedNoStructureFound(): void )->willReturn(null)->shouldBeCalled(); $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); @@ -181,6 +185,7 @@ public function testMapUnlocalizedTemplate(): void ]; $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled(); $unlocalizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled(); @@ -222,12 +227,14 @@ public function testMapLocalizedTemplate(): void ]; $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled(); $unlocalizedDimensionContent->setTemplateData(['unlocalizedField' => 'Test Unlocalized'])->shouldBeCalled(); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); $localizedDimensionContent->willImplement(TemplateInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled(); $localizedDimensionContent->setTemplateData(['localizedField' => 'Test Localized'])->shouldBeCalled(); @@ -270,11 +277,13 @@ public function testMapLocalizedNoTemplateKeyWithDefaultTemplate(): void ]; $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled(); $unlocalizedDimensionContent->setTemplateData(['unlocalizedField' => 'Test Unlocalized'])->shouldBeCalled(); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled(); $localizedDimensionContent->setTemplateData(['localizedField' => 'Test Localized'])->shouldBeCalled(); @@ -322,11 +331,13 @@ public function testMapFloatValueTemplate(): void ]; $unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $unlocalizedDimensionContent */ $unlocalizedDimensionContent->willImplement(TemplateInterface::class); $unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled(); $unlocalizedDimensionContent->setTemplateData(['1.1' => 'Test Unlocalized'])->shouldBeCalled(); $localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); + /** @var ObjectProphecy $localizedDimensionContent */ $localizedDimensionContent->willImplement(TemplateInterface::class); $localizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled(); $localizedDimensionContent->setTemplateData(['localizedField' => 'Test Localized'])->shouldBeCalled(); diff --git a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php index 83c637cf..db63b2cb 100644 --- a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php +++ b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php @@ -24,12 +24,14 @@ class DimensionContentCollectionTest extends TestCase /** * @param DimensionContentInterface[] $dimensionContents * @param mixed[] $dimensionAttributes + * + * @return DimensionContentCollectionInterface */ protected function createDimensionContentCollectionInstance( array $dimensionContents, array $dimensionAttributes ): DimensionContentCollectionInterface { - return new DimensionContentCollection($dimensionContents, $dimensionAttributes, ExampleDimensionContent::class); + return new DimensionContentCollection($dimensionContents, $dimensionAttributes, DimensionContentInterface::class); } public function testCount(): void diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php index f338522d..eab7d2a4 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php @@ -74,21 +74,21 @@ public function testGetObject(int $id = 1, string $locale = 'de'): void $this->entityManager->createQueryBuilder()->willReturn($queryBuilder->reveal())->shouldBeCalledTimes(1); - $queryBuilder->select(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->select(Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->from(Argument::type('string'), Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->from(Argument::type('string'), Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->where(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->where(Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->setParameter(Argument::type('string'), Argument::any())->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->setParameter(Argument::type('string'), Argument::any()) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); $query = $this->prophesize(AbstractQuery::class); @@ -125,21 +125,21 @@ public function testGetObjectContentNotFound(int $id = 1, string $locale = 'de') $this->entityManager->createQueryBuilder()->willReturn($queryBuilder->reveal())->shouldBeCalledTimes(1); - $queryBuilder->select(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->select(Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->from(Argument::type('string'), Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->from(Argument::type('string'), Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->where(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->where(Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->setParameter(Argument::type('string'), Argument::any())->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->setParameter(Argument::type('string'), Argument::any()) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); $query = $this->prophesize(AbstractQuery::class); @@ -248,21 +248,21 @@ public function testDeserialize(): void $this->entityManager->createQueryBuilder()->willReturn($queryBuilder->reveal())->shouldBeCalledTimes(1); - $queryBuilder->select(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->select(Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->from(Argument::type('string'), Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->from(Argument::type('string'), Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->where(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->where(Argument::type('string')) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); - $queryBuilder->setParameter(Argument::type('string'), Argument::any())->will(function() { - return \func_get_arg(\func_num_args() - 2); - })->shouldBeCalledTimes(1); + $queryBuilder->setParameter(Argument::type('string'), Argument::any()) + ->willReturn($queryBuilder->reveal()) + ->shouldBeCalledTimes(1); $query = $this->prophesize(AbstractQuery::class); diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php index 2821ef37..c2ed446f 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentStructureBridge; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentStructureBridgeFactory; @@ -41,6 +42,7 @@ protected function getContentStructureBridgeFactory( */ protected function wrapTemplateMock(ObjectProphecy $templateMock): TemplateInterface { + /** @var ObjectProphecy $templateMock */ return new class($templateMock) extends MockWrapper implements TemplateInterface { use TemplateMockWrapperTrait; }; diff --git a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php index 13b7e4b9..6367efc0 100644 --- a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php +++ b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php @@ -14,11 +14,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; /** * Trait for composing a class that wraps a DimensionContentInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property DimensionContentInterface $instance */ trait DimensionContentMockWrapperTrait { @@ -42,7 +45,7 @@ public function getStage(): string return $this->instance->getStage(); } - public function setStage(?string $stage): void + public function setStage(string $stage): void { $this->instance->setStage($stage); } diff --git a/Tests/Unit/Mocks/MockWrapper.php b/Tests/Unit/Mocks/MockWrapper.php index 05fd2a27..7bf13763 100644 --- a/Tests/Unit/Mocks/MockWrapper.php +++ b/Tests/Unit/Mocks/MockWrapper.php @@ -14,8 +14,6 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; use Prophecy\Prophecy\ObjectProphecy; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; /** @@ -24,22 +22,24 @@ * possible to mock calls to static methods in PHP (https://phpunit.readthedocs.io/en/9.0/test-doubles.html). * * Therefore, when testing a service that calls a static method of a given object (eg. a TemplateInterface mock), - * we need to wrap the the mock into a wrapper-class that implements the static method that is called. If we dont + * we need to wrap the mock into a wrapper-class that implements the static method that is called. If we dont * do this, accessing the static method will fail with a "Error: Using $this when not in object context" message. * * Along with the traits in this namespace, this class provides a simple way for composing a wrapper-class that * that implements specific interfaces. For example, @see TemplateDataMapperTest::wrapTemplateMock to learn how to * compose such a wrapper-class. + * + * @template-covariant T of object */ class MockWrapper { /** - * @var mixed + * @var T */ protected $instance; /** - * @param ObjectProphecy|ObjectProphecy|ObjectProphecy $configuredMock + * @param ObjectProphecy $configuredMock */ public function __construct(ObjectProphecy $configuredMock) { diff --git a/Tests/Unit/Mocks/RoutableMockWrapperTrait.php b/Tests/Unit/Mocks/RoutableMockWrapperTrait.php index 57e168d8..0ee97c7d 100644 --- a/Tests/Unit/Mocks/RoutableMockWrapperTrait.php +++ b/Tests/Unit/Mocks/RoutableMockWrapperTrait.php @@ -13,10 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface; + /** * Trait for composing a class that wraps a RoutableInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property RoutableInterface $instance */ trait RoutableMockWrapperTrait { diff --git a/Tests/Unit/Mocks/TemplateMockWrapperTrait.php b/Tests/Unit/Mocks/TemplateMockWrapperTrait.php index e8d184b3..18737356 100644 --- a/Tests/Unit/Mocks/TemplateMockWrapperTrait.php +++ b/Tests/Unit/Mocks/TemplateMockWrapperTrait.php @@ -13,10 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; + /** * Trait for composing a class that wraps a TemplateInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property TemplateInterface $instance */ trait TemplateMockWrapperTrait { diff --git a/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php b/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php index a7a6e203..5d8777a1 100644 --- a/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php +++ b/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php @@ -13,10 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; + /** * Trait for composing a class that wraps a WorkflowInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property WorkflowInterface $instance */ trait WorkflowMockWrapperTrait { diff --git a/composer.json b/composer.json index 5a0f85e7..510bb6d9 100644 --- a/composer.json +++ b/composer.json @@ -42,15 +42,15 @@ "handcraftedinthealps/code-coverage-checker": "^0.2.1", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4", - "jangregor/phpstan-prophecy": "^0.8", + "jangregor/phpstan-prophecy": "^1.0", "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^4.0", "phpspec/prophecy": "^1.14", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-symfony": "^0.12", - "phpstan/phpstan-webmozart-assert": "^0.12", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-symfony": "^1.0", + "phpstan/phpstan-webmozart-assert": "^1.0", "qossmic/deptrac-shim": "^0.11.1 || ^0.23.0", "sulu/automation-bundle": "^2.0@dev", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", @@ -60,7 +60,7 @@ "symfony/monolog-bundle": "^3.1", "symfony/phpunit-bridge": "^5.4 || ^6.0", "symfony/string": "^4.4 || ^5.4 || ^6.0", - "thecodingmachine/phpstan-strict-rules": "^0.12" + "thecodingmachine/phpstan-strict-rules": "^1.0" }, "conflict": { "doctrine/persistence": "1.3.2" diff --git a/phpstan.neon b/phpstan.neon index b95a3e16..dafdfa20 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,11 +11,12 @@ parameters: paths: - . level: max - excludes_analyse: + excludePaths: - %currentWorkingDirectory%/DependencyInjection/Configuration.php - %currentWorkingDirectory%/vendor/* - %currentWorkingDirectory%/Tests/Application/Kernel.php - %currentWorkingDirectory%/Tests/Application/var/* + - %currentWorkingDirectory%/Tests/Unit/Mocks/* symfony: container_xml_path: %currentWorkingDirectory%/Tests/Application/var/cache/admin/dev/Sulu_Bundle_ContentBundle_Tests_Application_KernelDevDebugContainer.xml console_application_loader: Tests/phpstan/console-application.php From 2d0fa05efcbcbcc0bbb07319d0f4d7d30d7805e1 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 15 Mar 2023 19:53:03 +0100 Subject: [PATCH 2/9] Allow composer plugins --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 510bb6d9..e650bfeb 100644 --- a/composer.json +++ b/composer.json @@ -66,7 +66,11 @@ "doctrine/persistence": "1.3.2" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "composer/package-versions-deprecated": true, + "php-http/discovery": true + } }, "autoload": { "psr-4": { From 43e3033be636c988bebdab84800a2b602c544993 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 15 Mar 2023 22:31:01 +0100 Subject: [PATCH 3/9] Add missing prophecy trait --- .../ContentCopier/ContentCopierTest.php | 2 + .../ContentDataMapperTest.php | 2 + .../DataMapper/ExcerptDataMapperTest.php | 2 + .../DataMapper/RoutableDataMapperTest.php | 3 +- .../DataMapper/SeoDataMapperTest.php | 2 + .../DataMapper/TemplateDataMapperTest.php | 3 +- .../DataMapper/WorkflowDataMapperTest.php | 2 + .../ContentIndexer/ContentIndexerTest.php | 2 + .../ContentManager/ContentManagerTest.php | 2 + .../ContentMerger/ContentMergerTest.php | 2 + .../Merger/ExcerptMergerTest.php | 2 + .../ContentMerger/Merger/SeoMergerTest.php | 2 + .../Merger/TemplateMergerTest.php | 2 + .../Merger/WorkflowMergerTest.php | 2 + .../ContentMetadataInspectorTest.php | 2 + .../ContentNormalizerTest.php | 2 + .../DimensionContentNormalizerTest.php | 2 + .../Normalizer/ExcerptNormalizerTest.php | 2 + .../Normalizer/RoutableNormalizerTest.php | 2 + .../Normalizer/TemplateNormalizerTest.php | 2 + .../Normalizer/WorkflowNormalizerTest.php | 2 + .../ContentPersister/ContentPersisterTest.php | 2 + .../ContentResolver/ContentResolverTest.php | 2 + .../ContentWorkflow/ContentWorkflowTest.php | 2 + .../PublishTransitionSubscriberTest.php | 2 + .../RemoveDraftTransitionSubscriberTest.php | 2 + .../UnpublishTransitionSubscriberTest.php | 2 + .../DimensionContentCollectionFactoryTest.php | 2 + .../Model/ContentRichEntityTraitTest.php | 2 + .../Model/DimensionContentCollectionTest.php | 2 + .../Domain/Model/RoutableTraitTest.php | 2 + .../Doctrine/MetadataLoaderTest.php | 2 + .../Admin/ContentViewBuilderFactoryTest.php | 2 + .../ContentPublishTaskHandlerTest.php | 1 + .../ContentUnpublishTaskHandlerTest.php | 1 + .../Preview/ContentObjectProviderTest.php | 1 + .../PreviewDimensionContentCollectionTest.php | 4 +- .../ContentRouteDefaultsProviderTest.php | 2 + .../DataItem/ContentDataItemTest.php | 2 + .../Sulu/Structure/ContentDocumentTest.php | 2 + .../ContentStructureBridgeFactoryTest.php | 3 +- .../Structure/ContentStructureBridgeTest.php | 2 + composer.json | 4 +- phpunit.xml.dist | 46 +++++++++++-------- 44 files changed, 111 insertions(+), 25 deletions(-) diff --git a/Tests/Unit/Content/Application/ContentCopier/ContentCopierTest.php b/Tests/Unit/Content/Application/ContentCopier/ContentCopierTest.php index e32189e0..51732670 100644 --- a/Tests/Unit/Content/Application/ContentCopier/ContentCopierTest.php +++ b/Tests/Unit/Content/Application/ContentCopier/ContentCopierTest.php @@ -26,6 +26,8 @@ class ContentCopierTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentCopierInstance( ContentResolverInterface $contentResolver, ContentMergerInterface $contentMerger, diff --git a/Tests/Unit/Content/Application/ContentDataMapper/ContentDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/ContentDataMapperTest.php index 68567063..2078c2ac 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/ContentDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/ContentDataMapperTest.php @@ -21,6 +21,8 @@ class ContentDataMapperTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param iterable $dataMappers */ diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapperTest.php index 8cbe5e5e..c7b86cc4 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapperTest.php @@ -24,6 +24,8 @@ class ExcerptDataMapperTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createExcerptDataMapperInstance( TagFactoryInterface $tagFactory, CategoryFactoryInterface $categoryFactory diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php index be6e8de6..5897a77c 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php @@ -35,6 +35,8 @@ class RoutableDataMapperTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param array $structureDefaultTypes * @param array> $resourceKeyMappings @@ -72,7 +74,6 @@ protected function wrapRoutableMock(ObjectProphecy $routableMock): RoutableInter DimensionContentInterface, TemplateInterface, RoutableInterface { - /** * @var DimensionContentInterface&TemplateInterface&RoutableInterface */ diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/SeoDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/SeoDataMapperTest.php index 5976ead9..2bc82240 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/SeoDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/SeoDataMapperTest.php @@ -21,6 +21,8 @@ class SeoDataMapperTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createSeoDataMapperInstance(): SeoDataMapper { return new SeoDataMapper(); diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php index c2240263..e7cadeb2 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapperTest.php @@ -28,6 +28,8 @@ class TemplateDataMapperTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param array $structureDefaultTypes */ @@ -46,7 +48,6 @@ protected function wrapTemplateMock(ObjectProphecy $templateMock): TemplateInter return new class($templateMock) extends MockWrapper implements DimensionContentInterface, TemplateInterface { - use DimensionContentMockWrapperTrait; use TemplateMockWrapperTrait; }; diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapperTest.php index 875b99b8..723ac60c 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapperTest.php @@ -22,6 +22,8 @@ class WorkflowDataMapperTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createWorkflowDataMapperInstance(): WorkflowDataMapper { return new WorkflowDataMapper(); diff --git a/Tests/Unit/Content/Application/ContentIndexer/ContentIndexerTest.php b/Tests/Unit/Content/Application/ContentIndexer/ContentIndexerTest.php index ac60e4d5..03def389 100644 --- a/Tests/Unit/Content/Application/ContentIndexer/ContentIndexerTest.php +++ b/Tests/Unit/Content/Application/ContentIndexer/ContentIndexerTest.php @@ -29,6 +29,8 @@ class ContentIndexerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentIndexerInstance( SearchManagerInterface $searchManager, ContentResolverInterface $contentResolver diff --git a/Tests/Unit/Content/Application/ContentManager/ContentManagerTest.php b/Tests/Unit/Content/Application/ContentManager/ContentManagerTest.php index eef77a45..a7b986e7 100644 --- a/Tests/Unit/Content/Application/ContentManager/ContentManagerTest.php +++ b/Tests/Unit/Content/Application/ContentManager/ContentManagerTest.php @@ -27,6 +27,8 @@ class ContentManagerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentManagerInstance( ContentResolverInterface $contentResolver, ContentPersisterInterface $contentPersister, diff --git a/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php index 748c4c49..58828b7b 100644 --- a/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php @@ -25,6 +25,8 @@ class ContentMergerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param iterable $mergers */ diff --git a/Tests/Unit/Content/Application/ContentMerger/Merger/ExcerptMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/Merger/ExcerptMergerTest.php index b25f8e34..37c30b80 100644 --- a/Tests/Unit/Content/Application/ContentMerger/Merger/ExcerptMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/Merger/ExcerptMergerTest.php @@ -24,6 +24,8 @@ class ExcerptMergerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getExcerptMergerInstance(): MergerInterface { return new ExcerptMerger(); diff --git a/Tests/Unit/Content/Application/ContentMerger/Merger/SeoMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/Merger/SeoMergerTest.php index 524b364c..3fd7ffce 100644 --- a/Tests/Unit/Content/Application/ContentMerger/Merger/SeoMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/Merger/SeoMergerTest.php @@ -22,6 +22,8 @@ class SeoMergerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getSeoMergerInstance(): MergerInterface { return new SeoMerger(); diff --git a/Tests/Unit/Content/Application/ContentMerger/Merger/TemplateMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/Merger/TemplateMergerTest.php index 06e569c3..e0df1ae0 100644 --- a/Tests/Unit/Content/Application/ContentMerger/Merger/TemplateMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/Merger/TemplateMergerTest.php @@ -22,6 +22,8 @@ class TemplateMergerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getTemplateMergerInstance(): MergerInterface { return new TemplateMerger(); diff --git a/Tests/Unit/Content/Application/ContentMerger/Merger/WorkflowMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/Merger/WorkflowMergerTest.php index e94d90a6..0d1672b0 100644 --- a/Tests/Unit/Content/Application/ContentMerger/Merger/WorkflowMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/Merger/WorkflowMergerTest.php @@ -21,6 +21,8 @@ class WorkflowMergerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getWorkflowMergerInstance(): MergerInterface { return new WorkflowMerger(); diff --git a/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php b/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php index fad91f85..099817f9 100644 --- a/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php +++ b/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php @@ -23,6 +23,8 @@ class ContentMetadataInspectorTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentMetadataInspectorTestInstance( EntityManagerInterface $entityManager ): ContentMetadataInspectorInterface { diff --git a/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php index 12dbd407..1fd08d4f 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php @@ -39,6 +39,8 @@ class ContentNormalizerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentNormalizerInstance(): ContentNormalizerInterface { return new ContentNormalizer([ diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php index e2bd14e1..e4c394f7 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php @@ -20,6 +20,8 @@ class DimensionContentNormalizerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createDimensionContentNormalizerInstance(): DimensionContentNormalizer { return new DimensionContentNormalizer(); diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/ExcerptNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/ExcerptNormalizerTest.php index 49dc2f13..b4fcd60d 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/ExcerptNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/ExcerptNormalizerTest.php @@ -19,6 +19,8 @@ class ExcerptNormalizerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createExcerptNormalizerInstance(): ExcerptNormalizer { return new ExcerptNormalizer(); diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/RoutableNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/RoutableNormalizerTest.php index 97055f04..e1ebcdfc 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/RoutableNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/RoutableNormalizerTest.php @@ -19,6 +19,8 @@ class RoutableNormalizerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createRoutableNormalizerInstance(): RoutableNormalizer { return new RoutableNormalizer(); diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizerTest.php index 70c9bae5..4365c504 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizerTest.php @@ -19,6 +19,8 @@ class TemplateNormalizerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createTemplateNormalizerInstance(): TemplateNormalizer { return new TemplateNormalizer(); diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/WorkflowNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/WorkflowNormalizerTest.php index 32aee3e5..d59194dd 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/WorkflowNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/WorkflowNormalizerTest.php @@ -19,6 +19,8 @@ class WorkflowNormalizerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createWorkflowNormalizerInstance(): WorkflowNormalizer { return new WorkflowNormalizer(); diff --git a/Tests/Unit/Content/Application/ContentPersister/ContentPersisterTest.php b/Tests/Unit/Content/Application/ContentPersister/ContentPersisterTest.php index 5031553f..003e236f 100644 --- a/Tests/Unit/Content/Application/ContentPersister/ContentPersisterTest.php +++ b/Tests/Unit/Content/Application/ContentPersister/ContentPersisterTest.php @@ -25,6 +25,8 @@ class ContentPersisterTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentPersisterInstance( DimensionContentCollectionFactoryInterface $dimensionContentCollectionFactory, ContentMergerInterface $contentMerger diff --git a/Tests/Unit/Content/Application/ContentResolver/ContentResolverTest.php b/Tests/Unit/Content/Application/ContentResolver/ContentResolverTest.php index 16bcb4c0..e549390d 100644 --- a/Tests/Unit/Content/Application/ContentResolver/ContentResolverTest.php +++ b/Tests/Unit/Content/Application/ContentResolver/ContentResolverTest.php @@ -27,6 +27,8 @@ class ContentResolverTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentResolverInstance( DimensionContentRepositoryInterface $dimensionContentRepository, ContentMergerInterface $contentMerger diff --git a/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php b/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php index 1b39aacd..f22b9b0a 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php @@ -34,6 +34,8 @@ class ContentWorkflowTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentWorkflowInstance( DimensionContentRepositoryInterface $dimensionContentRepository, ContentMergerInterface $contentMerger diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php index 21b6a5e2..0bbb2512 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php @@ -27,6 +27,8 @@ class PublishTransitionSubscriberTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + public function createContentPublisherSubscriberInstance( ContentCopierInterface $contentCopier ): PublishTransitionSubscriber { diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php index a155c4c0..6dc8717b 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php @@ -26,6 +26,8 @@ class RemoveDraftTransitionSubscriberTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + public function createContentRemoveDraftSubscriberInstance( ContentCopierInterface $contentCopier ): RemoveDraftTransitionSubscriber { diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php index 0fcdc3f8..65cb1372 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php @@ -29,6 +29,8 @@ class UnpublishTransitionSubscriberTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + public function createContentUnpublishSubscriberInstance( DimensionContentRepositoryInterface $dimensionContentRepository, EntityManagerInterface $entityManager diff --git a/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php b/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php index 4217c637..d6557691 100644 --- a/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php +++ b/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php @@ -27,6 +27,8 @@ class DimensionContentCollectionFactoryTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param mixed[] $dimensionAttributes * @param DimensionContentInterface[] $existDimensionContents diff --git a/Tests/Unit/Content/Domain/Model/ContentRichEntityTraitTest.php b/Tests/Unit/Content/Domain/Model/ContentRichEntityTraitTest.php index 1820200d..2babebb3 100644 --- a/Tests/Unit/Content/Domain/Model/ContentRichEntityTraitTest.php +++ b/Tests/Unit/Content/Domain/Model/ContentRichEntityTraitTest.php @@ -20,6 +20,8 @@ class ContentRichEntityTraitTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getContentRichEntityInstance(): ContentRichEntityInterface { return new class() implements ContentRichEntityInterface { diff --git a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php index db63b2cb..a11c7909 100644 --- a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php +++ b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php @@ -21,6 +21,8 @@ class DimensionContentCollectionTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param DimensionContentInterface[] $dimensionContents * @param mixed[] $dimensionAttributes diff --git a/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php b/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php index ef441d61..5add2c4d 100644 --- a/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php +++ b/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php @@ -20,6 +20,8 @@ class RoutableTraitTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getRoutableInstance(): RoutableInterface { $contentRichEntity = $this->prophesize(ContentRichEntityInterface::class); diff --git a/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php b/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php index 88e56054..7433e07d 100644 --- a/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php +++ b/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php @@ -33,6 +33,8 @@ class MetadataLoaderTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getMetadataLoader(): MetadataLoader { return new MetadataLoader(); diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php index 13f966a5..80495f90 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php @@ -45,6 +45,8 @@ class ContentViewBuilderFactoryTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentViewBuilder( ContentMetadataInspectorInterface $contentMetadataInspector, SecurityCheckerInterface $securityChecker, diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php index 83f6c279..42bd9195 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php @@ -28,6 +28,7 @@ class ContentPublishTaskHandlerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; /** * @var EntityManagerInterface|ObjectProphecy */ diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php index 07507069..89cb3545 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php @@ -28,6 +28,7 @@ class ContentUnpublishTaskHandlerTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; /** * @var EntityManagerInterface|ObjectProphecy */ diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php index eab7d2a4..91fe6d8e 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php @@ -33,6 +33,7 @@ class ContentObjectProviderTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; /** * @var ObjectProphecy|EntityManagerInterface */ diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php index d9c4d5be..872fa4e5 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php @@ -11,7 +11,7 @@ * with this source code in the file LICENSE. */ -namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Structure; +namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Preview; use PHPUnit\Framework\TestCase; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; @@ -21,6 +21,8 @@ class PreviewDimensionContentCollectionTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createPreviewDimensionContentCollection( ?DimensionContentInterface $previewDimensionContent = null, string $locale = 'en' diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProviderTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProviderTest.php index aa80d635..b510106b 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProviderTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProviderTest.php @@ -34,6 +34,8 @@ class ContentRouteDefaultsProviderTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getContentRouteDefaultsProvider( EntityManagerInterface $entityManager, ContentResolverInterface $contentResolver, diff --git a/Tests/Unit/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItemTest.php b/Tests/Unit/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItemTest.php index ccde8e84..1c9cc268 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItemTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItemTest.php @@ -21,6 +21,8 @@ class ContentDataItemTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * @param mixed[] $data */ diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentDocumentTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentDocumentTest.php index d914ef72..7b5fcd80 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentDocumentTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentDocumentTest.php @@ -22,6 +22,8 @@ class ContentDocumentTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createContentDocument( ?TemplateInterface $content = null, string $locale = 'en' diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php index c2ed446f..173df37f 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactoryTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentStructureBridge; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentStructureBridgeFactory; @@ -28,6 +27,8 @@ class ContentStructureBridgeFactoryTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function getContentStructureBridgeFactory( StructureMetadataFactoryInterface $structureMetadataFactory, LegacyPropertyFactory $propertyFactory diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php index 58e60c9f..83846937 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php @@ -30,6 +30,8 @@ class ContentStructureBridgeTest extends TestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + protected function createStructureBridge( ?TemplateInterface $content = null, ?StructureMetadata $structure = null, diff --git a/composer.json b/composer.json index e650bfeb..2f050f60 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^4.0", "phpspec/prophecy": "^1.14", + "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "^1.0", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", @@ -81,7 +82,8 @@ "autoload-dev": { "psr-4": { "Sulu\\Bundle\\ContentBundle\\Tests\\": "Tests/" - } + }, + "exclude-from-classmap": ["/Tests/Application/assets"] }, "scripts": { "bootstrap-dev-environment": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1767f092..a936430b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,38 +1,44 @@ - + - - - - - - ./Tests + + ./Tests/Unit + + + + ./Tests/Functional - - - . - - Resources/ - TestCases/ - Tests/ - vendor/ - .php-cs-fixer.dist.php - Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php - - - + + + src + + + + Resources/ + TestCases/ + Tests/ + vendor/ + .php-cs-fixer.dist.php + Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php + + From 7654e606a70f921dc06df01f79c7950bbe404f85 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 15 Mar 2023 22:33:58 +0100 Subject: [PATCH 4/9] Use ExampleDimensionContent in DimensionContentCollectionTest --- .../Model/DimensionContentCollectionTest.php | 89 ++++++++++--------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php index a11c7909..465dc373 100644 --- a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php +++ b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php @@ -17,6 +17,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollection; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; class DimensionContentCollectionTest extends TestCase @@ -33,23 +34,23 @@ protected function createDimensionContentCollectionInstance( array $dimensionContents, array $dimensionAttributes ): DimensionContentCollectionInterface { - return new DimensionContentCollection($dimensionContents, $dimensionAttributes, DimensionContentInterface::class); + return new DimensionContentCollection($dimensionContents, $dimensionAttributes, ExampleDimensionContent::class); } public function testCount(): void { - $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent1->getLocale()->willReturn(null); - $dimensionContent1->getStage()->willReturn('draft'); - $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent2->getLocale()->willReturn('de'); - $dimensionContent2->getStage()->willReturn('draft'); + $example = new Example(); + $dimensionContent1 = new ExampleDimensionContent($example); + $dimensionContent1->setStage('draft'); + $dimensionContent2 = new ExampleDimensionContent($example); + $dimensionContent2->setLocale('de'); + $dimensionContent2->setStage('draft'); $attributes = ['locale' => 'de']; $dimensionContentCollection = $this->createDimensionContentCollectionInstance([ - $dimensionContent1->reveal(), - $dimensionContent2->reveal(), + $dimensionContent1, + $dimensionContent2, ], $attributes); $this->assertCount(2, $dimensionContentCollection); @@ -59,40 +60,40 @@ public function testCount(): void public function testIterator(): void { - $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent1->getLocale()->willReturn(null); - $dimensionContent1->getStage()->willReturn('draft'); - $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent2->getLocale()->willReturn('de'); - $dimensionContent2->getStage()->willReturn('draft'); + $example = new Example(); + $dimensionContent1 = new ExampleDimensionContent($example); + $dimensionContent1->setStage('draft'); + $dimensionContent2 = new ExampleDimensionContent($example); + $dimensionContent2->setLocale('de'); + $dimensionContent2->setStage('draft'); $attributes = ['locale' => 'de']; $dimensionContentCollection = $this->createDimensionContentCollectionInstance([ - $dimensionContent1->reveal(), - $dimensionContent2->reveal(), + $dimensionContent1, + $dimensionContent2, ], $attributes); $this->assertSame([ - $dimensionContent1->reveal(), - $dimensionContent2->reveal(), + $dimensionContent1, + $dimensionContent2, ], \iterator_to_array($dimensionContentCollection)); } public function testGetDimensionContentClass(): void { - $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent1->getLocale()->willReturn(null); - $dimensionContent1->getStage()->willReturn('draft'); - $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent2->getLocale()->willReturn('de'); - $dimensionContent2->getStage()->willReturn('draft'); + $example = new Example(); + $dimensionContent1 = new ExampleDimensionContent($example); + $dimensionContent1->setStage('draft'); + $dimensionContent2 = new ExampleDimensionContent($example); + $dimensionContent2->setLocale('de'); + $dimensionContent2->setStage('draft'); $attributes = ['locale' => 'de']; $dimensionContentCollection = $this->createDimensionContentCollectionInstance([ - $dimensionContent1->reveal(), - $dimensionContent2->reveal(), + $dimensionContent1, + $dimensionContent2, ], $attributes); $this->assertSame( @@ -103,18 +104,18 @@ public function testGetDimensionContentClass(): void public function testGetDimensionAttributes(): void { - $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent1->getLocale()->willReturn(null); - $dimensionContent1->getStage()->willReturn('draft'); - $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent2->getLocale()->willReturn('de'); - $dimensionContent2->getStage()->willReturn('draft'); + $example = new Example(); + $dimensionContent1 = new ExampleDimensionContent($example); + $dimensionContent1->setStage('draft'); + $dimensionContent2 = new ExampleDimensionContent($example); + $dimensionContent2->setLocale('de'); + $dimensionContent2->setStage('draft'); $attributes = ['locale' => 'de']; $dimensionContentCollection = $this->createDimensionContentCollectionInstance([ - $dimensionContent1->reveal(), - $dimensionContent2->reveal(), + $dimensionContent1, + $dimensionContent2, ], $attributes); $this->assertSame( @@ -125,22 +126,22 @@ public function testGetDimensionAttributes(): void public function testGetDimensionContent(): void { - $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent1->getLocale()->willReturn(null); - $dimensionContent1->getStage()->willReturn('draft'); - $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent2->getLocale()->willReturn('de'); - $dimensionContent2->getStage()->willReturn('draft'); + $example = new Example(); + $dimensionContent1 = new ExampleDimensionContent($example); + $dimensionContent1->setStage('draft'); + $dimensionContent2 = new ExampleDimensionContent($example); + $dimensionContent2->setLocale('de'); + $dimensionContent2->setStage('draft'); $attributes = ['locale' => 'de']; $dimensionContentCollection = $this->createDimensionContentCollectionInstance([ - $dimensionContent1->reveal(), - $dimensionContent2->reveal(), + $dimensionContent1, + $dimensionContent2, ], $attributes); $this->assertSame( - $dimensionContent2->reveal(), + $dimensionContent2, $dimensionContentCollection->getDimensionContent($attributes) ); } From 99cfe29433a5274770a0cd8119bc55aa514889c7 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 15 Mar 2023 23:02:59 +0100 Subject: [PATCH 5/9] Avoid the PHPUnit bridge --- .github/workflows/test-application.yaml | 13 ++++++++----- .../Repository/ContentDataProviderRepository.php | 8 ++------ composer.json | 8 ++++---- phpstan.neon | 2 -- phpunit.xml.dist | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 27477afd..ffc0abf4 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -24,25 +24,28 @@ jobs: - php-version: '7.2' coverage: false dependency-versions: 'lowest' - tools: 'composer:v1' env: SYMFONY_DEPRECATIONS_HELPER: disabled - php-version: '7.4' - coverage: true + coverage: false dependency-versions: 'highest' - tools: 'composer:v2' env: SYMFONY_DEPRECATIONS_HELPER: weak - php-version: '8.0' coverage: false dependency-versions: 'highest' - tools: 'composer:v2' env: SYMFONY_DEPRECATIONS_HELPER: weak - php-version: '8.1' + coverage: true + dependency-versions: 'highest' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + + - php-version: '8.2' coverage: false dependency-versions: 'highest' env: @@ -67,7 +70,7 @@ jobs: php-version: ${{ matrix.php-version }} extensions: ctype, iconv, mysql coverage: pcov - tools: ${{ matrix.tools }} + tools: 'composer:v2' - name: Install composer dependencies uses: ramsey/composer-install@v2 diff --git a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php index 435dc1f9..82db7339 100644 --- a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php +++ b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php @@ -96,9 +96,7 @@ public function findByFilters($filters, $page, $pageSize, $limit, $locale, $opti return \array_filter( \array_map( function(ContentRichEntityInterface $contentRichEntity) use ($locale, $showUnpublished) { - $stage = $showUnpublished - ? DimensionContentInterface::STAGE_DRAFT - : DimensionContentInterface::STAGE_LIVE; + $stage = $showUnpublished ? DimensionContentInterface::STAGE_DRAFT : DimensionContentInterface::STAGE_LIVE; $resolvedDimensionContent = $this->contentManager->resolve( $contentRichEntity, @@ -457,9 +455,7 @@ protected function appendRelationAnd(QueryBuilder $queryBuilder, string $relatio protected function createEntityIdsQueryBuilder(string $locale): QueryBuilder { - $stage = $this->showDrafts - ? DimensionContentInterface::STAGE_DRAFT - : DimensionContentInterface::STAGE_LIVE; + $stage = $this->showDrafts ? DimensionContentInterface::STAGE_DRAFT : DimensionContentInterface::STAGE_LIVE; return $this->entityManager->createQueryBuilder() // no distinct used here else it would hurt performance of the query: https://github.com/sulu/SuluContentBundle/pull/226 diff --git a/composer.json b/composer.json index 2f050f60..0ed4838a 100644 --- a/composer.json +++ b/composer.json @@ -46,13 +46,14 @@ "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^4.0", "phpspec/prophecy": "^1.14", - "phpspec/prophecy-phpunit": "^2.0", + "phpspec/prophecy-phpunit": "^1.1 || ^2.0", "phpstan/phpstan": "^1.0", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpstan/phpstan-webmozart-assert": "^1.0", - "qossmic/deptrac-shim": "^0.11.1 || ^0.23.0", + "phpunit/phpunit": "^8.5.33 || ^9.6.5", + "qossmic/deptrac-shim": "^0.11.1 || ^0.23.0 || ^1.0", "sulu/automation-bundle": "^2.0@dev", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", "symfony/console": "^4.4 || ^5.4 || ^6.0", @@ -107,14 +108,13 @@ "test": [ "@phpunit" ], - "phpunit": "vendor/bin/simple-phpunit", + "phpunit": "vendor/bin/phpunit", "test-with-coverage": "@phpunit --coverage-php Tests/reports/coverage.php --coverage-html Tests/reports/html --log-junit Tests/reports/unit/junit.xml --coverage-clover Tests/reports/clover.xml", "check-coverage": [ "@php vendor/bin/code-coverage-checker \"Tests/reports/coverage.php\" \"line\" \"100.00\" \"Content\" \"DependencyInjection\"" ], "phpstan": [ "Tests/Application/bin/adminconsole cache:warmup --env dev", - "@test install", "vendor/bin/phpstan analyze" ], "php-cs": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", diff --git a/phpstan.neon b/phpstan.neon index dafdfa20..f315c6d8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -22,8 +22,6 @@ parameters: console_application_loader: Tests/phpstan/console-application.php doctrine: objectManagerLoader: Tests/phpstan/object-manager.php - bootstrapFiles: - - vendor/bin/.phpunit/phpunit-8.5-0/vendor/autoload.php ignoreErrors: - message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Sulu\\\\Structure\\\\ContentDocument\\:\\:getStructure\\(\\) should return Sulu\\\\Component\\\\Content\\\\Document\\\\Structure\\\\StructureInterface but returns null\\.$#" count: 1 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a936430b..3343ae0d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,7 +27,7 @@ - src + . From e98d7fdf4f581c89e2fc23b999dd83e56c291a23 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 16 Mar 2023 00:18:40 +0100 Subject: [PATCH 6/9] Add more Generic for better Typing --- .../ContentCopier/ContentCopierInterface.php | 18 +++++++++++ .../ContentDataMapperInterface.php | 4 +++ .../DataMapper/DataMapperInterface.php | 4 +++ .../DataMapper/ExcerptDataMapper.php | 2 +- .../DataMapper/RoutableDataMapper.php | 5 +-- .../DataMapper/SeoDataMapper.php | 2 +- .../DataMapper/TemplateDataMapper.php | 5 ++- .../DataMapper/WorkflowDataMapper.php | 1 + .../ContentIndexer/ContentIndexer.php | 5 +++ .../ContentIndexerInterface.php | 17 +++++++++- .../ContentManagerInterface.php | 32 ++++++++++++++++++- .../ContentMerger/ContentMergerInterface.php | 7 ++++ .../ContentMerger/Merger/ExcerptMerger.php | 4 +-- .../ContentMetadataInspector.php | 10 +++++- .../ContentMetadataInspectorInterface.php | 10 ++++-- .../Normalizer/TemplateNormalizer.php | 2 +- .../ContentPersisterInterface.php | 5 +++ .../ContentResolverInterface.php | 5 +++ .../ContentWorkflowInterface.php | 5 +++ .../DimensionContentCollectionFactory.php | 7 +++- .../Exception/ContentNotFoundException.php | 6 +++- ...nsionContentCollectionFactoryInterface.php | 6 ++++ .../Model/ContentRichEntityInterface.php | 14 +++++++- .../Model/DimensionContentInterface.php | 6 ++++ Content/Domain/Model/ExcerptInterface.php | 2 +- Content/Domain/Model/RoutableInterface.php | 2 +- .../DimensionContentRepositoryInterface.php | 6 ++++ .../ExampleTestBundle/Entity/Example.php | 3 ++ .../Entity/ExampleDimensionContent.php | 3 ++ 29 files changed, 179 insertions(+), 19 deletions(-) diff --git a/Content/Application/ContentCopier/ContentCopierInterface.php b/Content/Application/ContentCopier/ContentCopierInterface.php index 192d922c..287b6db3 100644 --- a/Content/Application/ContentCopier/ContentCopierInterface.php +++ b/Content/Application/ContentCopier/ContentCopierInterface.php @@ -20,8 +20,14 @@ interface ContentCopierInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $sourceContentRichEntity * @param mixed[] $sourceDimensionAttributes + * @param ContentRichEntityInterface $targetContentRichEntity * @param mixed[] $targetDimensionAttributes + * + * @return T */ public function copy( ContentRichEntityInterface $sourceContentRichEntity, @@ -31,7 +37,13 @@ public function copy( ): DimensionContentInterface; /** + * @template T of DimensionContentInterface + * + * @param DimensionContentCollectionInterface $dimensionContentCollection + * @param ContentRichEntityInterface $targetContentRichEntity * @param mixed[] $targetDimensionAttributes + * + * @return T */ public function copyFromDimensionContentCollection( DimensionContentCollectionInterface $dimensionContentCollection, @@ -40,7 +52,13 @@ public function copyFromDimensionContentCollection( ): DimensionContentInterface; /** + * @template T of DimensionContentInterface + * + * @param T $dimensionContent + * @param ContentRichEntityInterface $targetContentRichEntity * @param mixed[] $targetDimensionAttributes + * + * @return T */ public function copyFromDimensionContent( DimensionContentInterface $dimensionContent, diff --git a/Content/Application/ContentDataMapper/ContentDataMapperInterface.php b/Content/Application/ContentDataMapper/ContentDataMapperInterface.php index 4f7db9c7..5d395c4b 100644 --- a/Content/Application/ContentDataMapper/ContentDataMapperInterface.php +++ b/Content/Application/ContentDataMapper/ContentDataMapperInterface.php @@ -14,11 +14,15 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; interface ContentDataMapperInterface { /** + * @template T of DimensionContentInterface + * * @param array $data + * @param DimensionContentCollectionInterface $dimensionContentCollection */ public function map( array $data, diff --git a/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php b/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php index 0b732abc..9f7bc32a 100644 --- a/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php +++ b/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php @@ -14,11 +14,15 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; interface DataMapperInterface { /** + * @template T of DimensionContentInterface + * * @param array $data + * @param DimensionContentCollectionInterface $dimensionContentCollection */ public function map( array $data, diff --git a/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php index ea6d52eb..4d186dec 100644 --- a/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php @@ -68,7 +68,7 @@ public function map( */ private function setExcerptData(ExcerptInterface $dimensionContent, array $data): void { - $dimensionContent->setExcerptTitle($data['excerptTitle'] ?? null); + $dimensionContent->setExcerptTitle($data['excerptTitle'] ?? null); // @phpstan-ignore-line TODO where validate this? $dimensionContent->setExcerptDescription($data['excerptDescription'] ?? null); $dimensionContent->setExcerptMore($data['excerptMore'] ?? null); $dimensionContent->setExcerptImage($data['excerptImage'] ?? null); diff --git a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php index db36c749..c367953c 100644 --- a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php @@ -151,9 +151,10 @@ public function map( return; // @codeCoverageIgnore } - $routePath = $data[$name] ?? null; + /** @var string $routePath */ + $routePath = $data[$name] ?? ''; if (!$routePath) { - /** @var mixed $routeGenerationData */ + /** @var mixed[] $routeGenerationData */ $routeGenerationData = \array_merge( $data, [ diff --git a/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php index 53a2165f..f77e2ec2 100644 --- a/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php @@ -50,7 +50,7 @@ public function map( */ private function setSeoData(SeoInterface $dimensionContent, array $data): void { - $dimensionContent->setSeoTitle($data['seoTitle'] ?? null); + $dimensionContent->setSeoTitle($data['seoTitle'] ?? null); // @phpstan-ignore-line TODO where validate this? $dimensionContent->setSeoDescription($data['seoDescription'] ?? null); $dimensionContent->setSeoKeywords($data['seoKeywords'] ?? null); $dimensionContent->setSeoCanonicalUrl($data['seoCanonicalUrl'] ?? null); diff --git a/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php index 040b3e11..a5efcde9 100644 --- a/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php @@ -95,7 +95,10 @@ public function map( /** * @param mixed[] $data * - * @return mixed[] + * @return array{ + * 0: mixed[], + * 1: mixed[], + * } */ private function getTemplateData(array $data, string $type, string $template): array { diff --git a/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php index 36cffc34..30d613de 100644 --- a/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php @@ -88,6 +88,7 @@ private function setPublishedToLiveDimension(WorkflowInterface $object, array $d return; } + /** @var string|null $published */ $published = $data['published'] ?? null; if (!$published) { diff --git a/Content/Application/ContentIndexer/ContentIndexer.php b/Content/Application/ContentIndexer/ContentIndexer.php index e22c73cf..a7087b4e 100644 --- a/Content/Application/ContentIndexer/ContentIndexer.php +++ b/Content/Application/ContentIndexer/ContentIndexer.php @@ -91,7 +91,12 @@ public function deindexDimensionContent(DimensionContentInterface $dimensionCont } /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ private function loadDimensionContent( ContentRichEntityInterface $contentRichEntity, diff --git a/Content/Application/ContentIndexer/ContentIndexerInterface.php b/Content/Application/ContentIndexer/ContentIndexerInterface.php index 07693401..1a3c3152 100644 --- a/Content/Application/ContentIndexer/ContentIndexerInterface.php +++ b/Content/Application/ContentIndexer/ContentIndexerInterface.php @@ -19,17 +19,32 @@ interface ContentIndexerInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ public function index(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface; + /** + * @template T of DimensionContentInterface + * + * @param T $dimensionContent + */ public function indexDimensionContent(DimensionContentInterface $dimensionContent): void; /** - * @param mixed $id + * @param int|string $id * @param mixed[] $dimensionAttributes */ public function deindex(string $resourceKey, $id, array $dimensionAttributes = []): void; + /** + * @template T of DimensionContentInterface + * + * @param T $dimensionContent + */ public function deindexDimensionContent(DimensionContentInterface $dimensionContent): void; } diff --git a/Content/Application/ContentManager/ContentManagerInterface.php b/Content/Application/ContentManager/ContentManagerInterface.php index f40bb01b..100eb1c5 100644 --- a/Content/Application/ContentManager/ContentManagerInterface.php +++ b/Content/Application/ContentManager/ContentManagerInterface.php @@ -19,24 +19,44 @@ interface ContentManagerInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ public function resolve(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface; /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $data * @param mixed[] $dimensionAttributes + * + * @return T */ public function persist(ContentRichEntityInterface $contentRichEntity, array $data, array $dimensionAttributes): DimensionContentInterface; /** + * @template T of DimensionContentInterface + * + * @param T $dimensionContent + * * @return mixed[] */ public function normalize(DimensionContentInterface $dimensionContent): array; /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $sourceContentRichEntity * @param mixed[] $sourceDimensionAttributes + * @param ContentRichEntityInterface $targetContentRichEntity * @param mixed[] $targetDimensionAttributes + * + * @return T */ public function copy( ContentRichEntityInterface $sourceContentRichEntity, @@ -46,7 +66,12 @@ public function copy( ): DimensionContentInterface; /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ public function applyTransition( ContentRichEntityInterface $contentRichEntity, @@ -55,12 +80,17 @@ public function applyTransition( ): DimensionContentInterface; /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ public function index(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface; /** - * @param mixed $id + * @param int|string $id * @param mixed[] $dimensionAttributes */ public function deindex(string $resourceKey, $id, array $dimensionAttributes = []): void; diff --git a/Content/Application/ContentMerger/ContentMergerInterface.php b/Content/Application/ContentMerger/ContentMergerInterface.php index bc2e878a..0ece708a 100644 --- a/Content/Application/ContentMerger/ContentMergerInterface.php +++ b/Content/Application/ContentMerger/ContentMergerInterface.php @@ -18,5 +18,12 @@ interface ContentMergerInterface { + /** + * @template T of DimensionContentInterface + * + * @param DimensionContentCollectionInterface $dimensionContentCollection + * + * @return T + */ public function merge(DimensionContentCollectionInterface $dimensionContentCollection): DimensionContentInterface; } diff --git a/Content/Application/ContentMerger/Merger/ExcerptMerger.php b/Content/Application/ContentMerger/Merger/ExcerptMerger.php index 3dcd28a8..068f431b 100644 --- a/Content/Application/ContentMerger/Merger/ExcerptMerger.php +++ b/Content/Application/ContentMerger/Merger/ExcerptMerger.php @@ -48,13 +48,13 @@ public function merge(object $targetObject, object $sourceObject): void } if ($excerptTags = $sourceObject->getExcerptTags()) { - if (!empty($excerptTags)) { + if (count($excerptTags) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array $targetObject->setExcerptTags($excerptTags); } } if ($excerptCategories = $sourceObject->getExcerptCategories()) { - if (!empty($excerptCategories)) { + if (count($excerptCategories) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array $targetObject->setExcerptCategories($excerptCategories); } } diff --git a/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php b/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php index e7b23ab4..4150cdcd 100644 --- a/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php +++ b/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php @@ -14,6 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector; use Doctrine\ORM\EntityManagerInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; class ContentMetadataInspector implements ContentMetadataInspectorInterface @@ -28,10 +29,17 @@ public function __construct(EntityManagerInterface $entityManager) $this->entityManager = $entityManager; } + /** + * @template T of DimensionContentInterface + * + * @param class-string> $contentRichEntityClass + * + * @return class-string + */ public function getDimensionContentClass(string $contentRichEntityClass): string { $classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass); - /** @var array{targetEntity: class-string} $associationMapping */ + /** @var array{targetEntity: class-string} $associationMapping */ $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); return $associationMapping['targetEntity']; diff --git a/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php b/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php index d9f6521b..27fa7e18 100644 --- a/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php +++ b/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php @@ -19,14 +19,18 @@ interface ContentMetadataInspectorInterface { /** - * @param class-string $contentRichEntityClass + * @template T of DimensionContentInterface * - * @return class-string + * @param class-string> $contentRichEntityClass + * + * @return class-string */ public function getDimensionContentClass(string $contentRichEntityClass): string; /** - * @param class-string $contentRichEntityClass + * @template T of DimensionContentInterface + * + * @param class-string> $contentRichEntityClass */ public function getDimensionContentPropertyName(string $contentRichEntityClass): string; } diff --git a/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php b/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php index 6497099f..9b1963cb 100644 --- a/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php +++ b/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php @@ -23,7 +23,7 @@ public function enhance(object $object, array $normalizedData): array return $normalizedData; } - $normalizedData = \array_merge($normalizedData['templateData'], $normalizedData); + $normalizedData = \array_merge($normalizedData['templateData'], $normalizedData); // @phpstan-ignore-line TODO check whats going on here unset($normalizedData['templateData']); $normalizedData['template'] = $normalizedData['templateKey']; diff --git a/Content/Application/ContentPersister/ContentPersisterInterface.php b/Content/Application/ContentPersister/ContentPersisterInterface.php index 0cfea457..baf11bc5 100644 --- a/Content/Application/ContentPersister/ContentPersisterInterface.php +++ b/Content/Application/ContentPersister/ContentPersisterInterface.php @@ -19,8 +19,13 @@ interface ContentPersisterInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $data * @param mixed[] $dimensionAttributes + * + * @return T */ public function persist(ContentRichEntityInterface $contentRichEntity, array $data, array $dimensionAttributes): DimensionContentInterface; } diff --git a/Content/Application/ContentResolver/ContentResolverInterface.php b/Content/Application/ContentResolver/ContentResolverInterface.php index 280af02b..5f7ffdf6 100644 --- a/Content/Application/ContentResolver/ContentResolverInterface.php +++ b/Content/Application/ContentResolver/ContentResolverInterface.php @@ -19,7 +19,12 @@ interface ContentResolverInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ public function resolve(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface; } diff --git a/Content/Application/ContentWorkflow/ContentWorkflowInterface.php b/Content/Application/ContentWorkflow/ContentWorkflowInterface.php index 8f8dda97..e1919819 100644 --- a/Content/Application/ContentWorkflow/ContentWorkflowInterface.php +++ b/Content/Application/ContentWorkflow/ContentWorkflowInterface.php @@ -23,7 +23,12 @@ interface ContentWorkflowInterface public const DIMENSION_ATTRIBUTES_CONTEXT_KEY = 'dimensionAttributes'; /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return T */ public function apply( ContentRichEntityInterface $contentRichEntity, diff --git a/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php b/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php index d9dd7f81..0f2df5d0 100644 --- a/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php +++ b/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php @@ -105,8 +105,13 @@ public function create( } /** - * @param Collection $dimensionContents + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity + * @param Collection $dimensionContents * @param mixed[] $attributes + * + * @return T */ private function createContentDimension( ContentRichEntityInterface $contentRichEntity, diff --git a/Content/Domain/Exception/ContentNotFoundException.php b/Content/Domain/Exception/ContentNotFoundException.php index b5bba848..9fa4ebb9 100644 --- a/Content/Domain/Exception/ContentNotFoundException.php +++ b/Content/Domain/Exception/ContentNotFoundException.php @@ -14,11 +14,15 @@ namespace Sulu\Bundle\ContentBundle\Content\Domain\Exception; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; class ContentNotFoundException extends \Exception { /** - * @param array $dimensionAttributes + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity + * @param mixed[] $dimensionAttributes */ public function __construct(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes) { diff --git a/Content/Domain/Factory/DimensionContentCollectionFactoryInterface.php b/Content/Domain/Factory/DimensionContentCollectionFactoryInterface.php index 91b52620..80b119f9 100644 --- a/Content/Domain/Factory/DimensionContentCollectionFactoryInterface.php +++ b/Content/Domain/Factory/DimensionContentCollectionFactoryInterface.php @@ -15,12 +15,18 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; interface DimensionContentCollectionFactoryInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param array $data * @param mixed[] $dimensionAttributes + * + * @return DimensionContentCollectionInterface */ public function create( ContentRichEntityInterface $contentRichEntity, diff --git a/Content/Domain/Model/ContentRichEntityInterface.php b/Content/Domain/Model/ContentRichEntityInterface.php index 3a431f81..252e5eaa 100644 --- a/Content/Domain/Model/ContentRichEntityInterface.php +++ b/Content/Domain/Model/ContentRichEntityInterface.php @@ -15,6 +15,9 @@ use Doctrine\Common\Collections\Collection; +/** + * @template T of DimensionContentInterface + */ interface ContentRichEntityInterface { /** @@ -23,13 +26,22 @@ interface ContentRichEntityInterface public function getId(); /** - * @return Collection + * @return Collection */ public function getDimensionContents(): Collection; + /** + * @return T + */ public function createDimensionContent(): DimensionContentInterface; + /** + * @param T $dimensionContent + */ public function addDimensionContent(DimensionContentInterface $dimensionContent): void; + /** + * @param T $dimensionContent + */ public function removeDimensionContent(DimensionContentInterface $dimensionContent): void; } diff --git a/Content/Domain/Model/DimensionContentInterface.php b/Content/Domain/Model/DimensionContentInterface.php index 8e1eebe4..7d6fea1b 100644 --- a/Content/Domain/Model/DimensionContentInterface.php +++ b/Content/Domain/Model/DimensionContentInterface.php @@ -13,6 +13,9 @@ namespace Sulu\Bundle\ContentBundle\Content\Domain\Model; +/** + * @template T of ContentRichEntityInterface + */ interface DimensionContentInterface { public const STAGE_DRAFT = 'draft'; @@ -28,6 +31,9 @@ public function getStage(): string; public function setStage(string $stage): void; + /** + * @return T + */ public function getResource(): ContentRichEntityInterface; public function isMerged(): bool; diff --git a/Content/Domain/Model/ExcerptInterface.php b/Content/Domain/Model/ExcerptInterface.php index 9f6e2862..99f0fe58 100644 --- a/Content/Domain/Model/ExcerptInterface.php +++ b/Content/Domain/Model/ExcerptInterface.php @@ -28,7 +28,7 @@ public function setExcerptMore(?string $excerptMore): void; public function getExcerptDescription(): ?string; - public function setExcerptDescription(?string $excerptTitle): void; + public function setExcerptDescription(?string $excerptDescription): void; /** * @return CategoryInterface[] diff --git a/Content/Domain/Model/RoutableInterface.php b/Content/Domain/Model/RoutableInterface.php index fc9d7099..a37ce3b8 100644 --- a/Content/Domain/Model/RoutableInterface.php +++ b/Content/Domain/Model/RoutableInterface.php @@ -21,7 +21,7 @@ interface RoutableInterface public static function getResourceKey(): string; /** - * @return mixed + * @return int|string */ public function getResourceId(); diff --git a/Content/Domain/Repository/DimensionContentRepositoryInterface.php b/Content/Domain/Repository/DimensionContentRepositoryInterface.php index e31e9d51..b0f8743c 100644 --- a/Content/Domain/Repository/DimensionContentRepositoryInterface.php +++ b/Content/Domain/Repository/DimensionContentRepositoryInterface.php @@ -15,11 +15,17 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; interface DimensionContentRepositoryInterface { /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity * @param mixed[] $dimensionAttributes + * + * @return DimensionContentCollectionInterface */ public function load( ContentRichEntityInterface $contentRichEntity, diff --git a/Tests/Application/ExampleTestBundle/Entity/Example.php b/Tests/Application/ExampleTestBundle/Entity/Example.php index 9c897837..bc029a77 100644 --- a/Tests/Application/ExampleTestBundle/Entity/Example.php +++ b/Tests/Application/ExampleTestBundle/Entity/Example.php @@ -17,6 +17,9 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityTrait; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; +/** + * @implements ContentRichEntityInterface + */ class Example implements ContentRichEntityInterface { use ContentRichEntityTrait; diff --git a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php index 6a59a41e..de5f5630 100644 --- a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php +++ b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php @@ -27,6 +27,9 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowTrait; +/** + * @implements DimensionContentInterface + */ class ExampleDimensionContent implements DimensionContentInterface, ExcerptInterface, SeoInterface, TemplateInterface, RoutableInterface, WorkflowInterface { use DimensionContentTrait; From 1bbea77a689a3f18dfde6090750fd5cf6f87bb6f Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 16 Mar 2023 01:30:37 +0100 Subject: [PATCH 7/9] Define more generics --- .../Doctrine/DimensionContentRepository.php | 14 +++- .../Doctrine/MetadataLoader.php | 4 +- .../ContentViewBuilderFactoryInterface.php | 9 ++- .../Automation/ContentPublishTaskHandler.php | 12 +++- .../ContentUnpublishTaskHandler.php | 12 +++- .../Sulu/Preview/ContentObjectProvider.php | 34 ++++++---- .../PreviewDimensionContentCollection.php | 10 ++- .../Route/ContentRouteDefaultsProvider.php | 18 +++++- .../Sulu/Search/ContentReindexProvider.php | 14 ++-- .../Search/ContentSearchMetadataProvider.php | 14 ++-- .../Sulu/Sitemap/ContentSitemapProvider.php | 17 +++-- .../SmartContent/DataItem/ContentDataItem.php | 8 ++- .../Provider/ContentDataProvider.php | 23 ++++++- .../ContentDataProviderRepository.php | 64 +++++++++++++++---- .../Sulu/Teaser/ContentTeaserProvider.php | 25 ++++++-- 15 files changed, 216 insertions(+), 62 deletions(-) diff --git a/Content/Infrastructure/Doctrine/DimensionContentRepository.php b/Content/Infrastructure/Doctrine/DimensionContentRepository.php index ff658f60..3423aa41 100644 --- a/Content/Infrastructure/Doctrine/DimensionContentRepository.php +++ b/Content/Infrastructure/Doctrine/DimensionContentRepository.php @@ -43,6 +43,14 @@ public function __construct( $this->contentMetadataInspector = $contentMetadataInspector; } + /** + * @template T of DimensionContentInterface + * + * @param ContentRichEntityInterface $contentRichEntity + * @param mixed[] $dimensionAttributes + * + * @return DimensionContentCollectionInterface + */ public function load( ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes @@ -61,7 +69,7 @@ public function load( $queryBuilder->addCriteria($this->getAttributesCriteria('dimensionContent', $effectiveAttributes)); $this->addSortBy($queryBuilder, $effectiveAttributes); - /** @var DimensionContentInterface[] $dimensionContents */ + /** @var T[] $dimensionContents */ $dimensionContents = $queryBuilder->getQuery()->getResult(); return new DimensionContentCollection( @@ -106,7 +114,9 @@ private function getAttributesCriteria(string $alias, array $attributes): Criter } /** - * @param class-string $className + * @template T of ContentRichEntityInterface + * + * @param class-string> $className * @param mixed[] $attributes * * @return mixed[] diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index 5e41621e..7edd187c 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -112,8 +112,9 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void * @codeCoverageIgnore * * @param ClassMetadataInfo $metadata + * @param class-string $class */ - private function addManyToOne( + private function addManyToOne( // @phpstan-ignore-line ignore unused method LoadClassMetadataEventArgs $event, ClassMetadataInfo $metadata, string $name, @@ -143,6 +144,7 @@ private function addManyToOne( /** * @param ClassMetadataInfo $metadata + * @param class-string $class */ private function addManyToMany( LoadClassMetadataEventArgs $event, diff --git a/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryInterface.php b/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryInterface.php index 200049b4..622da7e0 100644 --- a/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryInterface.php +++ b/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryInterface.php @@ -16,11 +16,14 @@ use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction; use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; interface ContentViewBuilderFactoryInterface { /** - * @param class-string $contentRichEntityClass + * @template T of DimensionContentInterface + * + * @param class-string> $contentRichEntityClass * * @return array */ @@ -29,7 +32,9 @@ public function getDefaultToolbarActions( ): array; /** - * @param class-string $contentRichEntityClass + * @template T of DimensionContentInterface + * + * @param class-string> $contentRichEntityClass * @param array $toolbarActions * * @return ViewBuilderInterface[] diff --git a/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandler.php b/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandler.php index e2e6bf31..89f8ece0 100644 --- a/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandler.php +++ b/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandler.php @@ -18,6 +18,7 @@ use Sulu\Bundle\AutomationBundle\TaskHandler\TaskHandlerConfiguration; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Contracts\Translation\TranslatorInterface; @@ -63,6 +64,15 @@ public function getConfiguration(): TaskHandlerConfiguration return TaskHandlerConfiguration::create($this->translator->trans('sulu_content.task_handler.publish', [], 'admin')); } + /** + * @template T of DimensionContentInterface + * + * @param array{ + * class: class-string>, + * id: int|string, + * locale: string, + * } $workload + */ public function handle($workload) { if (!\is_array($workload)) { @@ -70,11 +80,9 @@ public function handle($workload) return; // @codeCoverageIgnore } - /** @var class-string $class */ $class = $workload['class']; $repository = $this->entityManager->getRepository($class); - /** @var ContentRichEntityInterface|null $entity */ $entity = $repository->findOneBy(['id' => $workload['id']]); if (null === $entity) { // TODO FIXME add test case for this diff --git a/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandler.php b/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandler.php index 39dc24b0..9e8f025f 100644 --- a/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandler.php +++ b/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandler.php @@ -18,6 +18,7 @@ use Sulu\Bundle\AutomationBundle\TaskHandler\TaskHandlerConfiguration; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Contracts\Translation\TranslatorInterface; @@ -63,6 +64,15 @@ public function getConfiguration(): TaskHandlerConfiguration return TaskHandlerConfiguration::create($this->translator->trans('sulu_content.task_handler.unpublish', [], 'admin')); } + /** + * @template T of DimensionContentInterface + * + * @param array{ + * class: class-string>, + * id: int|string, + * locale: string, + * } $workload + */ public function handle($workload) { if (!\is_array($workload)) { @@ -70,11 +80,9 @@ public function handle($workload) return; // @codeCoverageIgnore } - /** @var class-string $class */ $class = $workload['class']; $repository = $this->entityManager->getRepository($class); - /** @var ContentRichEntityInterface|null $entity */ $entity = $repository->findOneBy(['id' => $workload['id']]); if (null === $entity) { // TODO FIXME add test case for this diff --git a/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php b/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php index 2a04fd1b..826cc888 100644 --- a/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php +++ b/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php @@ -23,6 +23,10 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; use Sulu\Bundle\PreviewBundle\Preview\Object\PreviewObjectProviderInterface; +/** + * @template B of DimensionContentInterface + * @template T of ContentRichEntityInterface + */ class ContentObjectProvider implements PreviewObjectProviderInterface { /** @@ -41,7 +45,7 @@ class ContentObjectProvider implements PreviewObjectProviderInterface private $contentDataMapper; /** - * @var class-string + * @var class-string */ private $contentRichEntityClass; @@ -51,7 +55,7 @@ class ContentObjectProvider implements PreviewObjectProviderInterface private $securityContext; /** - * @param class-string $contentRichEntityClass + * @param class-string $contentRichEntityClass */ public function __construct( EntityManagerInterface $entityManager, @@ -68,15 +72,15 @@ public function __construct( } /** - * @param string $id + * @param string|int $id * @param string $locale * - * @return DimensionContentInterface|null + * @return B|null */ public function getObject($id, $locale) { try { - /** @var ContentRichEntityInterface $contentRichEntity */ + /** @var T $contentRichEntity */ $contentRichEntity = $this->entityManager->createQueryBuilder() ->select('entity') ->from($this->contentRichEntityClass, 'entity') @@ -92,9 +96,9 @@ public function getObject($id, $locale) } /** - * @param DimensionContentInterface $object + * @param B $object * - * @return string + * @return string|int */ public function getId($object) { @@ -102,7 +106,7 @@ public function getId($object) } /** - * @param DimensionContentInterface $object + * @param B $object * @param string $locale * @param mixed[] $data */ @@ -113,9 +117,11 @@ public function setValues($object, $locale, array $data): void } /** - * @param DimensionContentInterface $object + * @param B $object * @param string $locale * @param mixed[] $context + * + * @return B */ public function setContext($object, $locale, array $context): DimensionContentInterface { @@ -129,7 +135,7 @@ public function setContext($object, $locale, array $context): DimensionContentIn } /** - * @param DimensionContentInterface $object + * @param B $object * * @return string */ @@ -145,10 +151,11 @@ public function serialize($object) * @param string $serializedObject * @param string $objectClass * - * @return mixed + * @return B|null */ public function deserialize($serializedObject, $objectClass) { + /** @var array{id?: int|string, locale?: string} $data */ $data = \json_decode($serializedObject, true); $id = $data['id'] ?? null; @@ -166,6 +173,11 @@ public function getSecurityContext($id, $locale): ?string return $this->securityContext; } + /** + * @param T $contentRichEntity + * + * @return B|null + */ protected function resolveContent(ContentRichEntityInterface $contentRichEntity, string $locale): ?DimensionContentInterface { try { diff --git a/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollection.php b/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollection.php index 8bd06eb8..2594f56b 100644 --- a/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollection.php +++ b/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollection.php @@ -20,12 +20,15 @@ /** * @internal * - * @implements \IteratorAggregate + * @template-covariant T of DimensionContentInterface + * + * @implements DimensionContentCollectionInterface + * @implements \IteratorAggregate */ class PreviewDimensionContentCollection implements \IteratorAggregate, DimensionContentCollectionInterface { /** - * @var DimensionContentInterface + * @var T */ private $previewDimensionContent; @@ -34,6 +37,9 @@ class PreviewDimensionContentCollection implements \IteratorAggregate, Dimension */ private $previewLocale; + /** + * @param T $previewDimensionContent + */ public function __construct( DimensionContentInterface $previewDimensionContent, string $previewLocale diff --git a/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProvider.php b/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProvider.php index 528fc48e..7fc8206e 100644 --- a/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProvider.php +++ b/Content/Infrastructure/Sulu/Route/ContentRouteDefaultsProvider.php @@ -61,10 +61,12 @@ public function __construct( } /** - * @param string $entityClass + * @template T of DimensionContentInterface + * + * @param class-string> $entityClass * @param string $id * @param string $locale - * @param DimensionContentInterface|null $object + * @param T|null $object * * @return mixed[] */ @@ -96,6 +98,11 @@ public function getByEntity($entityClass, $id, $locale, $object = null) ]; } + /** + * @template T of DimensionContentInterface + * + * @param class-string> $entityClass + */ public function isPublished($entityClass, $id, $locale) { $entity = $this->loadEntity($entityClass, $id, $locale); @@ -114,10 +121,15 @@ public function supports($entityClass) || \is_a($entityClass, DimensionContentInterface::class, true); } + /** + * @template T of DimensionContentInterface + * + * @param class-string> $entityClass + */ protected function loadEntity(string $entityClass, string $id, string $locale): ?TemplateInterface { try { - /** @var ContentRichEntityInterface $contentRichEntity */ + /** @var ContentRichEntityInterface $contentRichEntity */ $contentRichEntity = $this->entityManager->createQueryBuilder() ->select('entity') ->from($entityClass, 'entity') diff --git a/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php b/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php index 8d08abcf..e1fba99a 100644 --- a/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php +++ b/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php @@ -23,6 +23,10 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; use Sulu\Component\HttpKernel\SuluKernel; +/** + * @template B of DimensionContentInterface + * @template T of ContentRichEntityInterface + */ class ContentReindexProvider implements LocalizedReindexProviderInterface { /** @@ -46,17 +50,17 @@ class ContentReindexProvider implements LocalizedReindexProviderInterface private $context; /** - * @var class-string + * @var class-string */ private $contentRichEntityClass; /** - * @var class-string|null + * @var class-string|null */ private $dimensionContentClass = null; /** - * @param class-string $contentRichEntityClass + * @param class-string $contentRichEntityClass */ public function __construct( EntityManagerInterface $entityManager, @@ -80,6 +84,7 @@ public function provide($classFqn, $offset, $maxResults) ->setFirstResult($offset) ->setMaxResults($maxResults); + /** @var array */ return $queryBuilder->getQuery()->execute(); } @@ -99,6 +104,7 @@ public function getCount($classFqn) ->from($this->contentRichEntityClass, 'contentRichEntity') ->select('COUNT(contentRichEntity)'); + /** @var int */ return $queryBuilder->getQuery()->getSingleScalarResult(); } @@ -178,7 +184,7 @@ private function getWorkflowStage(): string } /** - * @return class-string + * @return class-string */ private function getDimensionContentClass(): string { diff --git a/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php b/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php index 94d0448f..8c75b08b 100644 --- a/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php +++ b/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php @@ -31,6 +31,10 @@ use Sulu\Component\Content\Metadata\PropertyMetadata; use Sulu\Component\Content\Metadata\StructureMetadata; +/** + * @template B of DimensionContentInterface + * @template T of ContentRichEntityInterface + */ class ContentSearchMetadataProvider implements ProviderInterface { public const SEARCH_FIELD_TAG = 'sulu.search.field'; @@ -63,17 +67,17 @@ class ContentSearchMetadataProvider implements ProviderInterface private $structureFactory; /** - * @var class-string + * @var class-string */ private $contentRichEntityClass; /** - * @var class-string|null + * @var class-string|null */ private $dimensionContentClass = null; /** - * @param class-string $contentRichEntityClass + * @param class-string $contentRichEntityClass */ public function __construct( ContentMetadataInspectorInterface $contentMetadataInspector, @@ -170,7 +174,7 @@ private function getMetadata(string $className, StructureMetadata $structureMeta $indexMeta->setIdField($this->searchMetadataFactory->createMetadataField('resourceId')); $indexMeta->setLocaleField($this->searchMetadataFactory->createMetadataField('locale')); - /** @var class-string $dimensionContentClass */ + /** @var class-string $dimensionContentClass */ $dimensionContentClass = $this->getDimensionContentClass(); if (!\is_a($dimensionContentClass, DimensionContentInterface::class, true)) { @@ -372,7 +376,7 @@ private function mapProperty(PropertyMetadata $property, IndexMetadata $metadata } /** - * @return class-string + * @return class-string */ private function getDimensionContentClass(): string { diff --git a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php index 39e243a6..5e2cae28 100644 --- a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php +++ b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php @@ -30,6 +30,10 @@ use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; use Sulu\Component\Webspace\PortalInformation; +/** + * @template B of DimensionContentInterface + * @template T of ContentRichEntityInterface + */ class ContentSitemapProvider implements SitemapProviderInterface { public const ROUTE_ALIAS = 'route'; @@ -52,7 +56,7 @@ class ContentSitemapProvider implements SitemapProviderInterface protected $kernelEnvironment; /** - * @var class-string + * @var class-string */ protected $contentRichEntityClass; @@ -68,7 +72,7 @@ class ContentSitemapProvider implements SitemapProviderInterface /** * @param string $kernelEnvironment Inject parameter "kernel.environment" here - * @param class-string $contentRichEntityClass Classname that is used in the route table + * @param class-string $contentRichEntityClass Classname that is used in the route table * @param class-string $routeClass */ public function __construct( @@ -168,7 +172,7 @@ public function getMaxPage($scheme, $host): int /** * @param RouteInterface[] $routes * - * @return mixed[] + * @return array> */ protected function groupRoutesByEntityId(array $routes): array { @@ -188,7 +192,7 @@ protected function groupRoutesByEntityId(array $routes): array } /** - * @return mixed[] + * @return RouteInterface[] */ protected function getRoutes(int $limit, int $offset): array { @@ -201,9 +205,8 @@ protected function getRoutes(int $limit, int $offset): array ->setFirstResult($offset) ->setMaxResults($limit); - $result = $queryBuilder->getQuery()->getResult(); - - return $result; + /** @var RouteInterface[] */ + return $queryBuilder->getQuery()->getResult(); } protected function createRoutesQueryBuilder(): QueryBuilder diff --git a/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItem.php b/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItem.php index bd93e2ce..0ba2a7ff 100644 --- a/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItem.php +++ b/Content/Infrastructure/Sulu/SmartContent/DataItem/ContentDataItem.php @@ -21,11 +21,14 @@ use Sulu\Component\SmartContent\PublishInterface; /** + * @template T of DimensionContentInterface + * * @Serializer\ExclusionPolicy("all") */ class ContentDataItem extends ArrayAccessItem implements ItemInterface, PublishInterface { /** + * @param T $dimensionContent * @param mixed[] $data */ public function __construct(DimensionContentInterface $dimensionContent, array $data) @@ -101,9 +104,12 @@ public function getPublishedState(): bool return WorkflowInterface::WORKFLOW_PLACE_PUBLISHED === $dimensionContent->getWorkflowPlace(); } + /** + * @return T + */ protected function getDimensionContent(): DimensionContentInterface { - /** @var DimensionContentInterface $dimensionContent */ + /** @var T $dimensionContent */ $dimensionContent = $this->getResource(); return $dimensionContent; diff --git a/Content/Infrastructure/Sulu/SmartContent/Provider/ContentDataProvider.php b/Content/Infrastructure/Sulu/SmartContent/Provider/ContentDataProvider.php index d4f8cc10..21108c3e 100644 --- a/Content/Infrastructure/Sulu/SmartContent/Provider/ContentDataProvider.php +++ b/Content/Infrastructure/Sulu/SmartContent/Provider/ContentDataProvider.php @@ -71,7 +71,9 @@ protected function configure(BuilderInterface $builder): void } /** - * @param DimensionContentInterface[] $data + * @template T of DimensionContentInterface + * + * @param T[] $data * * @return mixed[] */ @@ -90,7 +92,9 @@ function(DimensionContentInterface $dimensionContent) { /** * Decorates result as resource item. * - * @param DimensionContentInterface[] $data + * @template T of DimensionContentInterface + * + * @param T[] $data * @param string $locale * * @return ResourceItemInterface[] @@ -113,7 +117,9 @@ function(DimensionContentInterface $dimensionContent) { } /** - * @param DimensionContentInterface $dimensionContent + * @template T of DimensionContentInterface + * + * @param T $dimensionContent * * @return mixed */ @@ -123,6 +129,10 @@ protected function getIdForItem($dimensionContent) } /** + * @template T of DimensionContentInterface + * + * @param T $dimensionContent + * * @return mixed[] */ protected function normalizeContent(DimensionContentInterface $dimensionContent): array @@ -131,6 +141,10 @@ protected function normalizeContent(DimensionContentInterface $dimensionContent) } /** + * @template T of DimensionContentInterface + * + * @param T $dimensionContent + * * @param mixed[] $data */ protected function createDataItem(DimensionContentInterface $dimensionContent, array $data): ItemInterface @@ -139,7 +153,10 @@ protected function createDataItem(DimensionContentInterface $dimensionContent, a } /** + * @template T of DimensionContentInterface + * * @param mixed $id + * @param T $dimensionContent * @param mixed[] $data */ protected function createResourceItem($id, DimensionContentInterface $dimensionContent, array $data): ResourceItemInterface diff --git a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php index 82db7339..bed9ab71 100644 --- a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php +++ b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php @@ -21,6 +21,10 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Component\SmartContent\Orm\DataProviderRepositoryInterface; +/** + * @template B of DimensionContentInterface + * @template T of ContentRichEntityInterface + */ class ContentDataProviderRepository implements DataProviderRepositoryInterface { public const CONTENT_RICH_ENTITY_ALIAS = 'entity'; @@ -42,18 +46,18 @@ class ContentDataProviderRepository implements DataProviderRepositoryInterface protected $showDrafts; /** - * @var class-string + * @var class-string */ protected $contentRichEntityClass; /** - * @var ClassMetadata + * @var ClassMetadata */ protected $contentRichEntityClassMetadata; /** * @param bool $showDrafts Inject parameter "sulu_document_manager.show_drafts" here - * @param class-string $contentRichEntityClass + * @param class-string $contentRichEntityClass */ public function __construct( ContentManagerInterface $contentManager, @@ -66,20 +70,35 @@ public function __construct( $this->showDrafts = $showDrafts; $this->contentRichEntityClass = $contentRichEntityClass; - /** @var ClassMetadata $contentRichEntityClassMetadata */ + /** @var ClassMetadata $contentRichEntityClassMetadata */ $contentRichEntityClassMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); $this->contentRichEntityClassMetadata = $contentRichEntityClassMetadata; } /** - * @param array $filters - * @param mixed|null $page - * @param mixed|null $pageSize - * @param mixed|null $limit + * @param array{ + * categories?: int[], + * categoryOperator?: 'AND'|'OR', + * websiteCategories?: int[], + * websiteCategoriesOperator?: 'AND'|'OR', + * tags?: string[], + * tagOperator?: 'AND'|'OR', + * websiteTags?: string[], + * websiteTagsOperator?: 'AND'|'OR', + * types?: string[], + * targetGroupId?: int, + * dataSource?: string|int, + * includeSubFolders?: bool, + * sortBy?: string, + * sortMethod?: 'asc'|'desc', + * } $filters + * @param int|null $page + * @param int|null $pageSize + * @param int|null $limit * @param string $locale * @param array $options * - * @return DimensionContentInterface[] + * @return B[] */ public function findByFilters($filters, $page, $pageSize, $limit, $locale, $options = []): array { @@ -93,6 +112,7 @@ public function findByFilters($filters, $page, $pageSize, $limit, $locale, $opti $showUnpublished = $this->showDrafts; + /** @var B[] */ return \array_filter( \array_map( function(ContentRichEntityInterface $contentRichEntity) use ($locale, $showUnpublished) { @@ -118,10 +138,27 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale, $showUnpub } /** - * @param array $filters + * TODO check "tagOperator"|"tagsOperator" vs "websiteTagOperator"|"websiteTagsOperator" + * + * @param array{ + * categories?: int[], + * categoryOperator?: 'AND'|'OR', + * websiteCategories?: int[], + * websiteCategoriesOperator?: 'AND'|'OR', + * tags?: string[], + * tagOperator?: 'AND'|'OR', + * websiteTags?: string[], + * websiteTagsOperator?: 'AND'|'OR', + * types?: string[], + * targetGroupId?: int, + * dataSource?: string|int, + * includeSubFolders?: bool, + * sortBy?: string, + * sortMethod?: 'asc'|'desc', + * } $filters * @param array $options * - * @return mixed[] entity ids + * @return array entity ids */ protected function findEntityIdsByFilters( array $filters, @@ -470,14 +507,15 @@ protected function createEntityIdsQueryBuilder(string $locale): QueryBuilder } /** - * @param mixed[] $ids + * @param array $ids * - * @return ContentRichEntityInterface[] + * @return T[] */ protected function findEntitiesByIds(array $ids): array { $entityIdentifierFieldName = $this->getEntityIdentifierFieldName(); + /** @var T[] $entities */ $entities = $this->entityManager->createQueryBuilder() ->select(self::CONTENT_RICH_ENTITY_ALIAS) ->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS) diff --git a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php index dab6b98b..6e45b4f3 100644 --- a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php +++ b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php @@ -26,6 +26,10 @@ use Sulu\Bundle\PageBundle\Teaser\Teaser; use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface; +/** + * @template B of DimensionContentInterface + * @template T of ContentRichEntityInterface + */ abstract class ContentTeaserProvider implements TeaserProviderInterface { public const CONTENT_RICH_ENTITY_ALIAS = ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY; @@ -51,7 +55,7 @@ abstract class ContentTeaserProvider implements TeaserProviderInterface protected $metadataFactory; /** - * @var class-string + * @var class-string */ protected $contentRichEntityClass; @@ -61,7 +65,7 @@ abstract class ContentTeaserProvider implements TeaserProviderInterface protected $showDrafts; /** - * @param class-string $contentRichEntityClass + * @param class-string $contentRichEntityClass * @param bool $showDrafts Inject parameter "sulu_document_manager.show_drafts" here */ public function __construct( @@ -115,6 +119,8 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale): ?Teaser { } /** + * @param B $dimensionContent + * * @param array $data */ protected function createTeaser(DimensionContentInterface $dimensionContent, array $data, string $locale): ?Teaser @@ -150,6 +156,11 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr ); } + /** + * @param T $contentRichEntity + * + * @return B|null + */ protected function resolveContent(ContentRichEntityInterface $contentRichEntity, string $locale): ?DimensionContentInterface { $stage = $this->showDrafts @@ -174,6 +185,7 @@ protected function resolveContent(ContentRichEntityInterface $contentRichEntity, } /** + * @param B $dimensionContent * @param mixed[] $data */ protected function getUrl(DimensionContentInterface $dimensionContent, array $data): ?string @@ -203,6 +215,7 @@ protected function getUrl(DimensionContentInterface $dimensionContent, array $da } /** + * @param B $dimensionContent * @param mixed[] $data */ protected function getTitle(DimensionContentInterface $dimensionContent, array $data): ?string @@ -217,6 +230,7 @@ protected function getTitle(DimensionContentInterface $dimensionContent, array $ } /** + * @param B $dimensionContent * @param array{description?: string|null} $data */ protected function getDescription(DimensionContentInterface $dimensionContent, array $data): ?string @@ -231,6 +245,7 @@ protected function getDescription(DimensionContentInterface $dimensionContent, a } /** + * @param B $dimensionContent * @param array{more?: string|null, moreText?: string|null} $data */ protected function getMoreText(DimensionContentInterface $dimensionContent, array $data): ?string @@ -245,6 +260,7 @@ protected function getMoreText(DimensionContentInterface $dimensionContent, arra } /** + * @param B $dimensionContent * @param mixed[] $data */ protected function getMediaId(DimensionContentInterface $dimensionContent, array $data): ?int @@ -260,6 +276,7 @@ protected function getMediaId(DimensionContentInterface $dimensionContent, array } /** + * @param B $dimensionContent * @param mixed[] $data * * @return mixed[] @@ -272,14 +289,14 @@ protected function getAttributes(DimensionContentInterface $dimensionContent, ar /** * @param array $ids * - * @return ContentRichEntityInterface[] + * @return T[] */ protected function findEntitiesByIds(array $ids): array { $entityIdField = $this->getEntityIdField(); $classMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); - /** @var ContentRichEntityInterface[] $entities */ + /** @var T[] $entities */ $entities = $this->entityManager->createQueryBuilder() ->select(self::CONTENT_RICH_ENTITY_ALIAS) ->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS) From a6619fc6a18e63a747a22ec70687c0bc5d4dd97c Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 16 Mar 2023 02:01:00 +0100 Subject: [PATCH 8/9] Remove unused code and fix some more types --- .../Model/DimensionContentCollection.php | 22 ------------------- .../Controller/ExampleController.php | 2 +- .../ExampleTestBundle/Entity/Example.php | 2 +- .../Entity/ExampleDimensionContent.php | 2 +- 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/Content/Domain/Model/DimensionContentCollection.php b/Content/Domain/Model/DimensionContentCollection.php index 3e6aaa30..b609a99e 100644 --- a/Content/Domain/Model/DimensionContentCollection.php +++ b/Content/Domain/Model/DimensionContentCollection.php @@ -29,16 +29,6 @@ class DimensionContentCollection implements \IteratorAggregate, DimensionContent */ private $dimensionContents; - /** - * @var T|null - */ - private $unlocalizedDimensionContent; - - /** - * @var T|null - */ - private $localizedDimensionContent; - /** * @var mixed[] */ @@ -70,18 +60,6 @@ public function __construct( $this->dimensionContentClass = $dimensionContentClass; $this->defaultDimensionAttributes = $dimensionContentClass::getDefaultDimensionAttributes(); - $this->unlocalizedDimensionContent = $this->dimensionContents->filter( - function(DimensionContentInterface $dimensionContent) { - return null === $dimensionContent->getLocale(); - } - )->first() ?: null; - - $this->localizedDimensionContent = $this->dimensionContents->filter( - function(DimensionContentInterface $dimensionContent) { - return null !== $dimensionContent->getLocale(); - } - )->first() ?: null; - $this->dimensionAttributes = $dimensionAttributes; } diff --git a/Tests/Application/ExampleTestBundle/Controller/ExampleController.php b/Tests/Application/ExampleTestBundle/Controller/ExampleController.php index 06b8c65d..4c87846f 100644 --- a/Tests/Application/ExampleTestBundle/Controller/ExampleController.php +++ b/Tests/Application/ExampleTestBundle/Controller/ExampleController.php @@ -309,7 +309,7 @@ protected function getData(Request $request): array * * @return mixed[] */ - protected function normalize(Example $example, DimensionContentInterface $dimensionContent): array + protected function normalize(Example $example, ExampleDimensionContent $dimensionContent): array { $normalizedContent = $this->contentManager->normalize($dimensionContent); diff --git a/Tests/Application/ExampleTestBundle/Entity/Example.php b/Tests/Application/ExampleTestBundle/Entity/Example.php index bc029a77..f415a558 100644 --- a/Tests/Application/ExampleTestBundle/Entity/Example.php +++ b/Tests/Application/ExampleTestBundle/Entity/Example.php @@ -18,7 +18,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; /** - * @implements ContentRichEntityInterface + * @implements ContentRichEntityInterface> */ class Example implements ContentRichEntityInterface { diff --git a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php index de5f5630..6e2e39ff 100644 --- a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php +++ b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php @@ -28,7 +28,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowTrait; /** - * @implements DimensionContentInterface + * @implements DimensionContentInterface> */ class ExampleDimensionContent implements DimensionContentInterface, ExcerptInterface, SeoInterface, TemplateInterface, RoutableInterface, WorkflowInterface { From 36b8fb84b7d8a9d391532ee5127ede6a12a6ae3e Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 16 Mar 2023 02:51:52 +0100 Subject: [PATCH 9/9] Update Example and ExampleDimensionContent Entity --- Content/Domain/Model/ContentRichEntityTrait.php | 14 ++++++++++++-- Content/Domain/Model/DimensionContentInterface.php | 2 +- .../ExampleTestBundle/Entity/Example.php | 5 ++++- .../Entity/ExampleDimensionContent.php | 2 +- .../Teaser/ExampleTeaserProvider.php | 4 ++++ .../Sulu/Search/ContentReindexProviderTest.php | 7 ++++--- .../Search/ContentSearchMetadataProviderTest.php | 7 ++++--- .../Sulu/Sitemap/ContentSitemapProviderTest.php | 4 +++- .../ContentNormalizer/ContentNormalizerTest.php | 2 +- 9 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Content/Domain/Model/ContentRichEntityTrait.php b/Content/Domain/Model/ContentRichEntityTrait.php index c2f31ed0..8b99ebb2 100644 --- a/Content/Domain/Model/ContentRichEntityTrait.php +++ b/Content/Domain/Model/ContentRichEntityTrait.php @@ -16,15 +16,18 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +/** + * @template T of DimensionContentInterface + */ trait ContentRichEntityTrait { /** - * @var ArrayCollection + * @var ArrayCollection */ protected $dimensionContents; /** - * @return Collection + * @return Collection */ public function getDimensionContents(): Collection { @@ -33,6 +36,9 @@ public function getDimensionContents(): Collection return $this->dimensionContents; } + /** + * @param T $dimensionContent + */ public function addDimensionContent(DimensionContentInterface $dimensionContent): void { $this->initializeDimensionContents(); @@ -40,6 +46,10 @@ public function addDimensionContent(DimensionContentInterface $dimensionContent) $this->dimensionContents->add($dimensionContent); } + + /** + * @param T $dimensionContent + */ public function removeDimensionContent(DimensionContentInterface $dimensionContent): void { $this->initializeDimensionContents(); diff --git a/Content/Domain/Model/DimensionContentInterface.php b/Content/Domain/Model/DimensionContentInterface.php index 7d6fea1b..a1b98e5b 100644 --- a/Content/Domain/Model/DimensionContentInterface.php +++ b/Content/Domain/Model/DimensionContentInterface.php @@ -32,7 +32,7 @@ public function getStage(): string; public function setStage(string $stage): void; /** - * @return T + * @return T */ public function getResource(): ContentRichEntityInterface; diff --git a/Tests/Application/ExampleTestBundle/Entity/Example.php b/Tests/Application/ExampleTestBundle/Entity/Example.php index f415a558..5b3a7f75 100644 --- a/Tests/Application/ExampleTestBundle/Entity/Example.php +++ b/Tests/Application/ExampleTestBundle/Entity/Example.php @@ -18,10 +18,13 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; /** - * @implements ContentRichEntityInterface> + * @implements ContentRichEntityInterface */ class Example implements ContentRichEntityInterface { + /** + * @phpstan-use ContentRichEntityTrait + */ use ContentRichEntityTrait; public const RESOURCE_KEY = 'examples'; diff --git a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php index 6e2e39ff..de5f5630 100644 --- a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php +++ b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php @@ -28,7 +28,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowTrait; /** - * @implements DimensionContentInterface> + * @implements DimensionContentInterface */ class ExampleDimensionContent implements DimensionContentInterface, ExcerptInterface, SeoInterface, TemplateInterface, RoutableInterface, WorkflowInterface { diff --git a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php index caec3fe8..91edd459 100644 --- a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php +++ b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php @@ -19,10 +19,14 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Teaser\ContentTeaserProvider; use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; use Sulu\Bundle\PageBundle\Teaser\Configuration\TeaserConfiguration; use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface; use Symfony\Contracts\Translation\TranslatorInterface; +/** + * @extends ContentTeaserProvider + */ class ExampleTeaserProvider extends ContentTeaserProvider { /** diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php index 0f89750a..f11e9bde 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php @@ -16,6 +16,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search\ContentReindexProvider; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; @@ -26,17 +27,17 @@ class ContentReindexProviderTest extends SuluTestCase use CreateExampleTrait; /** - * @var ContentReindexProvider + * @var ContentReindexProvider */ private $reindexProvider; /** - * @var ContentRichEntityInterface + * @var Example */ private static $example1; /** - * @var ContentRichEntityInterface + * @var Example */ private static $example2; diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php index 07d49256..7417639a 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php @@ -16,9 +16,10 @@ use Massive\Bundle\SearchBundle\Search\Metadata\ClassMetadata; use Massive\Bundle\SearchBundle\Search\ObjectToDocumentConverter; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search\ContentSearchMetadataProvider; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; @@ -37,12 +38,12 @@ class ContentSearchMetadataProviderTest extends SuluTestCase private $objectToDocumentConverter; /** - * @var ContentSearchMetadataProvider + * @var ContentSearchMetadataProvider */ private $searchMetadataProvider; /** - * @var ContentRichEntityInterface + * @var Example */ private static $example1; diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php index 417c13ff..d0a6f8b4 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php @@ -14,6 +14,8 @@ namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Sulu\Sitemap; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Sitemap\ContentSitemapProvider; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; +use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; use Sulu\Bundle\ContentBundle\Tests\Traits\AssertSnapshotTrait; use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; @@ -30,7 +32,7 @@ class ContentSitemapProviderTest extends SuluTestCase public const HOST = 'localhost'; /** - * @var ContentSitemapProvider + * @var ContentSitemapProvider */ private $contentSitemapProvider; diff --git a/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php index 1fd08d4f..3b7ea312 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php @@ -61,7 +61,7 @@ public function testResolveSimple(): void use DimensionContentTrait; /** - * @var ContentRichEntityInterface + * @var ContentRichEntityInterface */ protected $resource;