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 c7f9d8c
Show file tree
Hide file tree
Showing 26 changed files with 388 additions and 304 deletions.
3 changes: 2 additions & 1 deletion Content/Domain/Model/DimensionContentCollection.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getDimensionAttributes(): array
);
}

public function getIterator()
public function getIterator(): \Traversable
{
return new ArrayCollection([$this->previewDimensionContent]);
}
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public function toArray($complete = true): array
/**
* @return mixed[]
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray(true);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Application/ExampleTestBundle/Entity/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function getId()
return $this->id;
}

/**
* @return ExampleDimensionContent
*/
public function createDimensionContent(): DimensionContentInterface
{
$exampleDimensionContent = new ExampleDimensionContent($this);
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ protected function createTemplateDataMapperInstance(
}

/**
* @param ObjectProphecy<DimensionContentInterface&TemplateInterface> $templateMock
* @template T of DimensionContentInterface&TemplateInterface
*
* @param ObjectProphecy<T> $templateMock
*/
protected function wrapTemplateMock(ObjectProphecy $templateMock): TemplateInterface
{
Expand All @@ -50,6 +52,11 @@ protected function wrapTemplateMock(ObjectProphecy $templateMock): TemplateInter
TemplateInterface {
use DimensionContentMockWrapperTrait;
use TemplateMockWrapperTrait;

/**
* @var T
*/
protected $instance;
};
}

Expand Down Expand Up @@ -88,7 +95,6 @@ public function testMapLocalizedNoTemplateKey(): void
$structureMetadataFactory = $this->prophesize(StructureMetadataFactoryInterface::class);

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $unlocalizedDimensionContent */
$unlocalizedDimensionContent->willImplement(TemplateInterface::class);

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
Expand Down Expand Up @@ -130,7 +136,6 @@ public function testMapLocalizedNoTemplateInstance(): void
)->willReturn($structureMetadata->reveal())->shouldBeCalled();

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $unlocalizedDimensionContent */
$unlocalizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
Expand Down Expand Up @@ -161,7 +166,6 @@ public function testMapLocalizedNoStructureFound(): void
)->willReturn(null)->shouldBeCalled();

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $unlocalizedDimensionContent */
$unlocalizedDimensionContent->willImplement(TemplateInterface::class);

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
Expand All @@ -186,7 +190,6 @@ public function testMapUnlocalizedTemplate(): void
];

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $unlocalizedDimensionContent */
$unlocalizedDimensionContent->willImplement(TemplateInterface::class);
$unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled();
$unlocalizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled();
Expand Down Expand Up @@ -228,14 +231,12 @@ public function testMapLocalizedTemplate(): void
];

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $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<DimensionContentInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled();
$localizedDimensionContent->setTemplateData(['localizedField' => 'Test Localized'])->shouldBeCalled();

Expand Down Expand Up @@ -278,13 +279,11 @@ public function testMapLocalizedNoTemplateKeyWithDefaultTemplate(): void
];

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $unlocalizedDimensionContent */
$unlocalizedDimensionContent->willImplement(TemplateInterface::class);
$unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled();
$unlocalizedDimensionContent->setTemplateData(['unlocalizedField' => 'Test Unlocalized'])->shouldBeCalled();

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);
$localizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled();
$localizedDimensionContent->setTemplateData(['localizedField' => 'Test Localized'])->shouldBeCalled();
Expand Down Expand Up @@ -332,13 +331,11 @@ public function testMapFloatValueTemplate(): void
];

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $unlocalizedDimensionContent */
$unlocalizedDimensionContent->willImplement(TemplateInterface::class);
$unlocalizedDimensionContent->getTemplateData()->willReturn([])->shouldBeCalled();
$unlocalizedDimensionContent->setTemplateData(['1.1' => 'Test Unlocalized'])->shouldBeCalled();

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
/** @var ObjectProphecy<DimensionContentInterface&TemplateInterface> $localizedDimensionContent */
$localizedDimensionContent->willImplement(TemplateInterface::class);
$localizedDimensionContent->setTemplateKey('template-key')->shouldBeCalled();
$localizedDimensionContent->setTemplateData(['localizedField' => 'Test Localized'])->shouldBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testMerge(): void
$merger2->reveal(),
]);

$mergedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$mergedDimensionContent = $this->prophesize(ExampleDimensionContent::class);

$resource = $this->prophesize(Example::class);
$resource->createDimensionContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ public function testResolveSimple(): void
use DimensionContentTrait;

/**
* @var ContentRichEntityInterface<DimensionContentInterface>
* @var ContentRichEntityInterface<self>
*/
protected $resource;

/**
* @param ContentRichEntityInterface<self> $resource
*/
public function __construct(ContentRichEntityInterface $resource)
{
$this->resource = $resource;
Expand All @@ -77,6 +80,9 @@ public static function getResourceKey(): string
throw new \RuntimeException('Should not be called while executing tests.');
}

/**
* @return ContentRichEntityInterface<self>
*/
public function getResource(): ContentRichEntityInterface
{
return $this->resource;
Expand Down Expand Up @@ -105,10 +111,13 @@ public function testResolveFull(): void
use WorkflowTrait;

/**
* @var ContentRichEntityInterface
* @var ContentRichEntityInterface<self>
*/
protected $resource;

/**
* @param ContentRichEntityInterface<self> $resource
*/
public function __construct(ContentRichEntityInterface $resource)
{
$this->resource = $resource;
Expand All @@ -126,6 +135,9 @@ public static function getTemplateType(): string
throw new \RuntimeException('Should not be called while executing tests.');
}

/**
* @return ContentRichEntityInterface<self>
*/
public function getResource(): ContentRichEntityInterface
{
return $this->resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,25 @@ protected function createContentWorkflowInstance(
}

/**
* @param ObjectProphecy<DimensionContentInterface> $workflowMock
* @template T of DimensionContentInterface&WorkflowInterface
*
* @return DimensionContentInterface&WorkflowInterface
* @param ObjectProphecy<T> $templateMock
*
* @return T
*/
protected function wrapWorkflowMock(ObjectProphecy $workflowMock)
protected function wrapWorkflowMock(ObjectProphecy $templateMock): WorkflowInterface
{
return new class($workflowMock) extends MockWrapper implements
return new class($templateMock) extends MockWrapper implements // @phpstan-ignore-line
DimensionContentInterface,
WorkflowInterface {
use DimensionContentMockWrapperTrait;
use WorkflowMockWrapperTrait;

/**
* @var T
*/
protected $instance;

public static function getWorkflowName(): string
{
return 'content_workflow';
Expand Down
Loading

0 comments on commit c7f9d8c

Please sign in to comment.