Skip to content

Commit

Permalink
Fix JSON column UTF-8 twice encoded (#120)
Browse files Browse the repository at this point in the history
* Fix JSON column UTF-8 twice encoded

Co-authored-by: a.dmitryuk <[email protected]>
  • Loading branch information
dmitryuk and a.dmitryuk authored Oct 31, 2022
1 parent 4072a4e commit 2d4cfa1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private function value(EntityManagerInterface $entityManager, Type $type, $value

break;

case DoctrineHelper::getDoctrineType('JSON'):
return $value;

default:
$convertedValue = $type->convertToDatabaseValue($value, $platform);
}
Expand Down
53 changes: 53 additions & 0 deletions tests/Provider/Doctrine/Issues/Issue119Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace DH\Auditor\Tests\Provider\Doctrine\Issues;

use DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionProcessor;
use DH\Auditor\Provider\Doctrine\Model\Transaction;
use DH\Auditor\Provider\Doctrine\Persistence\Reader\Reader;
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\DummyEntity;
use DH\Auditor\Tests\Provider\Doctrine\Traits\Schema\DefaultSchemaSetupTrait;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
* @small
*/
final class Issue119Test extends TestCase
{
use DefaultSchemaSetupTrait;

public function testIssue119(): void
{
$reader = new Reader($this->provider);
$processor = new TransactionProcessor($this->provider);
$entityManager = $this->createEntityManager();
$transaction = new Transaction($entityManager);
$entity = new DummyEntity();
$transaction->insert($entity, [
'json_array' => [null, [
'example' => '',
]],
]);
$processor->process($transaction);
$audits = $reader->createQuery(DummyEntity::class)->execute();
self::assertCount(1, $audits, 'results count ok.');

/** @var \DH\Auditor\Model\Entry $audit */
$audit = $audits[0];
$diffs = $audit->getDiffs()['json_array'];
self::assertSame([
'example' => '',
], $diffs['new']);
}

private function configureEntities(): void
{
$this->provider->getConfiguration()->setEntities([
DummyEntity::class => ['enabled' => true],
]);
}
}

0 comments on commit 2d4cfa1

Please sign in to comment.