-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigTestCase.php
137 lines (116 loc) · 4.06 KB
/
ConfigTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/*
* This file is part of the Allay package.
*
* (c) Cedric van Putten <me@bycedric.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ByCedric\Allay\Tests;
use ByCedric\Allay\Contracts\Exceptions\Handler as ExceptionHandlerContract;
use ByCedric\Allay\Contracts\Exceptions\Manager as ExceptionManagerContract;
use ByCedric\Allay\Contracts\Resource\Manager as ResourceManagerContract;
use ByCedric\Allay\Contracts\Resource\Resolver as ResourceResolverContract;
use ByCedric\Allay\Contracts\Transformers\Transformer as TransformerContract;
abstract class ConfigTestCase extends \ByCedric\Allay\Tests\TestCase
{
/**
* Get the path of the configuration file, to test.
*
* @return string
*/
abstract protected function getConfigPath();
/**
* Get the contents of the configuration file.
*
* @param string $item (default: null)
* @return array
*/
protected function getConfig($item = null)
{
$config = include $this->getConfigPath();
if (!empty($item)) {
foreach (explode('.', $item) as $child) {
$config = $config[$child];
}
}
return $config;
}
public function testConfigReturnsAnArray()
{
$this->assertArray($this->getConfig(), 'Configuration did not return array.');
}
public function testResourceManagerIsDefinedAndImplementsContract()
{
$this->assertSubclassOf(
ResourceManagerContract::class,
$this->getConfig('resources.manager'),
'Defined resource manager is not compatible.'
);
}
public function testResourceResolverIsDefinedAndImplementsContract()
{
$this->assertSubclassOf(
ResourceResolverContract::class,
$this->getConfig('resources.resolver'),
'Defined resource resolver is not compatible.'
);
}
public function testResourceModelsIsAnEmptyArray()
{
$models = $this->getConfig('resources.models');
$this->assertArray($models, 'Defined resource models is not an array.');
$this->assertEmpty($models, 'Defined resource models is not empty.');
}
public function testRouteControllerIsDefined()
{
$this->assertClassExists($this->getConfig('routes.controller'), 'Defined controller class does not exists.');
}
public function testRouteSettingsIsAnArray()
{
$this->assertArray($this->getConfig('routes.settings'), 'Routes settings must be an array.');
}
public function testRouteSettingsMiddlewareExists()
{
$middleware = $this->getConfig('routes.settings.middleware');
if (!empty($middleware)) {
foreach ($middleware as $classType) {
$this->assertClassExists($classType, "Defined middleware \"$classType\" doesn't exists.");
}
}
}
public function testTransformerIsDefinedAndImplementsContract()
{
$this->assertSubclassOf(
TransformerContract::class,
$this->getConfig('transformer'),
'Defined transformer is not compatible.'
);
}
public function testExceptionManagerIsDefinedAndImplementsContract()
{
$this->assertSubclassOf(
ExceptionManagerContract::class,
$this->getConfig('exceptions.manager'),
'Defined exception manager is not compatible.'
);
}
public function testExceptionHandlersImplementsContract()
{
$handlers = $this->getConfig('exceptions.handlers');
if (!empty($handlers)) {
foreach ($handlers as $handler) {
$this->assertSubclassOf(
ExceptionHandlerContract::class,
$handler,
"Defined exception handler \"$handler\" is not compatible."
);
}
}
}
public function testStatusesIsAnArray()
{
$this->assertArray($this->getConfig('statuses'), 'Statuses must be an array.');
}
}