Skip to content

Commit

Permalink
Fix tests usage of generic interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Mar 17, 2023
1 parent 5bc35b5 commit d2a842d
Show file tree
Hide file tree
Showing 34 changed files with 391 additions and 316 deletions.
4 changes: 2 additions & 2 deletions Content/Application/ContentMerger/Merger/ExcerptMerger.php
Expand Up @@ -48,13 +48,13 @@ public function merge(object $targetObject, object $sourceObject): void
}

if ($excerptTags = $sourceObject->getExcerptTags()) {
if (count($excerptTags) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array
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 (count($excerptCategories) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array
if (\count($excerptCategories) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array
$targetObject->setExcerptCategories($excerptCategories);
}
}
Expand Down
1 change: 0 additions & 1 deletion Content/Domain/Model/ContentRichEntityTrait.php
Expand Up @@ -46,7 +46,6 @@ public function addDimensionContent(DimensionContentInterface $dimensionContent)
$this->dimensionContents->add($dimensionContent);
}


/**
* @param T $dimensionContent
*/
Expand Down
3 changes: 2 additions & 1 deletion Content/Domain/Model/DimensionContentCollection.php
Expand Up @@ -17,7 +17,7 @@
use Doctrine\Common\Collections\Criteria;

/**
* @template T of DimensionContentInterface
* @template-covariant T of DimensionContentInterface
*
* @implements \IteratorAggregate<T>
* @implements DimensionContentCollectionInterface<T>
Expand Down Expand Up @@ -91,6 +91,7 @@ public function getDimensionAttributes(): array
return $this->dimensionAttributes;
}

#[\ReturnTypeWillChange]
public function getIterator()
{
return $this->dimensionContents;
Expand Down
2 changes: 1 addition & 1 deletion Content/Infrastructure/Doctrine/MetadataLoader.php
Expand Up @@ -114,7 +114,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
* @param ClassMetadataInfo<object> $metadata
* @param class-string $class
*/
private function addManyToOne( // @phpstan-ignore-line ignore unused method
private function addManyToOne(// @phpstan-ignore-line ignore unused method
LoadClassMetadataEventArgs $event,
ClassMetadataInfo $metadata,
string $name,
Expand Down
Expand Up @@ -149,7 +149,7 @@ public function serialize($object)

/**
* @param string $serializedObject
* @param string $objectClass
* @param class-string $objectClass
*
* @return B|null
*/
Expand Down
Expand Up @@ -66,7 +66,7 @@ public function getDimensionAttributes(): array
);
}

public function getIterator()
public function getIterator(): \Traversable
{
return new ArrayCollection([$this->previewDimensionContent]);
}
Expand Down
Expand Up @@ -61,12 +61,13 @@ public function __construct(
}

/**
* @template T of DimensionContentInterface
* @template B of DimensionContentInterface
* @template T of ContentRichEntityInterface<B>
*
* @param class-string<ContentRichEntityInterface<T>> $entityClass
* @param class-string<T> $entityClass
* @param string $id
* @param string $locale
* @param T|null $object
* @param B|null $object
*
* @return mixed[]
*/
Expand Down
Expand Up @@ -144,7 +144,6 @@ protected function normalizeContent(DimensionContentInterface $dimensionContent)
* @template T of DimensionContentInterface
*
* @param T $dimensionContent
*
* @param mixed[] $data
*/
protected function createDataItem(DimensionContentInterface $dimensionContent, array $data): ItemInterface
Expand Down
Expand Up @@ -138,7 +138,7 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale, $showUnpub
}

/**
* TODO check "tagOperator"|"tagsOperator" vs "websiteTagOperator"|"websiteTagsOperator"
* TODO check "tagOperator"|"tagsOperator" vs "websiteTagOperator"|"websiteTagsOperator".
*
* @param array{
* categories?: int[],
Expand Down
Expand Up @@ -327,6 +327,7 @@ public function toArray($complete = true): array
/**
* @return mixed[]
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray(true);
Expand Down
Expand Up @@ -15,7 +15,7 @@

use Sulu\Component\Content\Compat\RoutableStructureInterface as SuluRoutableStructureInterface;

if (interface_exists(SuluRoutableStructureInterface::class)) {
if (\interface_exists(SuluRoutableStructureInterface::class)) {
/**
* @deprecated will be removed, as soon as the ArticleBundle rises the minimum requirement of sulu to a version,
* where this interface exists
Expand Down
Expand Up @@ -120,7 +120,6 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale): ?Teaser {

/**
* @param B $dimensionContent
*
* @param array<string, mixed> $data
*/
protected function createTeaser(DimensionContentInterface $dimensionContent, array $data, string $locale): ?Teaser
Expand Down
3 changes: 3 additions & 0 deletions Tests/Application/ExampleTestBundle/Entity/Example.php
Expand Up @@ -43,6 +43,9 @@ public function getId()
return $this->id;
}

/**
* @return ExampleDimensionContent
*/
public function createDimensionContent(): DimensionContentInterface
{
$exampleDimensionContent = new ExampleDimensionContent($this);
Expand Down
Expand Up @@ -13,7 +13,6 @@

namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Sulu\Search;

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;
Expand Down
Expand Up @@ -66,7 +66,9 @@ protected function createRouteDataMapperInstance(
}

/**
* @param ObjectProphecy<DimensionContentInterface&TemplateInterface&RoutableInterface> $routableMock
* @template T of DimensionContentInterface&TemplateInterface&RoutableInterface
*
* @param ObjectProphecy<T> $routableMock
*/
protected function wrapRoutableMock(ObjectProphecy $routableMock): RoutableInterface
{
Expand All @@ -75,7 +77,7 @@ protected function wrapRoutableMock(ObjectProphecy $routableMock): RoutableInter
TemplateInterface,
RoutableInterface {
/**
* @var DimensionContentInterface&TemplateInterface&RoutableInterface
* @var T
*/
protected $instance;

Expand Down Expand Up @@ -209,7 +211,6 @@ public function testMapNoTemplate(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -252,7 +253,6 @@ public function testMapNoMetadata(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -295,7 +295,6 @@ public function testMapNoRouteProperty(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -347,7 +346,6 @@ public function testMapNoRoutePropertyData(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -400,7 +398,6 @@ public function testMapNoRoutePropertyDataAndNoOldRoute(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);
$localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent);

Expand Down Expand Up @@ -469,7 +466,6 @@ public function testMapNoRoutePropertyDataAndNoOldRouteIgnoreSlash(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);
$localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent);

Expand Down Expand Up @@ -530,7 +526,6 @@ public function testMapNoContentId(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -578,7 +573,6 @@ public function testMapNoLocale(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -628,7 +622,6 @@ public function testMapNoRoutePath(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);
$localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent);

Expand Down Expand Up @@ -697,7 +690,6 @@ public function testMap(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -759,7 +751,6 @@ public function testMapConflictingRoute(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -821,7 +812,6 @@ public function testMapNoTemplateWithDefaultTemplate(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -884,7 +874,6 @@ public function testMapCustomRoute(): void
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&RoutableInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);
$localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent);

Expand Down

0 comments on commit d2a842d

Please sign in to comment.