Skip to content

Commit

Permalink
Fixes after review of nnatter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Dec 22, 2020
1 parent 18a5e68 commit f6fcbd7
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Content/Application/ContentMerger/ContentMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle
$merger->merge($mergedDimensionContent, $dimensionContent);
}

foreach ($dimensionContent::getDefaultAttributes() as $key => $value) {
foreach ($dimensionContentCollection->getDimensionAttributes() as $key => $value) {
$this->propertyAccessor->setValue(
$mergedDimensionContent,
$key,
Expand Down
2 changes: 1 addition & 1 deletion Content/Domain/Model/DimensionContentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
) {
$this->dimensionContents = new ArrayCollection($dimensionContents);
$this->dimensionContentClass = $dimensionContentClass;
$this->defaultDimensionAttributes = \call_user_func([$dimensionContentClass, 'getDefaultAttributes']);
$this->defaultDimensionAttributes = $dimensionContentClass::getDefaultAttributes();

$this->unlocalizedDimensionContent = $this->dimensionContents->filter(
function (DimensionContentInterface $dimensionContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ interface DimensionContentRepositoryInterface
*/
public function load(
ContentRichEntityInterface $contentRichEntity,
array $dimensionAttributes = []
array $dimensionAttributes
): DimensionContentCollectionInterface;
}
14 changes: 7 additions & 7 deletions Content/Infrastructure/Doctrine/DimensionContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(

public function load(
ContentRichEntityInterface $contentRichEntity,
array $dimensionAttributes = []
array $dimensionAttributes
): DimensionContentCollectionInterface {
$dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass(\get_class($contentRichEntity));
$mappingProperty = $this->contentMetadataInspector->getDimensionContentPropertyName(\get_class($contentRichEntity));
Expand All @@ -57,16 +57,16 @@ public function load(
->where('content.id = :id')
->setParameter('id', $contentRichEntity->getId());

$attributes = $this->getAttributes($dimensionContentClass, $dimensionAttributes);
$queryBuilder->addCriteria($this->getAttributesCriteria('dimensionContent', $attributes));
$this->addSortBy($queryBuilder, $attributes);
$effectiveAttributes = $this->getEffectiveAttributes($dimensionContentClass, $dimensionAttributes);
$queryBuilder->addCriteria($this->getAttributesCriteria('dimensionContent', $effectiveAttributes));
$this->addSortBy($queryBuilder, $effectiveAttributes);

/** @var DimensionContentInterface[] $dimensionContents */
$dimensionContents = $queryBuilder->getQuery()->getResult();

return new DimensionContentCollection(
$dimensionContents,
$attributes,
$effectiveAttributes,
$dimensionContentClass
);
}
Expand Down Expand Up @@ -111,9 +111,9 @@ private function getAttributesCriteria(string $alias, array $attributes): Criter
*
* @return mixed[]
*/
private function getAttributes(string $className, array $attributes): array
private function getEffectiveAttributes(string $className, array $attributes): array
{
$defaultValues = \call_user_func([$className, 'getDefaultAttributes']);
$defaultValues = $className::getDefaultAttributes();

// Ignore any key which is is which has no default values
$attributes = array_intersect_key($attributes, $defaultValues);
Expand Down
34 changes: 0 additions & 34 deletions Tests/Functional/BaseTestCase.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\CategoryFactoryInterface;
use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;

class CategoryFactoryTest extends BaseTestCase
class CategoryFactoryTest extends SuluTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example;
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent;
use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;

class DimensionContentRepositoryTest extends BaseTestCase
class DimensionContentRepositoryTest extends SuluTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Doctrine;

use Sulu\Bundle\ContentBundle\Content\Domain\Factory\TagFactoryInterface;
use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\TagBundle\Tag\TagInterface;
use Sulu\Bundle\TagBundle\Tag\TagRepositoryInterface;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;

class TagFactoryTest extends BaseTestCase
class TagFactoryTest extends SuluTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Sulu\Sitemap;

use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Sitemap\ContentSitemapProvider;
use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\ContentBundle\Tests\Traits\AssertSnapshotTrait;
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use Sulu\Bundle\WebsiteBundle\Sitemap\Sitemap;
use Sulu\Bundle\WebsiteBundle\Sitemap\SitemapAlternateLink;
use Sulu\Bundle\WebsiteBundle\Sitemap\SitemapUrl;

class ContentSitemapProviderTest extends BaseTestCase
class ContentSitemapProviderTest extends SuluTestCase
{
use AssertSnapshotTrait;

const SCHEME = 'https';
const HOST = 'localhost';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@

use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\SmartContent\Provider\ContentDataProvider;
use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\ContentBundle\Tests\Traits\AssertSnapshotTrait;
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateCategoryTrait;
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait;
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateTagTrait;
use Sulu\Bundle\TagBundle\Tag\TagInterface;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use Sulu\Component\SmartContent\ArrayAccessItem;
use Sulu\Component\SmartContent\DataProviderResult;

class ContentDataProviderTest extends BaseTestCase
class ContentDataProviderTest extends SuluTestCase
{
use AssertSnapshotTrait;
use CreateCategoryTrait;
use CreateExampleTrait;
use CreateTagTrait;
Expand Down
7 changes: 5 additions & 2 deletions Tests/Functional/Integration/ExampleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@

namespace Sulu\Bundle\ContentBundle\Tests\Functional\Integration;

use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\ContentBundle\Tests\Traits\AssertSnapshotTrait;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;

/**
* The integration test should have no impact on the coverage so we set it to coversNothing.
*
* @coversNothing
*/
class ExampleControllerTest extends BaseTestCase
class ExampleControllerTest extends SuluTestCase
{
use AssertSnapshotTrait;

/**
* @var KernelBrowser
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testMerge(): void
$merger1->merge($mergedDimensionContent->reveal(), $dimensionContent2)->shouldBeCalled();
$merger2->merge($mergedDimensionContent->reveal(), $dimensionContent2)->shouldBeCalled();

$mergedDimensionContent->setLocale(null) // TODO find a way to avoid this call
$mergedDimensionContent->setLocale(null) // TODO find a way to avoid this call (ExampleControllerTest::testPostTriggerUnpublish) currently files without this
->shouldBeCalled();
$mergedDimensionContent->setLocale('en')
->shouldBeCalled();
Expand All @@ -75,7 +75,10 @@ public function testMerge(): void
$dimensionContentCollection = new DimensionContentCollection([
$dimensionContent1,
$dimensionContent2,
], [], \get_class($dimensionContent1));
], [
'locale' => 'en',
'stage' => 'draft',
], \get_class($dimensionContent1));

$this->assertSame(
$mergedDimensionContent->reveal(),
Expand Down

0 comments on commit f6fcbd7

Please sign in to comment.