-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-commit-phpunit
51 lines (36 loc) · 1.35 KB
/
pre-commit-phpunit
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
#!/usr/bin/php
<?php
//echo PHP_EOL;
// Fix the files
//exec('php-cs-fixer fix . --config=sf21');
// output message
//echo 'Fixed files' . PHP_EOL;
echo PHP_EOL;
// output a little introduction
echo '>> Starting unit tests' . PHP_EOL;
// get the name for this project; probably the topmost folder name
$projectName = basename(getcwd());
// execute unit tests (it is assumed that a phpunit.xml configuration is present
// in the root of the project)
//exec('phpunit -c app/ --coverage-html app/doc/cc', $output, $returnCode); // cwd is assumed here
exec('phpunit -c app/', $output, $returnCode); // cwd is assumed here
// if the build failed, output a summary and fail
if ($returnCode !== 0) {
// find the line with the summary; this might not be the last
while (($minimalTestSummary = array_pop($output)) !== null) {
if (strpos($minimalTestSummary, 'Tests:') !== false) {
break;
}
}
// output the status
echo '>> Test suite for ' . $projectName . ' failed:' . PHP_EOL;
echo $minimalTestSummary;
echo chr(27) . '[0m' . PHP_EOL; // disable colors and add a line break
echo PHP_EOL;
// abort the commit
exit(1);
}
//echo '>> All tests for ' . $projectName . ' passed and code coverage written to app/doc/cc' . PHP_EOL;
echo '>> All tests for ' . $projectName . ' passed' . PHP_EOL;
echo PHP_EOL;
exit(0);