Skip to content

Commit

Permalink
Add ContentNotFoundException if dimensions not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Dec 11, 2019
1 parent e45d7a3 commit d796430
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Content/Application/ContentLoader/ContentLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function __construct(
public function load(ContentInterface $content, array $dimensionAttributes): ContentViewInterface
{
$dimensionCollection = $this->dimensionRepository->findByAttributes($dimensionAttributes);

if (0 === \count($dimensionCollection)) {
throw new ContentNotFoundException($content, $dimensionAttributes);
}

$contentDimensionCollection = $this->contentDimensionRepository->load($content, $dimensionCollection);

if (0 === \count($contentDimensionCollection)) {
Expand Down
5 changes: 5 additions & 0 deletions Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public function apply(
string $transitionName
): ContentViewInterface {
$dimensionCollection = $this->dimensionRepository->findByAttributes($dimensionAttributes);

if (0 === \count($dimensionCollection)) {
throw new ContentNotFoundException($content, $dimensionAttributes);
}

$contentDimensionCollection = $this->contentDimensionRepository->load($content, $dimensionCollection);

$localizedContentDimension = $contentDimensionCollection->getLocalizedContentDimension();
Expand Down
28 changes: 28 additions & 0 deletions Tests/Unit/Content/Application/ContentLoader/ContentLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ public function testLoad(): void
$this->assertSame($contentView->reveal(), $createContentMessageHandler->load($content->reveal(), $attributes));
}

public function testLoadDimensionNotFound(): void
{
$this->expectException(ContentNotFoundException::class);

$content = $this->prophesize(ContentInterface::class);

$attributes = [
'locale' => 'de',
];

$dimensionCollection = new DimensionCollection($attributes, []);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
$dimensionRepository->findByAttributes($attributes)->willReturn($dimensionCollection)->shouldBeCalled();

$contentDimensionRepository = $this->prophesize(ContentDimensionRepositoryInterface::class);
$contentView = $this->prophesize(ContentViewInterface::class);
$viewFactory = $this->prophesize(ViewFactoryInterface::class);

$createContentMessageHandler = $this->createContentLoaderInstance(
$dimensionRepository->reveal(),
$contentDimensionRepository->reveal(),
$viewFactory->reveal()
);

$this->assertSame($contentView->reveal(), $createContentMessageHandler->load($content->reveal(), $attributes));
}

public function testLoadNotFound(): void
{
$this->expectException(ContentNotFoundException::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,37 @@ public function testTransitionNoLocalizedContentDimension(): void
);
}

public function testTransitionNoDimensions(): void
{
$this->expectException(ContentNotFoundException::class);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
$contentDimensionRepository = $this->prophesize(ContentDimensionRepositoryInterface::class);
$viewFactory = $this->prophesize(ViewFactoryInterface::class);

$contentWorkflow = $this->createContentWorkflowInstance(
$dimensionRepository->reveal(),
$contentDimensionRepository->reveal(),
$viewFactory->reveal()
);

$content = $this->prophesize(ContentInterface::class);
$dimensionAttributes = ['locale' => 'de', 'stage' => 'draft'];
$transitionName = 'request_for_review';

$dimensionCollection = new DimensionCollection($dimensionAttributes, []);

$dimensionRepository->findByAttributes($dimensionAttributes)
->willReturn($dimensionCollection)
->shouldBeCalled();

$contentWorkflow->apply(
$content->reveal(),
$dimensionAttributes,
$transitionName
);
}

public function testNotExistTransition(): void
{
$this->expectException(ContentNotExistTransitionException::class);
Expand Down

0 comments on commit d796430

Please sign in to comment.