Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a...6abe82 )
by
unknown
79:54 queued 33:48
created

RestUserGroupRoleAssignmentTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 152
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 9

Importance

Changes 0
Metric Value
dl 152
loc 152
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testVisit() 47 47 1
A testResultContainsRoleAssignmentElement() 14 14 1
A testResultContainsRoleAssignmentAttributes() 15 15 1
A testResultContainsRoleElement() 11 11 1
A testResultContainsRoleAttributes() 15 15 1
A internalGetVisitor() 4 4 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
/**
4
 * File containing a test class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
12
13
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
14
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
15
use eZ\Publish\Core\Repository\Values\User;
16
use eZ\Publish\Core\REST\Server\Values;
17
18 View Code Duplication
class RestUserGroupRoleAssignmentTest extends ValueObjectVisitorBaseTest
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    /**
21
     * Test the RestUserGroupRoleAssignment visitor.
22
     *
23
     * @return string
24
     */
25
    public function testVisit()
26
    {
27
        $visitor = $this->getVisitor();
28
        $generator = $this->getGenerator();
29
30
        $generator->startDocument(null);
31
32
        $userGroupRoleAssignment = new Values\RestUserGroupRoleAssignment(
33
            new User\UserGroupRoleAssignment(
34
                array(
35
                    'role' => new User\Role(
36
                        array(
37
                            'id' => 42,
38
                            'identifier' => 'some-role',
39
                        )
40
                    ),
41
                )
42
            ),
43
            '/1/5/14'
44
        );
45
46
        $this->addRouteExpectation(
47
            'ezpublish_rest_loadRoleAssignmentForUserGroup',
48
            array(
49
                'groupPath' => '1/5/14',
50
                'roleId' => $userGroupRoleAssignment->roleAssignment->role->id,
51
            ),
52
            "/user/groups/1/5/14/roles/{$userGroupRoleAssignment->roleAssignment->role->id}"
53
        );
54
        $this->addRouteExpectation(
55
            'ezpublish_rest_loadRole',
56
            array('roleId' => $userGroupRoleAssignment->roleAssignment->role->id),
57
            "/user/roles/{$userGroupRoleAssignment->roleAssignment->role->id}"
58
        );
59
60
        $visitor->visit(
61
            $this->getVisitorMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getVisitorMock() targeting eZ\Publish\Core\REST\Com...eTest::getVisitorMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\REST\Com...eObjectVisitor::visit() does only seem to accept object<eZ\Publish\Core\R...\Common\Output\Visitor>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
62
            $generator,
63
            $userGroupRoleAssignment
64
        );
65
66
        $result = $generator->endDocument(null);
67
68
        $this->assertNotNull($result);
69
70
        return $result;
71
    }
72
73
    /**
74
     * Test if result contains RoleAssignment element.
75
     *
76
     * @param string $result
77
     *
78
     * @depends testVisit
79
     */
80
    public function testResultContainsRoleAssignmentElement($result)
81
    {
82
        $this->assertXMLTag(
83
            array(
84
                'tag' => 'RoleAssignment',
85
                'children' => array(
86
                    'count' => 1,
87
                ),
88
            ),
89
            $result,
90
            'Invalid <RoleAssignment> element.',
91
            false
92
        );
93
    }
94
95
    /**
96
     * Test if result contains RoleAssignment element attributes.
97
     *
98
     * @param string $result
99
     *
100
     * @depends testVisit
101
     */
102
    public function testResultContainsRoleAssignmentAttributes($result)
103
    {
104
        $this->assertXMLTag(
105
            array(
106
                'tag' => 'RoleAssignment',
107
                'attributes' => array(
108
                    'media-type' => 'application/vnd.ez.api.RoleAssignment+xml',
109
                    'href' => '/user/groups/1/5/14/roles/42',
110
                ),
111
            ),
112
            $result,
113
            'Invalid <RoleAssignment> attributes.',
114
            false
115
        );
116
    }
117
118
    /**
119
     * Test if result contains Role element.
120
     *
121
     * @param string $result
122
     *
123
     * @depends testVisit
124
     */
125
    public function testResultContainsRoleElement($result)
126
    {
127
        $this->assertXMLTag(
128
            array(
129
                'tag' => 'Role',
130
            ),
131
            $result,
132
            'Invalid <Role> element.',
133
            false
134
        );
135
    }
136
137
    /**
138
     * Test if result contains Role element attributes.
139
     *
140
     * @param string $result
141
     *
142
     * @depends testVisit
143
     */
144
    public function testResultContainsRoleAttributes($result)
145
    {
146
        $this->assertXMLTag(
147
            array(
148
                'tag' => 'Role',
149
                'attributes' => array(
150
                    'media-type' => 'application/vnd.ez.api.Role+xml',
151
                    'href' => '/user/roles/42',
152
                ),
153
            ),
154
            $result,
155
            'Invalid <Role> attributes.',
156
            false
157
        );
158
    }
159
160
    /**
161
     * Get the RestUserGroupRoleAssignment visitor.
162
     *
163
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestUserGroupRoleAssignment
164
     */
165
    protected function internalGetVisitor()
166
    {
167
        return new ValueObjectVisitor\RestUserGroupRoleAssignment();
168
    }
169
}
170