Completed
Push — ezp26297-rest_embedding_http_c... ( 123323 )
by
unknown
80:28 queued 54:58
created

getRandomMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
7
namespace eZ\Publish\Core\REST\Server\Tests\HttpCache\Controller;
8
9
use eZ\Publish\Core\REST\Server\HttpCache\Controller\CachedValueUnwrapperController;
10
use eZ\Publish\Core\REST\Server\Values\CachedValue;
11
use PHPUnit_Framework_TestCase;
12
use stdClass;
13
14
class CachedValueUnwrapperControllerTest extends PHPUnit_Framework_TestCase
15
{
16 View Code Duplication
    public function testAnyMethodWithCachedValue()
17
    {
18
        $method = $this->getRandomMethod();
19
20
        $innerControllerMock = $this->getMockBuilder('stdClass')->setMethods([$method])->getMock();
21
        $controller = new CachedValueUnwrapperController($innerControllerMock);
22
23
        $value = new stdClass;
24
25
        $innerControllerMock
26
            ->expects($this->once())
27
            ->method($method)
28
            ->will($this->returnValue(new CachedValue($value)));
29
30
        $this->assertSame($value, $controller->$method());
31
    }
32
33 View Code Duplication
    public function testAnyMethodWithoutCachedValue()
34
    {
35
        $method = $this->getRandomMethod();
36
37
        $innerControllerMock = $this->getMockBuilder('stdClass')->setMethods([$method])->getMock();
38
        $controller = new CachedValueUnwrapperController($innerControllerMock);
39
40
        $value = new stdClass;
41
42
        $innerControllerMock
43
            ->expects($this->once())
44
            ->method($method)
45
            ->will($this->returnValue($value));
46
47
        $this->assertSame($value, $controller->$method());
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    protected function getRandomMethod(): string
54
    {
55
        $actions = ['create', 'retrieve', 'update', 'delete'];
56
        $subjects = ['content', 'section', 'location'];
57
58
        return $actions[array_rand($actions)] . ucfirst($subjects[array_rand($subjects)]);
59
    }
60
}
61