Completed
Pull Request — master (#556)
by Evgenij
02:42
created

ConfiguredContextFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 63.64 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateSerializationContext() 14 14 1
A testCreateDeserializationContext() 14 14 1
A getContextConfig() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace JMS\SerializerBundle\Tests\ContextFactory;
4
5
use JMS\SerializerBundle\ContextFactory\ConfiguredContextFactory;
6
7
/**
8
 * Class ConfiguredContextFactoryTest
9
 */
10
class ConfiguredContextFactoryTest extends \PHPUnit_Framework_TestCase
11
{
12 View Code Duplication
    public function testCreateSerializationContext()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        $config = $this->getContextConfig();
15
        $object = new ConfiguredContextFactory($config);
16
17
        $this->assertInstanceOf('JMS\Serializer\ContextFactory\SerializationContextFactoryInterface', $object);
18
19
        $context = $object->createSerializationContext();
20
        $this->assertInstanceOf('JMS\Serializer\SerializationContext', $context);
21
        $this->assertSame($config['serialize_null'], $context->shouldSerializeNull());
22
23
        $this->assertSame($config['version'], $context->attributes->get('version')->get());
24
        $this->assertSame($config['groups'], $context->attributes->get('groups')->get());
25
    }
26
27 View Code Duplication
    public function testCreateDeserializationContext()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $config = $this->getContextConfig();
30
        $object = new ConfiguredContextFactory($config);
31
32
        $this->assertInstanceOf('JMS\Serializer\ContextFactory\DeserializationContextFactoryInterface', $object);
33
34
        $context = $object->createDeserializationContext();
35
        $this->assertInstanceOf('JMS\Serializer\DeserializationContext', $context);
36
        $this->assertSame($config['serialize_null'], $context->shouldSerializeNull());
37
38
        $this->assertSame($config['version'], $context->attributes->get('version')->get());
39
        $this->assertSame($config['groups'], $context->attributes->get('groups')->get());
40
    }
41
42
    private function getContextConfig()
43
    {
44
        return [
45
            'attributes'     => [
46
                'x' => mt_rand(0, PHP_INT_MAX),
47
            ],
48
            'groups'         => [ 'Default', 'Registration' ],
49
            'serialize_null' => true,
50
            'version'        => sprintf('%d.%d.%d', mt_rand(1, 10), mt_rand(1, 10), mt_rand(1, 10)),
51
        ];
52
    }
53
}
54