- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathphpunit
More file actions
Latest commit
executable file
·79 lines (56 loc) · 1.8 KB
/
Copy pathphpunit
File metadata and controls
executable file
·79 lines (56 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env php
<?php
// Traversing up the directory tree to find composer.json
$workingDir = $projectDir = getcwd();
while(!file_exists($projectDir . '/composer.json')) {
$projectDir = dirname($projectDir);
if ($projectDir === '/') {
fwrite(STDERR, "Could not find composer.json in the current directory or any parent\n");
exit(1);
}
}
$composer = $projectDir . '/composer.json';
// Parsing composer.json and find vendor-dir
$composerConfig = json_decode(file_get_contents($composer), true);
if (isset($composerConfig['config']['vendor-dir'])) {
$vendorDir = $composerConfig['config']['vendor-dir'];
} else {
$vendorDir = 'vendor';
}
$phpUnitBin = realpath($projectDir . '/' . $vendorDir) . '/phpunit/phpunit/phpunit';
if (!file_exists($phpUnitBin)) {
fwrite(STDERR, "Could not find the phpunit executable at $phpUnitBin\n");
exit(1);
}
// Next step is to find phpunit.xml.dist or phpunit.xml
$testDirs = [
'phpunit.xml',
'phpunit.xml.dist',
'test/phpunit.xml',
'test/phpunit.xml.dist',
'tests/phpunit.xml',
'tests/phpunit.xml.dist',
];
$phpUnitFile = null;
foreach($testDirsas$testDir) {
if (file_exists($workingDir . '/' . $testDir)) {
$phpUnitFile = $workingDir . '/' . $testDir;
break;
}
if (file_exists($projectDir . '/' . $testDir)) {
$phpUnitFile = $projectDir . '/' . $testDir;
break;
}
}
// Setting the current directory to where we found phpunit.xml
if ($phpUnitFile) {
chdir(dirname($phpUnitFile));
}
require$projectDir.'/'.$vendorDir.'/autoload.php';
if (class_exists('PHPUnit_TextUI_Command')) {
// start PHPUnit directly bypassing the binary as including the binary outputs the shebang line
PHPUnit_TextUI_Command::main();
} else {
// future-proofing
require$phpUnitBin;
}