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