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
|
35 |
|
public function __construct(string $inputPathOrFileName) |
25
|
|
|
{ |
26
|
35 |
|
$this->configFilename = $this->getConfigFileRealpath($inputPathOrFileName); |
27
|
33 |
|
$this->phpunitOptions = []; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string The full path for this configuration file |
32
|
|
|
*/ |
33
|
32 |
|
public function getFileFullPath(): string |
34
|
|
|
{ |
35
|
32 |
|
return $this->configFilename; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string The relative path from where the configuration defines the testsuites |
40
|
|
|
*/ |
41
|
32 |
|
public function getBaseDirectory(): string |
42
|
|
|
{ |
43
|
32 |
|
return dirname($this->configFilename); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param PHPUnitOption $option |
48
|
|
|
*/ |
49
|
4 |
|
public function addPhpunitOption(PHPUnitOption $option) |
50
|
|
|
{ |
51
|
4 |
|
$this->phpunitOptions[] = $option; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return PHPUnitOption[] |
56
|
|
|
*/ |
57
|
31 |
|
public function getPhpunitOptions(): array |
58
|
|
|
{ |
59
|
31 |
|
return $this->phpunitOptions; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $inputPathOrFileName |
64
|
|
|
* @return string |
65
|
|
|
* @throws \InvalidArgumentException |
66
|
|
|
*/ |
67
|
35 |
|
private function getConfigFileRealpath(string $inputPathOrFileName): string |
68
|
|
|
{ |
69
|
35 |
|
$configFile = realpath($inputPathOrFileName); |
70
|
|
|
|
71
|
35 |
|
if (false === $configFile) { |
72
|
1 |
|
throw new \InvalidArgumentException('Config path/file provided is not valid: ' . $inputPathOrFileName); |
73
|
|
|
} |
74
|
|
|
|
75
|
34 |
|
if (is_dir($configFile)) { |
76
|
5 |
|
$configFile .= DIRECTORY_SEPARATOR . self::DEFAULT_FILE_NAME; |
77
|
|
|
} |
78
|
|
|
|
79
|
34 |
|
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
|
33 |
|
return $configFile; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|