AbstractTestClass::getDiConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
/**
3
 *
4
 * Copyright (C) 2018  Ross Mitchell
5
 *
6
 * This file is part of RossMitchell/UpdateCloudFlare.
7
 *
8
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
9
 * it and/or modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace RossMitchell\UpdateCloudFlare\Tests;
23
24
use DI\Container;
25
use DI\ContainerBuilder;
26
use PHLAK\Config\Config as ConfigReader;
27
use PHPUnit\Framework\TestCase;
28
use RossMitchell\UpdateCloudFlare\Data\Config;
29
use RossMitchell\UpdateCloudFlare\Data\Headers;
30
use RossMitchell\UpdateCloudFlare\Interfaces\ConfigInterface;
31
use RossMitchell\UpdateCloudFlare\Interfaces\CurlInterface;
32
use RossMitchell\UpdateCloudFlare\Interfaces\CurlResourceInterface;
33
use RossMitchell\UpdateCloudFlare\Interfaces\HeadersInterface;
34
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Curl;
35
use RossMitchell\UpdateCloudFlare\Tests\Fakes\CurlResource;
36
37
/**
38
 * Class AbstractTestClass
39
 * @package RossMitchell\UpdateCloudFlare\Tests
40
 */
41
abstract class AbstractTestClass extends TestCase
42
{
43
    /**
44
     * @var Container
45
     */
46
    private $container;
47
48
    /**
49
     * @throws \DI\DependencyException
50
     * @throws \Exception
51
     */
52
    public function setUp()/* The :void return type declaration that should be here would cause a BC issue */
53
    {
54
        $builder = new ContainerBuilder();
55
        $builder->useAnnotations(true);
56
        $defaultConfig = $this->getDefaultDiConfig();
57
        $builder->addDefinitions($defaultConfig);
58
        $config = $this->getDiConfig();
59
        $builder->addDefinitions($config);
60
        $this->container = $builder->build();
61
        $this->container->injectOn($this);
62
        parent::setUp();
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function getDiConfig(): array
69
    {
70
        return [];
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getDefaultDiConfig(): array
77
    {
78
        return [
79
            'config.file'                => $this->getConfigFile(),
80
            Config::class                => \DI\create()->constructor(\DI\get(ConfigReader::class),
81
                \DI\get('config.file')),
82
            CurlInterface::class         => \DI\get(Curl::class),
83
            ConfigInterface::class       => \DI\get(Config::class),
84
            HeadersInterface::class      => \DI\get(Headers::class),
85
            CurlResourceInterface::class => \DI\get(CurlResource::class),
86
        ];
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getConfigFile(): string
93
    {
94
        return 'tests/_files/testConfig.json';
95
    }
96
}
97