ServiceRegistryTest::testLoadNested()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 23
rs 9.552
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\Action;
13
14
use CakeDC\Api\Service\Service;
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
use Cake\Http\Response;
20
use Cake\Http\ServerRequest;
21
22
class ServiceRegistryTest extends TestCase
23
{
24
25
    use ConfigTrait;
26
    use FixturesTrait;
27
28
    /**
29
     * setUp method
30
     *
31
     * @return void
32
     */
33
    public function setUp()
34
    {
35
        parent::setUp();
36
    }
37
38
    /**
39
     * tearDown method
40
     *
41
     * @return void
42
     */
43
    public function tearDown()
44
    {
45
        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...
46
        parent::tearDown();
47
    }
48
49
    /**
50
     * Test load value method
51
     *
52
     * @return void
53
     */
54
    public function testLoad()
55
    {
56
        $this->_initializeRequest([
57
            'params' => [
58
                'service' => 'authors',
59
            ]
60
        ]);
61
        $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...
62
        $options = [
63
            'version' => null,
64
            'service' => $service,
65
            'request' => $this->request,
66
            '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...
67
            'baseUrl' => '/authors'
68
        ];
69
        $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...
70
        $this->assertTrue($Service instanceof Service);
71
        $this->assertEquals('authors', $Service->getName());
72
    }
73
74
    /**
75
     * Test load value method
76
     *
77
     * @return void
78
     */
79
    public function testLoadNested()
80
    {
81
        $this->_initializeRequest([
82
            'params' => [
83
                'service' => 'authors',
84
                'pass' => [
85
                    '1',
86
                    'articles'
87
                ]
88
            ]
89
        ]);
90
        $service = 'authors';
91
        $options = [
92
            'version' => null,
93
            'service' => $service,
94
            'request' => $this->request,
95
            'response' => $this->response,
96
            'baseUrl' => '/authors/1/articles',
97
        ];
98
        $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...
99
        $this->assertTrue($Service instanceof Service);
100
        $this->assertTextEquals('/authors/1/articles', $Service->getBaseUrl());
101
    }
102
}
103