Skip to content

Commit bb3fa84

Browse files
Steveb-palongosz
authored andcommitted
Fixed Serializer
1 parent e5ad3df commit bb3fa84

8 files changed

+80
-27
lines changed

tests/lib/MVC/Symfony/Component/Serializer/CompoundMatcherNormalizerTest.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,30 @@
1515
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\MatcherStub;
1616
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1717
use PHPUnit\Framework\TestCase;
18+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
19+
use Symfony\Component\Serializer\Serializer;
1820

1921
final class CompoundMatcherNormalizerTest extends TestCase
2022
{
2123
public function testNormalization(): void
2224
{
2325
$matcher = new CompoundStub([]);
24-
$matcher->setSubMatchers([
25-
'foo' => new MatcherStub('foo'),
26-
'bar' => new MatcherStub('bar'),
27-
'baz' => new MatcherStub('baz'),
28-
]);
26+
$matcher->setSubMatchers(
27+
[
28+
'foo' => new MatcherStub('foo'),
29+
'bar' => new MatcherStub('bar'),
30+
'baz' => new MatcherStub('baz'),
31+
]
32+
);
2933

3034
$normalizer = new CompoundMatcherNormalizer();
31-
$normalizer->setSerializer(new SerializerStub());
35+
$serializer = new Serializer(
36+
[
37+
$normalizer,
38+
new SerializerStub(),
39+
new ObjectNormalizer(),
40+
]
41+
);
3242

3343
self::assertEquals(
3444
[
@@ -40,7 +50,7 @@ public function testNormalization(): void
4050
'config' => [],
4151
'matchersMap' => [],
4252
],
43-
$normalizer->normalize($matcher)
53+
$serializer->normalize($matcher)
4454
);
4555
}
4656

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

65+
/**
66+
* @throws \JsonException
67+
*/
5568
public function testSupportsDenormalization(): void
5669
{
5770
$normalizer = new CompoundMatcherNormalizer();
@@ -63,7 +76,8 @@ public function testSupportsDenormalization(): void
6376
],
6477
'config' => [],
6578
'matchersMap' => [],
66-
]
79+
],
80+
JSON_THROW_ON_ERROR
6781
);
6882

6983
self::assertTrue($normalizer->supportsDenormalization($data, Compound::class, 'json'));

tests/lib/MVC/Symfony/Component/Serializer/HostElementNormalizerTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@
1212
use Ibexa\Core\MVC\Symfony\Routing\SimplifiedRequest;
1313
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
1414
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\HostElement;
15-
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1615
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
17+
use Symfony\Component\Serializer\Serializer;
1718

19+
/**
20+
* @covers \Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer
21+
*/
1822
final class HostElementNormalizerTest extends TestCase
1923
{
2024
public function testNormalization(): void
2125
{
2226
$normalizer = new HostElementNormalizer();
23-
$normalizer->setSerializer(new SerializerStub());
27+
$serializer = new Serializer(
28+
[
29+
$normalizer,
30+
new ObjectNormalizer(),
31+
]
32+
);
2433

2534
$matcher = new HostElement(2);
2635
// Set request and invoke match to initialize HostElement::$hostElements
@@ -35,7 +44,7 @@ public function testNormalization(): void
3544
'dev',
3645
],
3746
],
38-
$normalizer->normalize($matcher)
47+
$serializer->normalize($matcher)
3948
);
4049
}
4150

tests/lib/MVC/Symfony/Component/Serializer/HostTextNormalizerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
use Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer;
1212
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
1313
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\HostText;
14-
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1514
use Ibexa\Tests\Core\Search\TestCase;
15+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
16+
use Symfony\Component\Serializer\Serializer;
1617

1718
final class HostTextNormalizerTest extends TestCase
1819
{
1920
public function testNormalize(): void
2021
{
2122
$normalizer = new HostTextNormalizer();
22-
$normalizer->setSerializer(new SerializerStub());
23+
$serializer = new Serializer(
24+
[
25+
$normalizer,
26+
new ObjectNormalizer(),
27+
]
28+
);
2329

2430
$matcher = new HostText([
2531
'prefix' => 'foo',
@@ -33,7 +39,7 @@ public function testNormalize(): void
3339
'suffix' => 'bar',
3440
],
3541
],
36-
$normalizer->normalize($matcher)
42+
$serializer->normalize($matcher)
3743
);
3844
}
3945

tests/lib/MVC/Symfony/Component/Serializer/RegexHostNormalizerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
use Ibexa\Core\MVC\Symfony\Component\Serializer\RegexHostNormalizer;
1212
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
1313
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\Regex\Host;
14-
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1514
use Ibexa\Tests\Core\Search\TestCase;
15+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
16+
use Symfony\Component\Serializer\Serializer;
1617

1718
final class RegexHostNormalizerTest extends TestCase
1819
{
1920
public function testNormalize(): void
2021
{
2122
$normalizer = new RegexHostNormalizer();
22-
$normalizer->setSerializer(new SerializerStub());
23+
$serializer = new Serializer(
24+
[
25+
$normalizer,
26+
new ObjectNormalizer(),
27+
]
28+
);
2329

2430
$matcher = new Host([
2531
'regex' => '/^Foo(.*)/(.*)/',
@@ -33,7 +39,7 @@ public function testNormalize(): void
3339
'itemNumber' => 2,
3440
],
3541
],
36-
$normalizer->normalize($matcher)
42+
$serializer->normalize($matcher)
3743
);
3844
}
3945

tests/lib/MVC/Symfony/Component/Serializer/RegexURINormalizerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
use Ibexa\Core\MVC\Symfony\Component\Serializer\RegexURINormalizer;
1212
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
1313
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\Regex\URI;
14-
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1514
use Ibexa\Tests\Core\Search\TestCase;
15+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
16+
use Symfony\Component\Serializer\Serializer;
1617

1718
final class RegexURINormalizerTest extends TestCase
1819
{
1920
public function testNormalize(): void
2021
{
2122
$normalizer = new RegexURINormalizer();
22-
$normalizer->setSerializer(new SerializerStub());
23+
$serializer = new Serializer(
24+
[
25+
$normalizer,
26+
new ObjectNormalizer(),
27+
]
28+
);
2329

2430
$matcher = new URI([
2531
'regex' => '/^Foo(.*)/(.*)/',
@@ -33,7 +39,7 @@ public function testNormalize(): void
3339
'itemNumber' => 2,
3440
],
3541
],
36-
$normalizer->normalize($matcher)
42+
$serializer->normalize($matcher)
3743
);
3844
}
3945

tests/lib/MVC/Symfony/Component/Serializer/Stubs/SerializerStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public function normalize($object, string $format = null, array $context = []):
4545

4646
public function supportsNormalization($data, string $format = null): bool
4747
{
48-
return true;
48+
return $data instanceof MatcherStub;
4949
}
5050
}

tests/lib/MVC/Symfony/Component/Serializer/URIElementNormalizerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@
1212
use Ibexa\Core\MVC\Symfony\Routing\SimplifiedRequest;
1313
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
1414
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\URIElement;
15-
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1615
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
17+
use Symfony\Component\Serializer\Serializer;
1718

1819
final class URIElementNormalizerTest extends TestCase
1920
{
2021
public function testNormalization(): void
2122
{
2223
$normalizer = new URIElementNormalizer();
23-
$normalizer->setSerializer(new SerializerStub());
24+
$serializer = new Serializer(
25+
[
26+
$normalizer,
27+
new ObjectNormalizer(),
28+
]
29+
);
2430

2531
$matcher = new URIElement(2);
2632
// Set request and invoke match to initialize HostElement::$hostElements
@@ -32,7 +38,7 @@ public function testNormalization(): void
3238
'elementNumber' => 2,
3339
'uriElements' => ['foo', 'bar'],
3440
],
35-
$normalizer->normalize($matcher)
41+
$serializer->normalize($matcher)
3642
);
3743
}
3844

tests/lib/MVC/Symfony/Component/Serializer/URITextNormalizerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
use Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer;
1212
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher;
1313
use Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\URIText;
14-
use Ibexa\Tests\Core\MVC\Symfony\Component\Serializer\Stubs\SerializerStub;
1514
use Ibexa\Tests\Core\Search\TestCase;
15+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
16+
use Symfony\Component\Serializer\Serializer;
1617

1718
final class URITextNormalizerTest extends TestCase
1819
{
1920
public function testNormalize(): void
2021
{
2122
$normalizer = new URITextNormalizer();
22-
$normalizer->setSerializer(new SerializerStub());
23+
$serializer = new Serializer(
24+
[
25+
$normalizer,
26+
new ObjectNormalizer(),
27+
]
28+
);
2329

2430
$matcher = new URIText([
2531
'prefix' => 'foo',
@@ -33,7 +39,7 @@ public function testNormalize(): void
3339
'suffix' => 'bar',
3440
],
3541
],
36-
$normalizer->normalize($matcher)
42+
$serializer->normalize($matcher)
3743
);
3844
}
3945

0 commit comments

Comments
 (0)