ArrayDeserializationVisitorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testDecodeIterableObject() 0 7 1
A testDecodeArray() 0 5 1
A testDecodeEmptyValue() 0 7 1
A testInvalidArgumentThrowsException() 0 4 1
1
<?php
2
namespace Wonnova\SDK\Test\Serializer;
3
4
use Doctrine\Common\Collections\ArrayCollection;
5
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
6
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy;
7
use PHPUnit_Framework_TestCase as TestCase;
8
use Wonnova\SDK\Serializer\ArrayDeserializationVisitor;
9
10
/**
11
 * Class ArrayDeserializationVisitorTest
12
 * @author Wonnova
13
 * @link http://www.wonnova.com
14
 */
15
class ArrayDeserializationVisitorTest extends TestCase
16
{
17
    /**
18
     * @var ArrayDeserializationVisitor
19
     */
20
    private $visitor;
21
22
    public function setUp()
23
    {
24
        $this->visitor = new ArrayDeserializationVisitor(new SerializedNameAnnotationStrategy(
25
            new IdenticalPropertyNamingStrategy()
26
        ));
27
    }
28
29
    public function testDecodeIterableObject()
30
    {
31
        $expected = [1, 2, 3];
32
        $data = new ArrayCollection($expected);
33
        $this->assertEquals($expected, $this->visitor->prepare($data));
34
        $this->assertCount(0, $this->visitor->prepare(new ArrayCollection()));
35
    }
36
37
    public function testDecodeArray()
38
    {
39
        $expected = [1, 2, 3];
40
        $this->assertEquals($expected, $this->visitor->prepare($expected));
41
    }
42
43
    public function testDecodeEmptyValue()
44
    {
45
        $expected = [];
46
        $this->assertEquals($expected, $this->visitor->prepare(null));
47
        $this->assertEquals($expected, $this->visitor->prepare([]));
48
        $this->assertEquals($expected, $this->visitor->prepare(''));
49
    }
50
51
    /**
52
     * @expectedException \JMS\Serializer\Exception\RuntimeException
53
     */
54
    public function testInvalidArgumentThrowsException()
55
    {
56
        $this->visitor->prepare(new \stdClass());
57
    }
58
}
59