Skip to content

Commit

Permalink
IBX-9316: Fixed failure to serialize field data post symfony/serializ…
Browse files Browse the repository at this point in the history
…er 5.4.40
  • Loading branch information
Steveb-p committed Dec 23, 2024
1 parent 90f0c81 commit 658783c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/contracts/Repository/Values/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Ibexa\Contracts\Core\Repository\Exceptions\PropertyNotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\PropertyReadOnlyException;
use Symfony\Component\Serializer\Annotation\Ignore as SerializerIgnore;

/**
* The base class for all value objects and structs.
Expand Down Expand Up @@ -46,6 +47,8 @@ public function __construct(array $properties = [])
* @param array $dynamicProperties Additional dynamic properties exposed on the object
*
* @return array
*
* @SerializerIgnore()
*/
protected function getProperties($dynamicProperties = [])
{
Expand Down Expand Up @@ -201,6 +204,8 @@ final public function attributes()
* @param string $property
*
* @return bool
*
* @SerializerIgnore()
*/
final public function hasAttribute($property)
{
Expand Down
13 changes: 8 additions & 5 deletions src/contracts/Test/IbexaKernelTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,23 @@ protected static function getFixtures(): iterable
*
* @return T
*/
final protected static function getServiceByClassName(string $className, ?string $id = null): object
{
final protected static function getServiceByClassName(
string $className,
?string $id = null,
bool $prefix = true
): object {
if (!self::$booted) {
static::bootKernel();
}

$serviceId = self::getTestServiceId($id, $className);
$serviceId = self::getTestServiceId($id, $className, $prefix);
$service = self::getContainer()->get($serviceId);
assert(is_object($service) && is_a($service, $className));

return $service;
}

protected static function getTestServiceId(?string $id, string $className): string
protected static function getTestServiceId(?string $id, string $className, bool $prefix = true): string
{
$kernel = self::$kernel;
if (!$kernel instanceof IbexaTestKernelInterface) {
Expand All @@ -102,7 +105,7 @@ protected static function getTestServiceId(?string $id, string $className): stri

$id = $id ?? $className;

return $kernel->getAliasServiceId($id);
return $prefix ? $kernel->getAliasServiceId($id) : $id;
}

protected static function getDoctrineConnection(): Connection
Expand Down
62 changes: 62 additions & 0 deletions tests/integration/Core/Repository/SerializationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

Check warning on line 1 in tests/integration/Core/Repository/SerializationTest.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.3)

Found violation(s) of type: blank_lines_before_namespace

/**
* @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\Tests\Integration\Core\Repository;

use Ibexa\Contracts\Core\Test\IbexaKernelTestCase;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\SerializerInterface;

final class SerializationTest extends IbexaKernelTestCase
{
protected function setUp(): void
{
self::bootKernel();

self::loadSchema();
self::loadFixtures();

self::setAdministratorUser();
}

public function testSerialization(): void
{
$serializer = self::getServiceByClassName(SerializerInterface::class, 'serializer', false);
$contentService = self::getContentService();

$user = $contentService->loadContent(14);
$field = $user->getField('user_account');
self::assertNotNull($field, 'Field "name" for admin user should not be null');

$result = $serializer->serialize($field, 'json', [JsonEncode::OPTIONS => JSON_PRETTY_PRINT]);
$passwordHash = '$2y$10$FDn9NPwzhq85cLLxfD5Wu.L3SL3Z\/LNCvhkltJUV0wcJj7ciJg2oy';
self::assertSame(
<<<JSON
{
"id": 30,
"fieldDefIdentifier": "user_account",
"value": {
"hasStoredLogin": true,
"contentId": 14,
"login": "admin",
"email": "[email protected]",
"passwordHash": "$passwordHash",
"passwordHashType": "7",
"passwordUpdatedAt": null,
"enabled": true,
"maxLogin": 10,
"plainPassword": null
},
"languageCode": "eng-US",
"fieldTypeIdentifier": "ezuser",
"fieldDefinitionIdentifier": "user_account",
"virtual": false
}
JSON,
$result,
);
}
}

0 comments on commit 658783c

Please sign in to comment.