Completed
Push — ezp-23733_disable_section_dele... ( 6e64a4...9f6957 )
by
unknown
26:00
created

testCountRoleAssignmentsUsingSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 17
loc 17
rs 9.4286
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Section\SectionHandlerTest 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\Persistence\Legacy\Tests\Content\Section;
12
13
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
14
use eZ\Publish\SPI\Persistence\Content\Section;
15
use eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler;
16
17
/**
18
 * Test case for Section Handler.
19
 */
20
class SectionHandlerTest extends TestCase
21
{
22
    /**
23
     * Section handler.
24
     *
25
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler
26
     */
27
    protected $sectionHandler;
28
29
    /**
30
     * Section gateway mock.
31
     *
32
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway
33
     */
34
    protected $gatewayMock;
35
36
    /**
37
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::create
38
     */
39 View Code Duplication
    public function testCreate()
40
    {
41
        $handler = $this->getSectionHandler();
42
43
        $gatewayMock = $this->getGatewayMock();
44
45
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
46
            ->method('insertSection')
47
            ->with(
48
                $this->equalTo('New Section'),
49
                $this->equalTo('new_section')
50
            )->will($this->returnValue(23));
51
52
        $sectionRef = new Section();
53
        $sectionRef->id = 23;
54
        $sectionRef->name = 'New Section';
55
        $sectionRef->identifier = 'new_section';
56
57
        $result = $handler->create('New Section', 'new_section');
58
59
        $this->assertEquals(
60
            $sectionRef,
61
            $result
62
        );
63
    }
64
65
    /**
66
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::update
67
     */
68 View Code Duplication
    public function testUpdate()
69
    {
70
        $handler = $this->getSectionHandler();
71
72
        $gatewayMock = $this->getGatewayMock();
73
74
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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
            ->method('updateSection')
76
            ->with(
77
                $this->equalTo(23),
78
                $this->equalTo('New Section'),
79
                $this->equalTo('new_section')
80
            );
81
82
        $sectionRef = new Section();
83
        $sectionRef->id = 23;
84
        $sectionRef->name = 'New Section';
85
        $sectionRef->identifier = 'new_section';
86
87
        $result = $handler->update(23, 'New Section', 'new_section');
88
89
        $this->assertEquals(
90
            $sectionRef,
91
            $result
92
        );
93
    }
94
95
    /**
96
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::load
97
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionFromArray
98
     */
99 View Code Duplication
    public function testLoad()
100
    {
101
        $handler = $this->getSectionHandler();
102
103
        $gatewayMock = $this->getGatewayMock();
104
105
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
106
            ->method('loadSectionData')
107
            ->with(
108
                $this->equalTo(23)
109
            )->will(
110
                $this->returnValue(
111
                    array(
112
                        array(
113
                            'id' => '23',
114
                            'identifier' => 'new_section',
115
                            'name' => 'New Section',
116
                        ),
117
                    )
118
                )
119
            );
120
121
        $sectionRef = new Section();
122
        $sectionRef->id = 23;
123
        $sectionRef->name = 'New Section';
124
        $sectionRef->identifier = 'new_section';
125
126
        $result = $handler->load(23);
127
128
        $this->assertEquals(
129
            $sectionRef,
130
            $result
131
        );
132
    }
133
134
    /**
135
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::loadAll
136
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionFromArray
137
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionsFromArray
138
     */
139
    public function testLoadAll()
140
    {
141
        $handler = $this->getSectionHandler();
142
143
        $gatewayMock = $this->getGatewayMock();
144
145
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
146
        ->method('loadAllSectionData')
147
        ->will(
148
            $this->returnValue(
149
                array(
150
                    array(
151
                        'id' => '23',
152
                        'identifier' => 'new_section',
153
                        'name' => 'New Section',
154
                    ),
155
                    array(
156
                        'id' => '46',
157
                        'identifier' => 'new_section2',
158
                        'name' => 'New Section2',
159
                    ),
160
                )
161
            )
162
        );
163
164
        $sectionRef = new Section();
165
        $sectionRef->id = 23;
166
        $sectionRef->name = 'New Section';
167
        $sectionRef->identifier = 'new_section';
168
169
        $sectionRef2 = new Section();
170
        $sectionRef2->id = 46;
171
        $sectionRef2->name = 'New Section2';
172
        $sectionRef2->identifier = 'new_section2';
173
174
        $result = $handler->loadAll();
175
176
        $this->assertEquals(
177
            array($sectionRef, $sectionRef2),
178
            $result
179
        );
180
    }
181
182
    /**
183
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::loadByIdentifier
184
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionFromArray
185
     */
186 View Code Duplication
    public function testLoadByIdentifier()
187
    {
188
        $handler = $this->getSectionHandler();
189
190
        $gatewayMock = $this->getGatewayMock();
191
192
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
193
            ->method('loadSectionDataByIdentifier')
194
            ->with(
195
                $this->equalTo('new_section')
196
            )->will(
197
                $this->returnValue(
198
                    array(
199
                        array(
200
                            'id' => '23',
201
                            'identifier' => 'new_section',
202
                            'name' => 'New Section',
203
                        ),
204
                    )
205
                )
206
            );
207
208
        $sectionRef = new Section();
209
        $sectionRef->id = 23;
210
        $sectionRef->name = 'New Section';
211
        $sectionRef->identifier = 'new_section';
212
213
        $result = $handler->loadByIdentifier('new_section');
214
215
        $this->assertEquals(
216
            $sectionRef,
217
            $result
218
        );
219
    }
220
221
    /**
222
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::delete
223
     */
224 View Code Duplication
    public function testDelete()
225
    {
226
        $handler = $this->getSectionHandler();
227
228
        $gatewayMock = $this->getGatewayMock();
229
230
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
231
            ->method('countContentObjectsInSection')
232
            ->with($this->equalTo(23))
233
            ->will($this->returnValue(0));
234
235
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
236
            ->method('deleteSection')
237
            ->with(
238
                $this->equalTo(23)
239
            );
240
241
        $result = $handler->delete(23);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $handler->delete(23) (which targets eZ\Publish\Core\Persiste...ction\Handler::delete()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
242
    }
243
244
    /**
245
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::delete
246
     * @expectedException RuntimeException
247
     */
248 View Code Duplication
    public function testDeleteFailure()
249
    {
250
        $handler = $this->getSectionHandler();
251
252
        $gatewayMock = $this->getGatewayMock();
253
254
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
255
            ->method('countContentObjectsInSection')
256
            ->with($this->equalTo(23))
257
            ->will($this->returnValue(2));
258
259
        $gatewayMock->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
260
            ->method('deleteSection');
261
262
        $result = $handler->delete(23);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $handler->delete(23) (which targets eZ\Publish\Core\Persiste...ction\Handler::delete()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
263
    }
264
265
    /**
266
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::assign
267
     */
268 View Code Duplication
    public function testAssign()
269
    {
270
        $handler = $this->getSectionHandler();
271
272
        $gatewayMock = $this->getGatewayMock();
273
274
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
275
            ->method('assignSectionToContent')
276
            ->with(
277
                $this->equalTo(23),
278
                $this->equalTo(42)
279
            );
280
281
        $result = $handler->assign(23, 42);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $handler->assign(23, 42) (which targets eZ\Publish\Core\Persiste...ction\Handler::assign()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
282
    }
283
284
    /**
285
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::policiesCount
286
     */
287 View Code Duplication
    public function testPoliciesCount()
288
    {
289
        $handler = $this->getSectionHandler();
290
291
        $gatewayMock = $this->getGatewayMock();
292
293
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
294
            ->method('countPoliciesUsingSection')
295
            ->with(
296
                $this->equalTo(1)
297
            )
298
            ->will(
299
                $this->returnValue(7)
300
            );
301
302
        $result = $handler->policiesCount(1);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
303
    }
304
305
    /**
306
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::countRoleAssignmentsUsingSection
307
     */
308 View Code Duplication
    public function testCountRoleAssignmentsUsingSection()
309
    {
310
        $handler = $this->getSectionHandler();
311
312
        $gatewayMock = $this->getGatewayMock();
313
314
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Section\Gateway>.

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...
315
            ->method('countRoleAssignmentsUsingSection')
316
            ->with(
317
                $this->equalTo(1)
318
            )
319
            ->will(
320
                $this->returnValue(0)
321
            );
322
323
        $handler->countRoleAssignmentsUsingSection(1);
324
    }
325
326
    /**
327
     * Returns the section handler to test.
328
     *
329
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler
330
     */
331
    protected function getSectionHandler()
332
    {
333
        if (!isset($this->sectionHandler)) {
334
            $this->sectionHandler = new Handler(
335
                $this->getGatewayMock()
336
            );
337
        }
338
339
        return $this->sectionHandler;
340
    }
341
342
    /**
343
     * Returns a mock for the section gateway.
344
     *
345
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway
346
     */
347
    protected function getGatewayMock()
348
    {
349
        if (!isset($this->gatewayMock)) {
350
            $this->gatewayMock = $this->getMockForAbstractClass(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...ent\\Section\\Gateway') of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ontent\Section\Gateway> of property $gatewayMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
351
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Section\\Gateway'
352
            );
353
        }
354
355
        return $this->gatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->gatewayMock; of type PHPUnit_Framework_MockOb...Content\Section\Gateway adds the type PHPUnit_Framework_MockObject_MockObject to the return on line 355 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...lerTest::getGatewayMock of type eZ\Publish\Core\Persiste...Content\Section\Gateway.
Loading history...
356
    }
357
}
358