Completed
Pull Request — master (#94)
by Alessandro
04:33
created

PHPUnitConfig::alterBoostrap()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Configuration;
5
6
/**
7
 * Class PHPUnitConfig
8
 * @package Paraunit\Configuration
9
 */
10
class PHPUnitConfig
11
{
12
    const DEFAULT_FILE_NAME = 'phpunit.xml.dist';
13
14
    /** @var string */
15
    private $configFilename;
16
17
    /** @var PHPUnitOption[] */
18
    private $phpunitOptions;
19
20
    /**
21
     * @param string $inputPathOrFileName
22
     * @throws \InvalidArgumentException
23
     */
24 33
    public function __construct(string $inputPathOrFileName)
25
    {
26 33
        $this->configFilename = $this->getConfigFileRealpath($inputPathOrFileName);
27 31
        $this->phpunitOptions = [];
28
    }
29
30
    /**
31
     * @return string The full path for this configuration file
32
     */
33 30
    public function getFileFullPath(): string
34
    {
35 30
        return $this->configFilename;
36
    }
37
38
    /**
39
     * @return string The relative path from where the configuration defines the testsuites
40
     */
41 30
    public function getBaseDirectory(): string
42
    {
43 30
        return dirname($this->configFilename);
44
    }
45
46
    /**
47
     * @param PHPUnitOption $option
48
     */
49 3
    public function addPhpunitOption(PHPUnitOption $option)
50
    {
51 3
        $this->phpunitOptions[] = $option;
52
    }
53
54
    /**
55
     * @return PHPUnitOption[]
56
     */
57 29
    public function getPhpunitOptions(): array
58
    {
59 29
        return $this->phpunitOptions;
60
    }
61
62
    /**
63
     * @param string $inputPathOrFileName
64
     * @return string
65
     * @throws \InvalidArgumentException
66
     */
67 33
    private function getConfigFileRealpath(string $inputPathOrFileName): string
68
    {
69 33
        $configFile = realpath($inputPathOrFileName);
70
71 33
        if (false === $configFile) {
72 1
            throw new \InvalidArgumentException('Config path/file provided is not valid: ' . $inputPathOrFileName);
73
        }
74
75 32
        if (is_dir($configFile)) {
76 4
            $configFile .= DIRECTORY_SEPARATOR . self::DEFAULT_FILE_NAME;
77
        }
78
79 32
        if (! is_file($configFile) || ! is_readable($configFile)) {
80 1
            throw new \InvalidArgumentException('Config file ' . $configFile . ' does not exist or is not readable');
81
        }
82
83 31
        return $configFile;
84
    }
85
}
86