Skip to content

Commit

Permalink
fix: CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn committed Apr 9, 2024
1 parent e24c72b commit 70d1af8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
7 changes: 3 additions & 4 deletions eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*/
class Mapper
{
const EMPTY_FIELD_ID = -1;
public const EMPTY_FIELD_ID = -1;

/**
* FieldValue converter registry.
Expand All @@ -80,7 +80,7 @@ class Mapper
private $contentTypeHandler;

/**
* @var EventDispatcherInterface
* @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
private $eventDispatcher;

Expand Down Expand Up @@ -329,10 +329,9 @@ private function buildContentObjects(
);

$field = $event->getField();
if ($field !== null) {
if ($field !== null) {
$content->fields[] = $field;
}

}
}

Expand Down
48 changes: 41 additions & 7 deletions eZ/Publish/Core/Persistence/Legacy/Tests/Content/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use eZ\Publish\SPI\Persistence\Content\Relation as SPIRelation;
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
* Test case for Mapper.
Expand Down Expand Up @@ -149,7 +151,12 @@ public function testConvertToStorageValue()
$field->type = 'some-type';
$field->value = new FieldValue();

$mapper = new Mapper($reg, $this->getLanguageHandler(), $this->getContentTypeHandler());
$mapper = new Mapper(
$reg,
$this->getLanguageHandler(),
$this->getContentTypeHandler(),
$this->getEventDispatcher(),
);
$res = $mapper->convertToStorageValue($field);

$this->assertInstanceOf(
Expand Down Expand Up @@ -183,7 +190,12 @@ public function testExtractContentFromRows()
'ezkeyword',
], count($rowsFixture) - 1);

$mapper = new Mapper($reg, $this->getLanguageHandler(), $contentTypeHandlerMock);
$mapper = new Mapper(
$reg,
$this->getLanguageHandler(),
$contentTypeHandlerMock,
$this->getEventDispatcher()
);
$result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture);

$expected = [$this->getContentExtractReference()];
Expand Down Expand Up @@ -217,7 +229,12 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void
'eznumber',
], count($rowsFixture));

$mapper = new Mapper($reg, $this->getLanguageHandler(), $contentTypeHandlerMock);
$mapper = new Mapper(
$reg,
$this->getLanguageHandler(),
$contentTypeHandlerMock,
$this->getEventDispatcher()
);
$result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture);

$expectedContent = $this->getContentExtractReference();
Expand Down Expand Up @@ -260,7 +277,12 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool {
'ezkeyword',
], count($rowsFixture) - 2);

$mapper = new Mapper($reg, $this->getLanguageHandler(), $contentTypeHandlerMock);
$mapper = new Mapper(
$reg,
$this->getLanguageHandler(),
$contentTypeHandlerMock,
$this->getEventDispatcher()
);
$result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture);

$expectedContent = $this->getContentExtractReference();
Expand Down Expand Up @@ -296,7 +318,12 @@ public function testExtractContentFromRowsMultipleVersions()
$contentTypeHandlerMock = $this->getContentTypeHandler();
$contentTypeHandlerMock->method('load')->willReturn($contentType);

$mapper = new Mapper($reg, $this->getLanguageHandler(), $contentTypeHandlerMock);
$mapper = new Mapper(
$reg,
$this->getLanguageHandler(),
$contentTypeHandlerMock,
$this->getEventDispatcher()
);
$result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture);

$this->assertCount(
Expand Down Expand Up @@ -477,7 +504,8 @@ public function testExtractContentInfoFromRow(array $fixtures, $prefix)
$mapper = new Mapper(
$this->getValueConverterRegistryMock(),
$this->getLanguageHandler(),
$this->getContentTypeHandler()
$this->getContentTypeHandler(),
$this->getEventDispatcher()
);
self::assertEquals($contentInfoReference, $mapper->extractContentInfoFromRow($fixtures, $prefix));
}
Expand Down Expand Up @@ -638,7 +666,8 @@ protected function getMapper($valueConverter = null)
return new Mapper(
$this->getValueConverterRegistryMock(),
$this->getLanguageHandler(),
$this->getContentTypeHandler()
$this->getContentTypeHandler(),
$this->getEventDispatcher()
);
}

Expand Down Expand Up @@ -676,6 +705,11 @@ protected function getRelationCreateStructFixture()
return $struct;
}

protected function getEventDispatcher(): EventDispatcherInterface
{
return new EventDispatcher();
}

/**
* Returns a language handler mock.
*
Expand Down
12 changes: 8 additions & 4 deletions src/contracts/Event/Mapper/ResolveMissingFieldEvent.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Contracts\Core\Event\Mapper;

use eZ\Publish\SPI\Persistence\Content;
Expand All @@ -9,10 +13,10 @@

final class ResolveMissingFieldEvent extends Event
{
/** @var Content */
/** @var \eZ\Publish\SPI\Persistence\Content */
private $content;

/** @var FieldDefinition */
/** @var \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition */
private $fieldDefinition;

/** @var string */
Expand All @@ -21,7 +25,7 @@ final class ResolveMissingFieldEvent extends Event
/** @var array */
private $context;

/** @var Field|null */
/** @var \eZ\Publish\SPI\Persistence\Content\Field|null */
private $field;

public function __construct(
Expand Down Expand Up @@ -66,4 +70,4 @@ public function getField(): ?Field
{
return $this->field;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

final class ResolveVirtualFieldSubscriber implements EventSubscriberInterface
{
/** @var ConverterRegistry */
/** @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry */
private $converterRegistry;

/** @var StorageRegistry */
/** @var \eZ\Publish\Core\Persistence\Legacy\Content\StorageRegistry */
private $storageRegistry;

/** @var ContentGateway */
/** @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway */
private $contentGateway;

public function __construct(
Expand All @@ -48,7 +48,7 @@ public static function getSubscribedEvents(): array
ResolveMissingFieldEvent::class => [
['persistExternalStorageField', -100],
['resolveVirtualField', 0],
]
],
];
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public function persistExternalStorageField(ResolveMissingFieldEvent $event): vo
}

/**
* @throws NotFound
* @throws \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound
*/
private function createEmptyField(
VersionInfo $versionInfo,
Expand All @@ -126,7 +126,7 @@ private function createEmptyField(
}

/**
* @throws NotFound
* @throws \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound
*/
private function getDefaultValue(FieldDefinition $fieldDefinition): FieldValue
{
Expand All @@ -151,4 +151,4 @@ private function getDefaultStorageValue(): StorageFieldValue

return $storageValue;
}
}
}

0 comments on commit 70d1af8

Please sign in to comment.