Completed
Push — master ( 0dd13d...744a89 )
by
unknown
15:17
created

Tests/Unit/DataMapper/UserDataMapperTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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);
43
44
        $this->assertEquals('Last Name', $user->getLastName());
45
        $this->assertEquals($meta, $user->getMeta());
46
    }
47
48 View Code Duplication
    public function testMapData_RewriteExistingMeta()
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);
59
60
        $this->assertEquals('Last Name', $user->getLastName());
61
        $this->assertEquals($meta, $user->getMeta());
62
    }
63
64 View Code Duplication
    public function testMapData_ClearExisting()
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);
75
76
        $this->assertEquals('Last Name', $user->getLastName());
77
        $this->assertEquals(array(), $user->getMeta());
78
    }
79
80 View Code Duplication
    public function testMapData_WillBeNotTouched()
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);
91
92
        $this->assertEquals('Last Name', $user->getLastName());
93
        $this->assertEquals($meta, $user->getMeta());
94
    }
95
}
96