Completed
Push — master ( 5ba1dc...b85ec4 )
by Tomasz
02:09
created

FacadeTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 6
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFacade() 0 18 1
A testExceptionInvalidFormat() 0 6 1
1
<?php
2
namespace Thunder\Serializard\Tests;
3
4
use Thunder\Serializard\Format\JsonFormat;
5
use Thunder\Serializard\Normalizer\ReflectionNormalizer;
6
use Thunder\Serializard\SerializardFacade;
7
use Thunder\Serializard\Tests\Fake\FakeTag;
8
use Thunder\Serializard\Tests\Fake\FakeUser;
9
10
/**
11
 * @author Tomasz Kowalczyk <[email protected]>
12
 */
13
class FacadeTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testFacade()
16
    {
17
        $userClass = 'Thunder\Serializard\Tests\Fake\FakeUser';
18
        $json = '{"id":1,"name":"[email protected]"}';
19
        $user = new FakeUser(1, '[email protected]', new FakeTag(1, 'tag'));
20
21
        $facade = new SerializardFacade();
22
        $facade->addFormat('thunder', new JsonFormat());
23
        $facade->addNormalizer($userClass, 'user', new ReflectionNormalizer(array('tag', 'tags')));
24
        $facade->addHydrator($userClass, 'user', function(array $data) {
25
            return new FakeUser($data['id'], $data['name'], new FakeTag(1, 'name'));
26
        });
27
28
        $this->assertSame($json, $facade->serialize($user, 'json'));
29
        $this->assertSame($json, $facade->serialize($user, 'thunder'));
30
        $this->assertInstanceOf($userClass, $facade->unserialize($json, $userClass, 'json'));
31
        $this->assertSame(1, $facade->unserialize($json, $userClass, 'json')->getId());
32
    }
33
34
    public function testExceptionInvalidFormat()
35
    {
36
        $facade = new SerializardFacade();
37
        $this->setExpectedException('RuntimeException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
        $facade->serialize(new \stdClass(), 'invalid');
39
    }
40
}
41