FormatTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 23
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testArrayUnserializeInvalidTypeException() 0 6 1
A testMissingUnserializationHandlerException() 0 6 1
A testJsonEncodeSerializationFailureException() 0 6 1
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