Completed
Pull Request — master (#304)
by Benoît
03:33
created

ExplicitNullArraySerializerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSerializingNullResource() 0 28 1
1
<?php
2
3
4
namespace Serializer;
5
6
7
use League\Fractal\Manager;
8
use League\Fractal\Resource\NullResource;
9
use League\Fractal\Scope;
10
use League\Fractal\Serializer\ExplicitNullArraySerializer;
11
use League\Fractal\Test\Stub\Transformer\GenericBookTransformer;
12
13
class ExplicitNullArraySerializerTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testSerializingNullResource()
16
    {
17
        $manager = new Manager();
18
        $manager->parseIncludes('author');
19
        $manager->setSerializer(new ExplicitNullArraySerializer());
20
21
        $resource = new NullResource(null, new GenericBookTransformer(), 'books');
22
23
        // Try without metadata
24
        $scope = new Scope($manager, $resource);
25
26
        $expected = null;
27
        $this->assertSame($expected, $scope->toArray());
28
29
        // JSON array of JSON objects
30
        $expectedJson = 'null';
31
        $this->assertSame($expectedJson, $scope->toJson());
32
33
        // Same again with metadata
34
        $resource->setMetaValue('foo', 'bar');
35
        $scope = new Scope($manager, $resource);
36
37
        $expected = null;
38
        $this->assertSame($expected, $scope->toArray());
39
40
        $expectedJson = 'null';
41
        $this->assertSame($expectedJson, $scope->toJson());
42
    }
43
}
44