Passed
Push — master ( 1cf0a9...56b73d )
by Ayan
01:37
created

ConfigTest::correctApiVersionsDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Phprest;
3
4
use InvalidArgumentException;
5
use League\BooBoo\BooBoo;
6
use Phprest\Service\Logger\Config as LoggerConfig;
7
use Phprest\Service\Logger\Service as LoggerService;
8
use Phprest\Service\Hateoas;
9
use League\Container\Container;
10
use League\Route\RouteCollection;
11
use League\Event\Emitter;
12
use Phprest\ErrorHandler\Handler\Log;
13
use PHPUnit\Framework\TestCase;
14
15
class ConfigTest extends TestCase
16
{
17
18
    /**
19
     * @dataProvider correctApiVersionsDataProvider
20
     *
21
     * @param mixed $apiVersion
22
     */
23
    public function testCorrectApiVersions($apiVersion): void
24
    {
25
        $config = new Config('phprest', $apiVersion, true);
26
27
        $this->assertEquals($apiVersion, $config->getApiVersion());
28
    }
29
30
    public function correctApiVersionsDataProvider(): array
31
    {
32
        return [
33
            [0], [1], [2], [3], [4], [5], [6], [7], [8], [9],
34
            ['0.0'], ['0.1'], ['0.2'], ['0.8'], ['0.9'],
35
            ['1.0'], ['1.1'], ['1.2'], ['1.8'], ['1.9'],
36
            ['2.0'], ['2.1'], ['2.2'], ['2.8'], ['2.9'],
37
            ['3.0'], ['3.1'], ['3.2'], ['3.8'], ['3.9'],
38
            ['4.0'], ['4.1'], ['4.2'], ['4.8'], ['4.9'],
39
            ['5.0'], ['5.1'], ['5.2'], ['5.8'], ['5.9'],
40
            ['6.0'], ['6.1'], ['6.2'], ['6.8'], ['6.9'],
41
            ['7.0'], ['7.1'], ['7.2'], ['7.8'], ['7.9'],
42
            ['8.0'], ['8.1'], ['8.2'], ['8.8'], ['8.9'],
43
            ['9.0'], ['9.1'], ['9.2'], ['9.8'], ['9.9']
44
        ];
45
    }
46
47
    /**
48
     * @dataProvider inCorrectApiVersionsDataProvider
49
     *
50
     * @expectedException InvalidArgumentException
51
     *
52
     * @param mixed $apiVersion
53
     */
54
    public function testInCorrectApiVersions($apiVersion): void
55
    {
56
        $config = new Config('phprest', $apiVersion, true);
57
58
        $this->assertEquals($apiVersion, $config->getApiVersion());
59
    }
60
61
    public function inCorrectApiVersionsDataProvider(): array
62
    {
63
        return [
64
            [-2], [-1], [10], [11], [12],
65
            ['a'], [null],
66
            ['1.0.0'],
67
            ['1.2.3.4'],
68
            ['10.1'],
69
            ['1.10']
70
        ];
71
    }
72
73
    public function testGetters(): void
74
    {
75
        $config = new Config('phprest', 1, true);
76
77
        $this->assertEquals('phprest', $config->getVendor());
78
        $this->assertEquals(1, $config->getApiVersion());
79
        $this->assertEquals(true, $config->isDebug());
80
        $this->assertInstanceOf(Container::class, $config->getContainer());
81
        $this->assertInstanceOf(RouteCollection::class, $config->getRouter());
82
        $this->assertInstanceOf(Emitter::class, $config->getEventEmitter());
83
        $this->assertInstanceOf(Hateoas\Config::class, $config->getHateoasConfig());
84
        $this->assertInstanceOf(Hateoas\Service::class, $config->getHateoasService());
85
        $this->assertInstanceOf(BooBoo::class, $config->getErrorHandler());
86
        $this->assertInstanceOf(Log::class, $config->getLogHandler());
87
    }
88
89
    public function testLoggerGetterSetter(): void
90
    {
91
        $config = new Config('phprest', 1, true);
92
93
        $loggerConfig = new LoggerConfig('test');
94
        $loggerService = new LoggerService();
95
96
        $config->setLoggerConfig($loggerConfig);
97
        $config->setLoggerService($loggerService);
98
99
        $this->assertSame($loggerConfig, $config->getLoggerConfig());
100
        $this->assertSame($loggerService, $config->getLoggerService());
101
    }
102
}
103