Skip to content

Commit

Permalink
fix: Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn committed Apr 23, 2024
1 parent 9d104aa commit 0f7966d
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 85 deletions.
50 changes: 24 additions & 26 deletions eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,37 @@
* Performs mapping of Content objects.
*
* @phpstan-type TVersionedLanguageFieldDefinitionsMap array<
int, array<
int, array<
string, array<
int, \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition,
>
>
>
>
* int, array<
* int, array<
* string, array<
* int, \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition,
* >
* >
* >
* >
* @phpstan-type TVersionedFieldMap array<
int, array<
int, array<
int, \eZ\Publish\SPI\Persistence\Content\Field,
>
>
>
* int, array<
* int, array<
* int, \eZ\Publish\SPI\Persistence\Content\Field,
* >
* >
* >
* @phpstan-type TVersionedNameMap array<
int, array<
int, array<
string, array<int, string>
>
>
>
* int, array<
* int, array<
* string, array<int, string>
* >
* >
* >
* @phpstan-type TContentInfoMap array<int, \eZ\Publish\SPI\Persistence\Content\ContentInfo>
* @phpstan-type TVersionInfoMap array<
int, array<
int, \eZ\Publish\SPI\Persistence\Content\VersionInfo,
>
>
* int, array<
* int, \eZ\Publish\SPI\Persistence\Content\VersionInfo,
* >
* >
*/
class Mapper
{
public const EMPTY_FIELD_ID = -1;

/**
* FieldValue converter registry.
*
Expand Down
39 changes: 20 additions & 19 deletions eZ/Publish/Core/Persistence/Legacy/Tests/Content/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use function count;
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
use eZ\Publish\Core\Persistence\Legacy\Bookmark\Handler;
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry;
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway;
Expand Down Expand Up @@ -97,8 +98,8 @@ public function testCreateVersionInfoForContent()
],
$versionInfo
);
$this->assertGreaterThanOrEqual($time, $versionInfo->creationDate);
$this->assertGreaterThanOrEqual($time, $versionInfo->modificationDate);
self::assertGreaterThanOrEqual($time, $versionInfo->creationDate);
self::assertGreaterThanOrEqual($time, $versionInfo->modificationDate);
}

/**
Expand Down Expand Up @@ -162,7 +163,7 @@ public function testConvertToStorageValue()
);
$res = $mapper->convertToStorageValue($field);

$this->assertInstanceOf(
self::assertInstanceOf(
StorageFieldValue::class,
$res
);
Expand Down Expand Up @@ -203,7 +204,7 @@ public function testExtractContentFromRows()

$expected = [$this->getContentExtractReference()];

$this->assertEquals(
self::assertEquals(
$expected,
$result
);
Expand Down Expand Up @@ -248,7 +249,7 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void
'versionNo' => 2,
]);

$this->assertEquals(
self::assertEquals(
[
$expectedContent,
],
Expand Down Expand Up @@ -296,7 +297,7 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool {
})
);

$this->assertEquals(
self::assertEquals(
[
$expectedContent,
],
Expand Down Expand Up @@ -330,25 +331,25 @@ public function testExtractContentFromRowsMultipleVersions()
);
$result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture);

$this->assertCount(
self::assertCount(
2,
$result
);

$this->assertEquals(
self::assertEquals(
11,
$result[0]->versionInfo->contentInfo->id
);
$this->assertEquals(
self::assertEquals(
11,
$result[1]->versionInfo->contentInfo->id
);

$this->assertEquals(
self::assertEquals(
1,
$result[0]->versionInfo->versionNo
);
$this->assertEquals(
self::assertEquals(
2,
$result[1]->versionInfo->versionNo
);
Expand Down Expand Up @@ -390,7 +391,7 @@ public function testCreateCreateStructFromContent()

$struct = $mapper->createCreateStructFromContent($content);

$this->assertInstanceOf(CreateStruct::class, $struct);
self::assertInstanceOf(CreateStruct::class, $struct);

return [
'original' => $content,
Expand Down Expand Up @@ -429,7 +430,7 @@ public function testCreateCreateStructFromContentBasicProperties($data)
*/
public function testCreateCreateStructFromContentParentLocationsEmpty($data)
{
$this->assertEquals(
self::assertEquals(
[],
$data['result']->locations
);
Expand All @@ -441,7 +442,7 @@ public function testCreateCreateStructFromContentParentLocationsEmpty($data)
*/
public function testCreateCreateStructFromContentFieldCount($data)
{
$this->assertEquals(
self::assertEquals(
count($data['original']->fields),
count($data['result']->fields)
);
Expand All @@ -454,7 +455,7 @@ public function testCreateCreateStructFromContentFieldCount($data)
public function testCreateCreateStructFromContentFieldsNoId($data)
{
foreach ($data['result']->fields as $field) {
$this->assertNull($field->id);
self::assertNull($field->id);
}
}

Expand All @@ -466,7 +467,7 @@ public function testExtractRelationsFromRows()

$res = $mapper->extractRelationsFromRows($rows);

$this->assertEquals(
self::assertEquals(
$this->getRelationExtractReference(),
$res
);
Expand All @@ -485,7 +486,7 @@ public function testCreateCreateStructFromContentWithPreserveOriginalLanguage()

$struct = $mapper->createCreateStructFromContent($content, true);

$this->assertInstanceOf(CreateStruct::class, $struct);
self::assertInstanceOf(CreateStruct::class, $struct);
$this->assertStructsEqual($content->versionInfo->contentInfo, $struct, ['sectionId', 'ownerId']);
self::assertNotEquals($content->versionInfo->contentInfo->remoteId, $struct->remoteId);
self::assertSame($content->versionInfo->contentInfo->contentTypeId, $struct->typeId);
Expand Down Expand Up @@ -719,7 +720,7 @@ protected function getEventDispatcher(): EventDispatcherInterface
$eventDispatcher->addSubscriber(
new ResolveVirtualFieldSubscriber(
$this->getValueConverterRegistryMock(),
new StorageRegistry([]),
$this->createMock(StorageRegistry::class),
$this->createMock(Gateway::class)
)
);
Expand Down Expand Up @@ -790,7 +791,7 @@ static function ($languageCode) use ($languages) {
/**
* @return \eZ\Publish\SPI\Persistence\Content\Type\Handler&\PHPUnit\Framework\MockObject\MockObject
*/
protected function getContentTypeHandler()
protected function getContentTypeHandler(): Content\Type\Handler
{
return $this->createMock(Content\Type\Handler::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/**
* Test case for Content Handler.
*
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler
*/
class StorageHandlerTest extends TestCase
{
Expand Down Expand Up @@ -47,10 +49,7 @@ class StorageHandlerTest extends TestCase
*/
protected $versionInfoMock;

/**
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler::storeFieldData
*/
public function testStoreFieldData()
public function testStoreFieldData(): void
{
$storageMock = $this->getStorageMock();
$storageRegistryMock = $this->getStorageRegistryMock();
Expand All @@ -76,10 +75,7 @@ public function testStoreFieldData()
$handler->storeFieldData($this->getVersionInfoMock(), $field);
}

/**
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler::getFieldData
*/
public function testGetFieldDataAvailable()
public function testGetFieldDataAvailable(): void
{
$storageMock = $this->getStorageMock();
$storageRegistryMock = $this->getStorageRegistryMock();
Expand Down Expand Up @@ -109,10 +105,7 @@ public function testGetFieldDataAvailable()
$handler->getFieldData($this->getVersionInfoMock(), $field);
}

/**
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler::getFieldData
*/
public function testGetFieldDataNotAvailable()
public function testGetFieldDataNotAvailable(): void
{
$storageMock = $this->getStorageMock();
$storageRegistryMock = $this->getStorageRegistryMock();
Expand All @@ -137,10 +130,7 @@ public function testGetFieldDataNotAvailable()
$handler->getFieldData($this->getVersionInfoMock(), $field);
}

/**
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler::getFieldData
*/
public function testGetFieldDataNotAvailableForVirtualField()
public function testGetFieldDataNotAvailableForVirtualField(): void
{
$storageMock = $this->getStorageMock();
$storageRegistryMock = $this->getStorageRegistryMock();
Expand All @@ -164,10 +154,7 @@ public function testGetFieldDataNotAvailableForVirtualField()
$handler->getFieldData($this->getVersionInfoMock(), $field);
}

/**
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler::deleteFieldData
*/
public function testDeleteFieldData()
public function testDeleteFieldData(): void
{
$storageMock = $this->getStorageMock();
$storageRegistryMock = $this->getStorageRegistryMock();
Expand All @@ -194,7 +181,7 @@ public function testDeleteFieldData()
*
* @return \eZ\Publish\Core\Persistence\Legacy\Content\StorageHandler
*/
protected function getStorageHandler()
protected function getStorageHandler(): StorageHandler
{
if (!isset($this->storageHandler)) {
$this->storageHandler = new StorageHandler(
Expand All @@ -209,9 +196,9 @@ protected function getStorageHandler()
/**
* Returns a context mock.
*
* @return array
* @return int[]
*/
protected function getContextMock()
protected function getContextMock(): array
{
return [23, 42];
}
Expand All @@ -221,7 +208,7 @@ protected function getContextMock()
*
* @return \eZ\Publish\Core\Persistence\Legacy\Content\StorageRegistry
*/
protected function getStorageRegistryMock()
protected function getStorageRegistryMock(): StorageRegistry
{
if (!isset($this->storageRegistryMock)) {
$this->storageRegistryMock = $this->getMockBuilder(StorageRegistry::class)
Expand All @@ -238,7 +225,7 @@ protected function getStorageRegistryMock()
*
* @return \eZ\Publish\SPI\FieldType\FieldStorage
*/
protected function getStorageMock()
protected function getStorageMock(): FieldStorage
{
if (!isset($this->storageMock)) {
$this->storageMock = $this->createMock(FieldStorage::class);
Expand All @@ -247,7 +234,7 @@ protected function getStorageMock()
return $this->storageMock;
}

protected function getVersionInfoMock()
protected function getVersionInfoMock(): VersionInfo
{
if (!isset($this->versionInfoMock)) {
$this->versionInfoMock = $this->createMock(VersionInfo::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function getEventDispatcher(): EventDispatcherInterface
$eventDispatcher->addSubscriber(
new ResolveVirtualFieldSubscriber(
$this->getConverterRegistry(),
new StorageRegistry([]),
$this->createMock(StorageRegistry::class),
$this->createMock(Gateway::class)
)
);
Expand Down
6 changes: 3 additions & 3 deletions eZ/Publish/Core/settings/storage_engines/legacy/content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ services:

Ibexa\Core\Persistence\Legacy\Content\Mapper\ResolveVirtualFieldSubscriber:
arguments:
- "@ezpublish.persistence.legacy.field_value_converter.registry"
- "@ezpublish.persistence.external_storage_registry"
- "@ezpublish.persistence.legacy.content.gateway"
$converterRegistry: "@ezpublish.persistence.legacy.field_value_converter.registry"
$storageRegistry: "@ezpublish.persistence.external_storage_registry"
$contentGateway: "@ezpublish.persistence.legacy.content.gateway"
tags:
- { name: kernel.event_subscriber }

Expand Down
8 changes: 7 additions & 1 deletion src/contracts/Event/Mapper/ResolveMissingFieldEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ final class ResolveMissingFieldEvent extends Event
/** @var string */
private $languageCode;

/** @var array */
/** @var array<mixed> */
private $context;

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

/**
* @param array<mixed> $context
*/
public function __construct(
Content $content,
FieldDefinition $fieldDefinition,
Expand Down Expand Up @@ -56,6 +59,9 @@ public function getLanguageCode(): string
return $this->languageCode;
}

/**
* @return array<mixed>
*/
public function getContext(): array
{
return $this->context;
Expand Down
Loading

0 comments on commit 0f7966d

Please sign in to comment.