Repository navigation
Expand file tree
/
Copy pathConfigTest.php
More file actions
104 lines (88 loc) · 3.33 KB
/
Copy pathConfigTest.php
File metadata and controls
104 lines (88 loc) · 3.33 KB
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
<?php
namespace Phprest\Test;
use InvalidArgumentException;
use League\BooBoo\BooBoo;
use Phprest\Config;
use Phprest\Service\Logger\Config as LoggerConfig;
use Phprest\Service\Logger\Service as LoggerService;
use Phprest\Service\Hateoas;
use League\Container\Container;
use League\Route\RouteCollection;
use League\Event\Emitter;
use Phprest\ErrorHandler\Handler\Log;
use PHPUnit\Framework\TestCase;
class ConfigTest extends TestCase
{
/**
* @dataProvider correctApiVersionsDataProvider
*
* @param mixed $apiVersion
*/
public function testCorrectApiVersions($apiVersion): void
{
$config = new Config('phprest', $apiVersion, true);
$this->assertEquals($apiVersion, $config->getApiVersion());
}
public function correctApiVersionsDataProvider(): array
{
return [
[0], [1], [2], [3], [4], [5], [6], [7], [8], [9],
['0.0'], ['0.1'], ['0.2'], ['0.8'], ['0.9'],
['1.0'], ['1.1'], ['1.2'], ['1.8'], ['1.9'],
['2.0'], ['2.1'], ['2.2'], ['2.8'], ['2.9'],
['3.0'], ['3.1'], ['3.2'], ['3.8'], ['3.9'],
['4.0'], ['4.1'], ['4.2'], ['4.8'], ['4.9'],
['5.0'], ['5.1'], ['5.2'], ['5.8'], ['5.9'],
['6.0'], ['6.1'], ['6.2'], ['6.8'], ['6.9'],
['7.0'], ['7.1'], ['7.2'], ['7.8'], ['7.9'],
['8.0'], ['8.1'], ['8.2'], ['8.8'], ['8.9'],
['9.0'], ['9.1'], ['9.2'], ['9.8'], ['9.9']
];
}
/**
* @dataProvider inCorrectApiVersionsDataProvider
*
* @param mixed $apiVersion
*/
public function testInCorrectApiVersions($apiVersion): void
{
$this->expectException(InvalidArgumentException::class);
$config = new Config('phprest', $apiVersion, true);
$this->assertEquals($apiVersion, $config->getApiVersion());
}
public function inCorrectApiVersionsDataProvider(): array
{
return [
[-2], [-1], [10], [11], [12],
['a'], ['b'],
['1.0.0'],
['1.2.3.4'],
['10.1'],
['1.10']
];
}
public function testGetters(): void
{
$config = new Config('phprest', 1, true);
$this->assertEquals('phprest', $config->getVendor());
$this->assertEquals(1, $config->getApiVersion());
$this->assertEquals(true, $config->isDebug());
$this->assertInstanceOf(Container::class, $config->getContainer());
$this->assertInstanceOf(RouteCollection::class, $config->getRouter());
$this->assertInstanceOf(Emitter::class, $config->getEventEmitter());
$this->assertInstanceOf(Hateoas\Config::class, $config->getHateoasConfig());
$this->assertInstanceOf(Hateoas\Service::class, $config->getHateoasService());
$this->assertInstanceOf(BooBoo::class, $config->getErrorHandler());
$this->assertInstanceOf(Log::class, $config->getLogHandler());
}
public function testLoggerGetterSetter(): void
{
$config = new Config('phprest', 1, true);
$loggerConfig = new LoggerConfig('test');
$loggerService = new LoggerService();
$config->setLoggerConfig($loggerConfig);
$config->setLoggerService($loggerService);
$this->assertSame($loggerConfig, $config->getLoggerConfig());
$this->assertSame($loggerService, $config->getLoggerService());
}
}