Completed
Push — master ( e22522...ee64fa )
by Sergei
13:37
created

UserDataMapperTest::testMapData_ClearExisting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Modera\BackendSecurityBundle\Tests\Unit\DataMapper;
4
5
use Modera\FoundationBundle\Testing\FunctionalTestCase;
6
use Modera\SecurityBundle\Entity\User;
7
8
/**
9
 * @author    Alex Plaksin <[email protected]>
10
 * @copyright 2016 Modera Foundation
11
 */
12
class UserDataMapperTest extends FunctionalTestCase
13
{
14
    /**
15
     * Phake Mock of Modera\BackendSecurityBundle\DataMapper\UserDataMapper.
16
     */
17
    private $mapper;
18
19
    public function doSetUp()
20
    {
21
        $mapperService = static::$container->get('sli.extjsintegration.entity_data_mapper');
22
23
        $this->mapper = \Phake::partialMock('Modera\BackendSecurityBundle\DataMapper\UserDataMapper', $mapperService, static::$em);
24
    }
25
26
    public function testDataMapper_ExcludedFiled()
27
    {
28
        $mappedFields = \Phake::makeVisible($this->mapper)->getAllowedFields(User::clazz());
29
30
        $this->assertTrue(false === array_search('meta', $mappedFields));
31
    }
32
33 View Code Duplication
    public function testMapData_SetNewMeta()
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...
34
    {
35
        $meta = array('newKey' => 'newVal');
36
        $params = array(
37
            'lastName' => 'Last Name',
38
            'meta' => $meta,
39
        );
40
        $user = new User();
41
42
        $this->mapper->mapData($params, $user);
0 ignored issues
show
Bug introduced by
The method mapData() does not seem to exist on object<Phake_IMock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
44
        $this->assertEquals('Last Name', $user->getLastName());
45
        $this->assertEquals($meta, $user->getMeta());
46
    }
47
48 View Code Duplication
    public function testMapData_RewriteExistingMeta()
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...
49
    {
50
        $meta = array('newKey' => 'newVal');
51
        $params = array(
52
            'lastName' => 'Last Name',
53
            'meta' => $meta,
54
        );
55
        $user = new User();
56
        $user->setMeta(array('WillBeRewrited' => true));
57
58
        $this->mapper->mapData($params, $user);
0 ignored issues
show
Bug introduced by
The method mapData() does not seem to exist on object<Phake_IMock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
60
        $this->assertEquals('Last Name', $user->getLastName());
61
        $this->assertEquals($meta, $user->getMeta());
62
    }
63
64 View Code Duplication
    public function testMapData_ClearExisting()
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...
65
    {
66
        $meta = array('WillBeErased' => true);
67
        $params = array(
68
            'lastName' => 'Last Name',
69
            'meta' => '',
70
        );
71
        $user = new User();
72
        $user->setMeta($meta);
73
74
        $this->mapper->mapData($params, $user);
0 ignored issues
show
Bug introduced by
The method mapData() does not seem to exist on object<Phake_IMock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
76
        $this->assertEquals('Last Name', $user->getLastName());
77
        $this->assertEquals(array(), $user->getMeta());
78
    }
79
80 View Code Duplication
    public function testMapData_WillBeNotTouched()
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...
81
    {
82
        $meta = array('WillExistsAfterMapping' => true);
83
        $params = array(
84
            'lastName' => 'Last Name',
85
        );
86
87
        $user = new User();
88
        $user->setMeta($meta);
89
90
        $this->mapper->mapData($params, $user);
0 ignored issues
show
Bug introduced by
The method mapData() does not seem to exist on object<Phake_IMock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
92
        $this->assertEquals('Last Name', $user->getLastName());
93
        $this->assertEquals($meta, $user->getMeta());
94
    }
95
}
96