Completed
Pull Request — master (#57)
by Alessandro
08:28
created

PHPUnitConfig::addPhpunitOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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