|
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\Action\CrudIndexAction; |
|
15
|
|
|
use CakeDC\Api\Service\Action\ExtensionRegistry; |
|
16
|
|
|
use CakeDC\Api\Service\Action\Extension\PaginateExtension; |
|
17
|
|
|
use CakeDC\Api\Service\Action\Extension\SortExtension; |
|
18
|
|
|
use CakeDC\Api\Service\FallbackService; |
|
19
|
|
|
use CakeDC\Api\TestSuite\TestCase; |
|
20
|
|
|
use CakeDC\Api\Test\ConfigTrait; |
|
21
|
|
|
use CakeDC\Api\Test\FixturesTrait; |
|
22
|
|
|
use Cake\Http\Response; |
|
23
|
|
|
use Cake\Http\ServerRequest; |
|
24
|
|
|
|
|
25
|
|
|
class ExtensionRegistryTest 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
|
|
|
$request = new ServerRequest(); |
|
41
|
|
|
$response = new Response(); |
|
42
|
|
|
$service = new FallbackService([ |
|
43
|
|
|
'request' => $request, |
|
44
|
|
|
'response' => $response |
|
45
|
|
|
]); |
|
46
|
|
|
$this->Action = new CrudIndexAction([ |
|
|
|
|
|
|
47
|
|
|
'service' => $service, |
|
48
|
|
|
'request' => $request, |
|
49
|
|
|
'response' => $response |
|
50
|
|
|
]); |
|
51
|
|
|
|
|
52
|
|
|
$this->ExtensionRegistry = new ExtensionRegistry($this->Action); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* tearDown method |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function tearDown() |
|
61
|
|
|
{ |
|
62
|
|
|
unset($this->ExtensionRegistry, $this->Action); |
|
63
|
|
|
parent::tearDown(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Test load value method |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testLoad() |
|
72
|
|
|
{ |
|
73
|
|
|
$extension = $this->ExtensionRegistry->load('CakeDC/Api.Sort', []); |
|
74
|
|
|
$this->assertTrue($extension instanceof SortExtension); |
|
75
|
|
|
$extension = $this->ExtensionRegistry->load('CakeDC/Api.Paginate', []); |
|
76
|
|
|
$this->assertTrue($extension instanceof PaginateExtension); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Test load unexists class method |
|
81
|
|
|
* |
|
82
|
|
|
* @expectedException \CakeDC\Api\Service\Exception\MissingExtensionException |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testLoadWrongClass() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->ExtensionRegistry->load('Unknown', []); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: