ListingServiceTest::testActionProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Test\TestCase\Service;
13
14
use CakeDC\Api\Service\ListingService;
15
use CakeDC\Api\Service\ServiceRegistry;
16
use CakeDC\Api\TestSuite\TestCase;
17
use CakeDC\Api\Test\ConfigTrait;
18
use CakeDC\Api\Test\FixturesTrait;
19
20
/**
21
 * Class ListingServiceTest
22
 *
23
 * @package CakeDC\Api\Test\TestCase\Service
24
 */
25
class ListingServiceTest extends TestCase
26
{
27
28
    use ConfigTrait;
29
    use FixturesTrait;
30
31
    /**
32
     * setUp method
33
     *
34
     * @return void
35
     */
36
    public function setUp()
37
    {
38
        parent::setUp();
39
    }
40
41
    /**
42
     * tearDown method
43
     *
44
     * @return void
45
     */
46
    public function tearDown()
47
    {
48
        ServiceRegistry::clear();
0 ignored issues
show
Deprecated Code introduced by
The method CakeDC\Api\Service\ServiceRegistry::clear() has been deprecated with message: 3.6.0 Use \CakeDC\Api\Service\Locator\ServiceLocator::clear() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
49
        parent::tearDown();
50
    }
51
52
    /**
53
     * Test load value method
54
     *
55
     * @return void
56
     */
57
    public function testActionProcess()
58
    {
59
        $this->_initializeRequest([
60
            'params' => [
61
                'service' => 'listing',
62
            ]
63
        ]);
64
        $service = $this->request->getParam('service');
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
65
        $options = [
66
            'version' => null,
67
            'service' => $service,
68
            'request' => $this->request,
69
            'response' => $this->response,
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70
            'baseUrl' => '/listing'
71
        ];
72
        $Service = ServiceRegistry::get($service, $options);
0 ignored issues
show
Deprecated Code introduced by
The method CakeDC\Api\Service\ServiceRegistry::get() has been deprecated with message: 3.6.0 Use \CakeDC\Api\Service\Locator\ServiceLocator::get() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73
        $this->assertTrue($Service instanceof ListingService);
74
        $this->assertEquals('listing', $Service->getName());
75
76
        $action = $Service->buildAction();
77
        $result = $action->process();
78
        $expected = [
79
            'articles',
80
            'articles_tags',
81
            'authors',
82
            'tags',
83
        ];
84
        sort($expected);
85
        sort($result);
86
        $this->assertEquals($expected, $result);
87
    }
88
}
89