diff --git a/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php b/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php new file mode 100644 index 00000000..3a9d62c3 --- /dev/null +++ b/Content/Application/ContentMetadataInspector/ContentMetadataInspector.php @@ -0,0 +1,45 @@ +entityManager = $entityManager; + } + + public function getDimensionContentClass(string $contentRichEntityClass): string + { + $classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass); + $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); + + return $associationMapping['targetEntity']; + } + + public function getDimensionContentMappingProperty(string $contentRichEntityClass): string + { + $classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass); + $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); + + return $associationMapping['mappedBy']; + } +} diff --git a/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php b/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php new file mode 100644 index 00000000..0e7c1720 --- /dev/null +++ b/Content/Application/ContentMetadataInspector/ContentMetadataInspectorInterface.php @@ -0,0 +1,32 @@ + $contentRichEntityClass + * + * @return class-string + */ + public function getDimensionContentClass(string $contentRichEntityClass): string; + + /** + * @param class-string $contentRichEntityClass + */ + public function getDimensionContentMappingProperty(string $contentRichEntityClass): string; +} diff --git a/Content/Infrastructure/Doctrine/DimensionContentRepository.php b/Content/Infrastructure/Doctrine/DimensionContentRepository.php index bff23595..8e7ff498 100644 --- a/Content/Infrastructure/Doctrine/DimensionContentRepository.php +++ b/Content/Infrastructure/Doctrine/DimensionContentRepository.php @@ -14,6 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine; use Doctrine\ORM\EntityManagerInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollection; @@ -28,25 +29,32 @@ class DimensionContentRepository implements DimensionContentRepositoryInterface */ private $entityManager; - public function __construct(EntityManagerInterface $entityManager) - { + /** + * @var ContentMetadataInspectorInterface + */ + private $contentMetadataInspector; + + public function __construct( + EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector + ) { $this->entityManager = $entityManager; + $this->contentMetadataInspector = $contentMetadataInspector; } public function load( ContentRichEntityInterface $contentRichEntity, DimensionCollectionInterface $dimensionCollection ): DimensionContentCollectionInterface { - $classMetadata = $this->entityManager->getClassMetadata(\get_class($contentRichEntity)); - $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); - $dimensionContentClass = $associationMapping['targetEntity']; + $dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass(\get_class($contentRichEntity)); + $mappingProperty = $this->contentMetadataInspector->getDimensionContentMappingProperty(\get_class($contentRichEntity)); $queryBuilder = $this->entityManager->createQueryBuilder() ->from($dimensionContentClass, 'dimensionContent') ->select('dimensionContent') ->addSelect('dimension') ->innerJoin('dimensionContent.dimension', 'dimension') - ->innerJoin('dimensionContent.' . $associationMapping['mappedBy'], 'content') + ->innerJoin('dimensionContent.' . $mappingProperty, 'content') ->where('content.id = :id') ->setParameter('id', $contentRichEntity->getId()); diff --git a/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php b/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php index 9ec79de9..9fa5cd7c 100644 --- a/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php +++ b/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php @@ -13,15 +13,13 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Admin; -use Doctrine\ORM\EntityManagerInterface; use Sulu\Bundle\AdminBundle\Admin\View\DropdownToolbarAction; use Sulu\Bundle\AdminBundle\Admin\View\FormViewBuilderInterface; use Sulu\Bundle\AdminBundle\Admin\View\PreviewFormViewBuilderInterface; use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction; use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface; use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderInterface; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; @@ -43,9 +41,9 @@ class ContentViewBuilderFactory implements ContentViewBuilderFactoryInterface private $objectProviderRegistry; /** - * @var EntityManagerInterface + * @var ContentMetadataInspectorInterface */ - private $entityManager; + private $contentMetadataInspector; /** * @var SecurityCheckerInterface @@ -55,19 +53,19 @@ class ContentViewBuilderFactory implements ContentViewBuilderFactoryInterface public function __construct( ViewBuilderFactoryInterface $viewBuilderFactory, PreviewObjectProviderRegistryInterface $objectProviderRegistry, - EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector, SecurityCheckerInterface $securityChecker ) { $this->viewBuilderFactory = $viewBuilderFactory; $this->objectProviderRegistry = $objectProviderRegistry; - $this->entityManager = $entityManager; + $this->contentMetadataInspector = $contentMetadataInspector; $this->securityChecker = $securityChecker; } public function getDefaultToolbarActions( string $contentRichEntityClass ): array { - $dimensionContentClass = $this->getDimensionContentClass($contentRichEntityClass); + $dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass($contentRichEntityClass); $toolbarActions = []; @@ -132,7 +130,7 @@ public function createViews( ?string $securityContext = null, ?array $toolbarActions = null ): array { - $dimensionContentClass = $this->getDimensionContentClass($contentRichEntityClass); + $dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass($contentRichEntityClass); $resourceKey = $dimensionContentClass::getResourceKey(); $previewEnabled = $this->objectProviderRegistry->hasPreviewObjectProvider($resourceKey); @@ -291,17 +289,4 @@ private function hasPermission(?string $securityContext, string $permissionType) return $this->securityChecker->hasPermission($securityContext, $permissionType); } - - /** - * @param class-string $contentRichEntityClass - * - * @return class-string - */ - private function getDimensionContentClass(string $contentRichEntityClass): string - { - $classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass); - $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); - - return $associationMapping['targetEntity']; - } } diff --git a/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php b/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php index 3d837dcb..c4ce6e9f 100644 --- a/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php +++ b/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php @@ -15,6 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use Massive\Bundle\SearchBundle\Search\Reindex\LocalizedReindexProviderInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\ContentResolverInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; @@ -30,6 +31,11 @@ class ContentReindexProvider implements LocalizedReindexProviderInterface */ private $entityManager; + /** + * @var ContentMetadataInspectorInterface + */ + private $contentMetadataInspector; + /** * @var ContentResolverInterface */ @@ -55,11 +61,13 @@ class ContentReindexProvider implements LocalizedReindexProviderInterface */ public function __construct( EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector, ContentResolverInterface $contentResolver, string $context, string $contentRichEntityClass ) { $this->entityManager = $entityManager; + $this->contentMetadataInspector = $contentMetadataInspector; $this->contentResolver = $contentResolver; $this->context = $context; $this->contentRichEntityClass = $contentRichEntityClass; @@ -173,9 +181,7 @@ private function getDimensionContentClass(): string return $this->dimensionContentClass; } - $classMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); - $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); - $this->dimensionContentClass = $associationMapping['targetEntity']; + $this->dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass($this->contentRichEntityClass); return $this->dimensionContentClass; } diff --git a/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php b/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php index 89e0bf8d..fce1ba59 100644 --- a/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php +++ b/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProvider.php @@ -13,7 +13,6 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search; -use Doctrine\ORM\EntityManagerInterface; use Massive\Bundle\SearchBundle\Search\Document; use Massive\Bundle\SearchBundle\Search\Factory; use Massive\Bundle\SearchBundle\Search\Metadata\ClassMetadata; @@ -21,6 +20,7 @@ use Massive\Bundle\SearchBundle\Search\Metadata\Field\Expression; use Massive\Bundle\SearchBundle\Search\Metadata\IndexMetadata; use Massive\Bundle\SearchBundle\Search\Metadata\ProviderInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface; @@ -49,9 +49,9 @@ class ContentSearchMetadataProvider implements ProviderInterface ]; /** - * @var EntityManagerInterface + * @var ContentMetadataInspectorInterface */ - private $entityManager; + private $contentMetadataInspector; /** * @var Factory @@ -77,12 +77,12 @@ class ContentSearchMetadataProvider implements ProviderInterface * @param class-string $contentRichEntityClass */ public function __construct( - EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector, Factory $searchMetadataFactory, StructureMetadataFactoryInterface $structureFactory, string $contentRichEntityClass ) { - $this->entityManager = $entityManager; + $this->contentMetadataInspector = $contentMetadataInspector; $this->searchMetadataFactory = $searchMetadataFactory; $this->structureFactory = $structureFactory; $this->contentRichEntityClass = $contentRichEntityClass; @@ -366,9 +366,7 @@ private function getDimensionContentClass(): string return $this->dimensionContentClass; } - $classMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); - $associationMapping = $classMetadata->getAssociationMapping('dimensionContents'); - $this->dimensionContentClass = $associationMapping['targetEntity']; + $this->dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass($this->contentRichEntityClass); return $this->dimensionContentClass; } diff --git a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php index f59231ef..31ea1215 100644 --- a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php +++ b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php @@ -15,6 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; @@ -40,6 +41,11 @@ abstract class ContentTeaserProvider implements TeaserProviderInterface */ protected $entityManager; + /** + * @var ContentMetadataInspectorInterface + */ + private $contentMetadataInspector; + /** * @var StructureMetadataFactoryInterface */ @@ -56,11 +62,13 @@ abstract class ContentTeaserProvider implements TeaserProviderInterface public function __construct( ContentManagerInterface $contentManager, EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector, StructureMetadataFactoryInterface $metadataFactory, string $contentRichEntityClass ) { $this->contentManager = $contentManager; $this->entityManager = $entityManager; + $this->contentMetadataInspector = $contentMetadataInspector; $this->metadataFactory = $metadataFactory; $this->contentRichEntityClass = $contentRichEntityClass; } @@ -297,8 +305,7 @@ protected function getEntityIdField(): string protected function getResourceKey(): string { - $classMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); - $dimensionContentClass = $classMetadata->getAssociationMapping('dimensionContents')['targetEntity']; + $dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass($this->contentRichEntityClass); return $dimensionContentClass::getResourceKey(); } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 8ef4f0f8..b53c40bb 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -11,7 +11,7 @@ - + @@ -57,9 +57,17 @@ + + + + + + + + diff --git a/Tests/Application/ExampleTestBundle/Resources/config/services.yaml b/Tests/Application/ExampleTestBundle/Resources/config/services.yaml index 5f1ac9b0..d4df39fa 100644 --- a/Tests/Application/ExampleTestBundle/Resources/config/services.yaml +++ b/Tests/Application/ExampleTestBundle/Resources/config/services.yaml @@ -44,6 +44,7 @@ services: arguments: - '@sulu_content.content_manager' - '@doctrine.orm.entity_manager' + - '@sulu_content.content_metadata_inspector' - '@sulu_page.structure.factory' - '@translator' tags: @@ -72,6 +73,7 @@ services: class: Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search\ContentReindexProvider arguments: - '@doctrine.orm.entity_manager' + - '@sulu_content.content_metadata_inspector' - '@sulu_content.content_resolver' - '%sulu.context%' - Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example @@ -81,7 +83,7 @@ services: example_test.example_search_metadata_provider: class: Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search\ContentSearchMetadataProvider arguments: - - '@doctrine.orm.entity_manager' + - '@sulu_content.content_metadata_inspector' - '@massive_search.factory_default' - '@sulu_page.structure.factory' - Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example diff --git a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php index 785487bd..3c38e431 100644 --- a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php +++ b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php @@ -15,6 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; 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; @@ -32,10 +33,11 @@ class ExampleTeaserProvider extends ContentTeaserProvider public function __construct( ContentManagerInterface $contentManager, EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector, StructureMetadataFactoryInterface $metadataFactory, TranslatorInterface $translator ) { - parent::__construct($contentManager, $entityManager, $metadataFactory, Example::class); + parent::__construct($contentManager, $entityManager, $contentMetadataInspector, $metadataFactory, Example::class); $this->translator = $translator; } diff --git a/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php b/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php new file mode 100644 index 00000000..7a7be212 --- /dev/null +++ b/Tests/Unit/Content/Application/ContentMetadataInspector/ContentMetadataInspectorTest.php @@ -0,0 +1,51 @@ +prophesize(EntityManagerInterface::class); + $classMetadata = $this->prophesize(ClassMetadata::class); + $classMetadata->getAssociationMapping('dimensionContents') + ->willReturn(['targetEntity' => ExampleDimensionContent::class]); + + $entityManager->getClassMetadata(Example::class)->willReturn($classMetadata->reveal()); + + $contentMetadataInspector = $this->createContentMetadataInspectorTestInstance( + $entityManager->reveal() + ); + + $dimensionContentClass = $contentMetadataInspector->getDimensionContentClass(Example::class); + + $this->assertSame(ExampleDimensionContent::class, $dimensionContentClass); + } +} diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php index 5f04a271..b6751cb2 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php @@ -14,12 +14,12 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Admin; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Mapping\ClassMetadata; use PHPUnit\Framework\TestCase; use Sulu\Bundle\AdminBundle\Admin\View\FormViewBuilderInterface; use Sulu\Bundle\AdminBundle\Admin\View\PreviewFormViewBuilderInterface; use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactory; use Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\ContentDataMapperInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\ContentResolverInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; @@ -46,7 +46,7 @@ class ContentViewBuilderFactoryTest extends TestCase { protected function createContentViewBuilder( - EntityManagerInterface $entityManager, + ContentMetadataInspectorInterface $contentMetadataInspector, SecurityCheckerInterface $securityChecker, PreviewObjectProviderRegistryInterface $previewObjectProviderRegistry = null ): ContentViewBuilderFactoryInterface { @@ -57,7 +57,7 @@ protected function createContentViewBuilder( return new ContentViewBuilderFactory( new ViewBuilderFactory(), $previewObjectProviderRegistry, - $entityManager, + $contentMetadataInspector, $securityChecker ); } @@ -91,14 +91,11 @@ public function testCreateViews(): void { $securityChecker = $this->prophesize(SecurityCheckerInterface::class); - $entityManager = $this->prophesize(EntityManagerInterface::class); - $classMetadata = $this->prophesize(ClassMetadata::class); - $classMetadata->getAssociationMapping('dimensionContents') - ->willReturn(['targetEntity' => ExampleDimensionContent::class]); + $contentMetadataInspector = $this->prophesize(ContentMetadataInspectorInterface::class); + $contentMetadataInspector->getDimensionContentClass(Example::class) + ->willReturn(ExampleDimensionContent::class); - $entityManager->getClassMetadata(Example::class)->willReturn($classMetadata->reveal()); - - $contentViewBuilder = $this->createContentViewBuilder($entityManager->reveal(), $securityChecker->reveal()); + $contentViewBuilder = $this->createContentViewBuilder($contentMetadataInspector->reveal(), $securityChecker->reveal()); $views = $contentViewBuilder->createViews(Example::class, 'edit_parent_key'); @@ -142,11 +139,9 @@ public function testCreateViewsWithPreview(): void $securityChecker = $this->prophesize(SecurityCheckerInterface::class); $entityManager = $this->prophesize(EntityManagerInterface::class); - $classMetadata = $this->prophesize(ClassMetadata::class); - $classMetadata->getAssociationMapping('dimensionContents') - ->willReturn(['targetEntity' => ExampleDimensionContent::class]); - - $entityManager->getClassMetadata(Example::class)->willReturn($classMetadata->reveal()); + $contentMetadataInspector = $this->prophesize(ContentMetadataInspectorInterface::class); + $contentMetadataInspector->getDimensionContentClass(Example::class) + ->willReturn(ExampleDimensionContent::class); $contentResolver = $this->prophesize(ContentResolverInterface::class); $contentDataMapper = $this->prophesize(ContentDataMapperInterface::class); @@ -161,7 +156,7 @@ public function testCreateViewsWithPreview(): void $previewObjectProviders = ['examples' => $contentObjectProvider]; $previewObjectProviderRegistry = $this->createPreviewObjectProviderRegistry($previewObjectProviders); $contentViewBuilder = $this->createContentViewBuilder( - $entityManager->reveal(), + $contentMetadataInspector->reveal(), $securityChecker->reveal(), $previewObjectProviderRegistry ); @@ -273,14 +268,11 @@ public function testCreateViewsWithSecurityContext(array $permissions, array $ex $securityChecker = $this->prophesize(SecurityCheckerInterface::class); $entityManager = $this->prophesize(EntityManagerInterface::class); - $classMetadata = $this->prophesize(ClassMetadata::class); - $classMetadata->getAssociationMapping('dimensionContents')->willReturn( - ['targetEntity' => ExampleDimensionContent::class] - ); - - $entityManager->getClassMetadata(Example::class)->willReturn($classMetadata->reveal()); + $contentMetadataInspector = $this->prophesize(ContentMetadataInspectorInterface::class); + $contentMetadataInspector->getDimensionContentClass(Example::class) + ->willReturn(ExampleDimensionContent::class); - $contentViewBuilder = $this->createContentViewBuilder($entityManager->reveal(), $securityChecker->reveal()); + $contentViewBuilder = $this->createContentViewBuilder($contentMetadataInspector->reveal(), $securityChecker->reveal()); foreach ($permissions as $permissionType => $permission) { $securityChecker->hasPermission('test_context', $permissionType)->willReturn($permission); @@ -403,15 +395,11 @@ public function testCreateViewsWithContentRichEntityClass(DimensionContentInterf { $securityChecker = $this->prophesize(SecurityCheckerInterface::class); - $entityManager = $this->prophesize(EntityManagerInterface::class); - $classMetadata = $this->prophesize(ClassMetadata::class); - $classMetadata->getAssociationMapping('dimensionContents')->willReturn( - ['targetEntity' => \get_class($dimensionContentObject)] - ); - - $entityManager->getClassMetadata(Example::class)->willReturn($classMetadata->reveal()); + $contentMetadataInspector = $this->prophesize(ContentMetadataInspectorInterface::class); + $contentMetadataInspector->getDimensionContentClass(Example::class) + ->willReturn(\get_class($dimensionContentObject)); - $contentViewBuilder = $this->createContentViewBuilder($entityManager->reveal(), $securityChecker->reveal()); + $contentViewBuilder = $this->createContentViewBuilder($contentMetadataInspector->reveal(), $securityChecker->reveal()); $views = $contentViewBuilder->createViews( Example::class,