willThrowAnExceptionIfConfigFileDoesNotExist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 *
5
 * Copyright (C) 2018  Ross Mitchell
6
 *
7
 * This file is part of RossMitchell/UpdateCloudFlare.
8
 *
9
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
10
 * it and/or modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
namespace RossMitchell\UpdateCloudFlare\Tests\Data\Config;
24
25
use PHLAK\Config\Config as ConfigLoader;
26
use RossMitchell\UpdateCloudFlare\Data\Config;
27
use RossMitchell\UpdateCloudFlare\Exceptions\MissingConfigException;
28
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass;
29
use Symfony\Component\Console\Exception\LogicException;
30
31
/**
32
 * Class InvalidConfigTest
33
 * @testdox RossMitchell\UpdateCloudFlare\Data\Config
34
 * @package RossMitchell\UpdateCloudFlare\Tests\Data\Config
35
 */
36
class InvalidConfigTest extends AbstractTestClass
37
{
38
    /**
39
     * @Inject
40
     * @var ConfigLoader
41
     */
42
    private $configLoader;
43
44
    /**
45
     * @test
46
     */
47
    public function willThrowAnExceptionIfConfigFileDoesNotExist(): void
48
    {
49
        $this->expectException(MissingConfigException::class);
50
51
        $this->getConfigClass('not/a/real/file');
52
    }
53
54
    /**
55
     * @test
56
     */
57
    public function willThrowAnExceptionIfInvalidSubDomainPassed(): void
58
    {
59
        $configClass = $this->getConfigClass('tests/_files/nonArraySubDomain.json');
60
        $this->expectException(LogicException::class);
61
        $configClass->getSubDomains();
62
    }
63
64
    /**
65
     * @test
66
     */
67
    public function canHandleASingleSubDomainInTheConfig(): void
68
    {
69
        $configFile  = 'tests/_files/singleSubDomain.json';
70
        $configClass = $this->getConfigClass($configFile);
71
        $expected    = ['www'];
72
        $actual      = $configClass->getSubDomains();
73
        $this->assertInternalType('array', $actual);
74
        $this->assertEquals($expected, $actual);
75
    }
76
77
    /**
78
     * @param string $configFile
79
     *
80
     * @return Config
81
     */
82
    private function getConfigClass(string $configFile): Config
83
    {
84
        $configLoader = $this->configLoader;
85
86
        return new Config($configLoader, $configFile);
87
    }
88
}
89