1
|
|
|
<?php |
2
|
|
|
namespace Thunder\Serializard\Tests; |
3
|
|
|
|
4
|
|
|
use Thunder\Serializard\Exception\HydratorNotFoundException; |
5
|
|
|
use Thunder\Serializard\Exception\SerializationFailureException; |
6
|
|
|
use Thunder\Serializard\Exception\UnserializationFailureException; |
7
|
|
|
use Thunder\Serializard\Format\ArrayFormat; |
8
|
|
|
use Thunder\Serializard\Format\JsonFormat; |
9
|
|
|
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer; |
10
|
|
|
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer; |
11
|
|
|
use Thunder\Serializard\Tests\Fake\Context\FakeNormalizerContext; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Tomasz Kowalczyk <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
final class FormatTest extends AbstractTestCase |
17
|
|
|
{ |
18
|
|
|
public function testArrayUnserializeInvalidTypeException() |
19
|
|
|
{ |
20
|
|
|
$format = new ArrayFormat(); |
21
|
|
|
$this->expectExceptionClass(UnserializationFailureException::class); |
22
|
|
|
$format->unserialize(new \stdClass(), \stdClass::class, new FallbackHydratorContainer()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testMissingUnserializationHandlerException() |
26
|
|
|
{ |
27
|
|
|
$format = new ArrayFormat(); |
28
|
|
|
$this->expectExceptionClass(HydratorNotFoundException::class); |
29
|
|
|
$format->unserialize([], \stdClass::class, new FallbackHydratorContainer()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testJsonEncodeSerializationFailureException() |
33
|
|
|
{ |
34
|
|
|
$format = new JsonFormat(); |
35
|
|
|
$this->expectExceptionClass(SerializationFailureException::class); // Inf and NaN cannot be JSON encoded |
36
|
|
|
$format->serialize(INF, new FallbackNormalizerContainer(), new FakeNormalizerContext()); // INF is returned as zero on PHP <=5.4 |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|