Skip to content

Commit

Permalink
IBX-9337: 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 authored Jan 9, 2025
1 parent 90f0c81 commit cd57d58
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 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
55 changes: 55 additions & 0 deletions tests/integration/Core/Repository/SerializationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Core\Repository;

use Ibexa\Tests\Integration\Core\RepositoryTestCase;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\SerializerInterface;

final class SerializationTest extends RepositoryTestCase
{
public function testSerialization(): void
{
$serializer = $this->getContainer()->get(SerializerInterface::class);
self::assertInstanceOf(SerializerInterface::class, $serializer);
$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 cd57d58

Please sign in to comment.