Skip to content

Commit

Permalink
Fixed Serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p authored and alongosz committed Jul 15, 2024
1 parent 1d579cc commit dddd5ff
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\MatcherStub;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

final class CompoundMatcherNormalizerTest extends TestCase
{
public function testNormalization(): void
{
$matcher = new CompoundStub([]);
$matcher->setSubMatchers([
'foo' => new MatcherStub('foo'),
'bar' => new MatcherStub('bar'),
'baz' => new MatcherStub('baz'),
]);
$matcher->setSubMatchers(
[
'foo' => new MatcherStub('foo'),
'bar' => new MatcherStub('bar'),
'baz' => new MatcherStub('baz'),
]
);

$normalizer = new CompoundMatcherNormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new SerializerStub(),
new ObjectNormalizer(),
]
);

self::assertEquals(
[
Expand All @@ -40,7 +50,7 @@ public function testNormalization(): void
'config' => [],
'matchersMap' => [],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand All @@ -52,6 +62,9 @@ public function testSupportsNormalization(): void
self::assertFalse($normalizer->supportsNormalization($this->createMock(Matcher::class)));
}

/**
* @throws \JsonException
*/
public function testSupportsDenormalization(): void
{
$normalizer = new CompoundMatcherNormalizer();
Expand All @@ -63,7 +76,8 @@ public function testSupportsDenormalization(): void
],
'config' => [],
'matchersMap' => [],
]
],
JSON_THROW_ON_ERROR
);

self::assertTrue($normalizer->supportsDenormalization($data, Compound::class, 'json'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@
use Ibexa\Core\MVC\Symfony\Routing\SimplifiedRequest;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\HostElement;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

/**
* @covers \Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer
*/
final class HostElementNormalizerTest extends TestCase
{
public function testNormalization(): void
{
$normalizer = new HostElementNormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new ObjectNormalizer(),
]
);

$matcher = new HostElement(2);
// Set request and invoke match to initialize HostElement::$hostElements
Expand All @@ -35,7 +44,7 @@ public function testNormalization(): void
'dev',
],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
use Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\HostText;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use Ibexa\Tests\Core\Search\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

final class HostTextNormalizerTest extends TestCase
{
public function testNormalize(): void
{
$normalizer = new HostTextNormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new ObjectNormalizer(),
]
);

$matcher = new HostText([
'prefix' => 'foo',
Expand All @@ -33,7 +39,7 @@ public function testNormalize(): void
'suffix' => 'bar',
],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
use Ibexa\Core\MVC\Symfony\Component\Serializer\RegexHostNormalizer;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\Regex\Host;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use Ibexa\Tests\Core\Search\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

final class RegexHostNormalizerTest extends TestCase
{
public function testNormalize(): void
{
$normalizer = new RegexHostNormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new ObjectNormalizer(),
]
);

$matcher = new Host([
'regex' => '/^Foo(.*)/(.*)/',
Expand All @@ -33,7 +39,7 @@ public function testNormalize(): void
'itemNumber' => 2,
],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
use Ibexa\Core\MVC\Symfony\Component\Serializer\RegexURINormalizer;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\Regex\URI;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use Ibexa\Tests\Core\Search\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

final class RegexURINormalizerTest extends TestCase
{
public function testNormalize(): void
{
$normalizer = new RegexURINormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new ObjectNormalizer(),
]
);

$matcher = new URI([
'regex' => '/^Foo(.*)/(.*)/',
Expand All @@ -33,7 +39,7 @@ public function testNormalize(): void
'itemNumber' => 2,
],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function normalize($object, string $format = null, array $context = []):

public function supportsNormalization($data, string $format = null): bool
{
return true;
return $data instanceof MatcherStub;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
use Ibexa\Core\MVC\Symfony\Routing\SimplifiedRequest;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\URIElement;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

final class URIElementNormalizerTest extends TestCase
{
public function testNormalization(): void
{
$normalizer = new URIElementNormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new ObjectNormalizer(),
]
);

$matcher = new URIElement(2);
// Set request and invoke match to initialize HostElement::$hostElements
Expand All @@ -32,7 +38,7 @@ public function testNormalization(): void
'elementNumber' => 2,
'uriElements' => ['foo', 'bar'],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
use Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\URIText;
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
use Ibexa\Tests\Core\Search\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

final class URITextNormalizerTest extends TestCase
{
public function testNormalize(): void
{
$normalizer = new URITextNormalizer();
$normalizer->setSerializer(new SerializerStub());
$serializer = new Serializer(
[
$normalizer,
new ObjectNormalizer(),
]
);

$matcher = new URIText([
'prefix' => 'foo',
Expand All @@ -33,7 +39,7 @@ public function testNormalize(): void
'suffix' => 'bar',
],
],
$normalizer->normalize($matcher)
$serializer->normalize($matcher)
);
}

Expand Down

0 comments on commit dddd5ff

Please sign in to comment.