PageTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 4 1
A testSuccessfulDeserialization() 0 18 1
A testSuccessfulSerialization() 0 15 1
1
<?php
2
3
/**
4
 * This file is part of the Setup package.
5
 *
6
 * (c) Sitewards GmbH
7
 */
8
9
namespace Sitewards\Setup\Domain\Page;
10
11
use Doctrine\Common\Annotations\AnnotationRegistry;
12
13
class PageTest extends \PHPUnit_Framework_TestCase
14
{
15
    /** @var \Jms\Serializer\Serializer */
16
    private $serializer;
17
18
    /**
19
     * Register the auto loader and build the serializer class we need
20
     */
21
    public function setUp()
22
    {
23
        AnnotationRegistry::registerAutoloadNamespace(
24
            'JMS\Serializer\Annotation',
25
            'vendor/jms/serializer/src'
26
        );
27
28
        $this->serializer = \JMS\Serializer\SerializerBuilder::create()->build();
29
    }
30
31
    /**
32
     * Unset the serializer after use
33
     */
34
    public function tearDown()
35
    {
36
        $this->serializer = null;
37
    }
38
39
    /**
40
     * Test to make sure that strings work
41
     */
42
    public function testSuccessfulDeserialization()
43
    {
44
        /** @var Page $page */
45
        $page = $this->serializer->deserialize(
46
            '{
47
                "identifier": "test-id",
48
                "title": "Test Title",
49
                "active": true,
50
                "content": "Test Page Content"
51
            }',
52
            Page::class,
53
            'json'
54
        );
55
        $this->assertEquals('test-id', $page->getIdentifier());
56
        $this->assertEquals('Test Title', $page->getTitle());
57
        $this->assertTrue($page->getActive());
58
        $this->assertEquals('Test Page Content', $page->getContent());
59
    }
60
61
    /**
62
     * Test to make sure that strings work
63
     */
64
    public function testSuccessfulSerialization()
65
    {
66
        /** @var Page $page */
67
        $page = new Page(
68
            'test-id',
69
            'Test Title',
70
            'Test Page Content',
71
            true
72
        );
73
        $pageJson = $this->serializer->serialize($page, 'json');
74
        $this->assertEquals(
75
            '{"identifier":"test-id","title":"Test Title","content":"Test Page Content","active":true}',
76
            $pageJson
77
        );
78
    }
79
}
80