Skip to content

Commit

Permalink
OXDEV-8728 Implemented collection serializer service
Browse files Browse the repository at this point in the history
  • Loading branch information
RahatHameed committed Sep 24, 2024
1 parent 9bc8ebd commit 3699ee8
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OxidEsales\GdprOptinModule\UserData\DataType\ResultFileInterface;
use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface;

interface CollectionSerializerInterface
interface CollectionSerializerServiceInterface
{
public function serializeCollection(TableCollectionInterface $data): ResultFileInterface;
}
22 changes: 22 additions & 0 deletions src/UserData/Service/JsonCollectionSerializerService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GdprOptinModule\UserData\Service;

use OxidEsales\GdprOptinModule\UserData\DataType\ResultFile;
use OxidEsales\GdprOptinModule\UserData\DataType\ResultFileInterface;
use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface;

class JsonCollectionSerializerService implements CollectionSerializerServiceInterface
{
public function serializeCollection(TableCollectionInterface $data): ResultFileInterface
{
return new ResultFile($data->getCollectionName(), json_encode($data->getCollection()));
}
}
5 changes: 4 additions & 1 deletion src/UserData/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,7 @@ services:
OxidEsales\GdprOptinModule\UserData\Service\CollectionAggregationServiceInterface:
class: OxidEsales\GdprOptinModule\UserData\Service\CollectionAggregationService
arguments:
$collectors: !tagged oe.gdpr.user_data
$collectors: !tagged oe.gdpr.user_data

OxidEsales\GdprOptinModule\UserData\Service\CollectionSerializerServiceInterface:
class: OxidEsales\GdprOptinModule\UserData\Service\JsonCollectionSerializerService
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GdprOptinModule\Tests\Unit\UserData\Service;

use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface;
use OxidEsales\GdprOptinModule\UserData\Service\JsonCollectionSerializerService;
use PHPUnit\Framework\TestCase;

final class JsonCollectionSerializerServiceTest extends TestCase
{
public function testSerializeCollection(): void
{
$expectedCollectionName = uniqid();
$expectedCollection = [
['OXID' => uniqid(), 'OXDELFNAME' => uniqid(), 'OXDELLNAME' => uniqid()],
['OXID' => uniqid(), 'OXDELFNAME' => uniqid(), 'OXDELLNAME' => uniqid()]
];

$tableCollectionMock = $this->createConfiguredMock(TableCollectionInterface::class, [
'getCollection' => $expectedCollection,
'getCollectionName' => $expectedCollectionName,
]);

$sut = new JsonCollectionSerializerService();

$actualResult = $sut->serializeCollection($tableCollectionMock);

$this->assertSame($expectedCollectionName, $actualResult->getFileName());
$this->assertSame(json_encode($expectedCollection), $actualResult->getContent());
}
}

0 comments on commit 3699ee8

Please sign in to comment.