This repository was archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithook.php-pre-commit.sublime-snippet
More file actions
86 lines (68 loc) · 2.14 KB
/
Copy pathgithook.php-pre-commit.sublime-snippet
File metadata and controls
86 lines (68 loc) · 2.14 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
80
81
82
83
84
85
86
<snippet>
<content><![CDATA[<?#!/usr/bin/php
<?${TM_PHP_OPEN_TAG:php}
// ------------------------------------------------------------------------
// PHP Lint Test
\$output = array();
\$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', \$output, \$return);
\$against = \$return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
exec("git diff-index --cached --name-only {\$against}", \$output);
\$filename_pattern = '/\.php\$/';
\$exit_status = 0;
foreach (\$output as \$file)
{
// don't check files that aren't PHP
if (!preg_match(\$filename_pattern, \$file)) continue;
if (file_exists(\$file))
{
\$lint_output = array();
exec("php -l " . escapeshellarg(\$file), \$lint_output, \$return);
if (\$return == 0) continue;
echo implode("\n", \$lint_output), "\n";
\$exit_status = 1;
}
}
if (\$exit_status != 0)
{
exit(\$exit_status);
}
// ------------------------------------------------------------------------
// PHPUnit Tests
// test suite path
\$test_suite_file = realpath(dirname(__FILE__)).'${1:path_to_test_suite}.php';
echo PHP_EOL;
echo '+ Starting PHPUnit tests...';
\$output = array();
\$return = 0;
// Execute project unit tests
exec('phpunit "'.\$test_suite_file.'"', \$output, \$return);
// if the build failed, output a summary and fail
if (\$return !== 0)
{
// find the line with the summary; this might not be the last
while ((\$test_summary = array_pop(\$output)) !== null)
{
if (strpos(\$test_summary, 'Tests:') !== false
|| strpos(\$test_summary, 'Cannot open file') !== false)
{
break;
}
}
// output the status and abort the commit
echo 'FAIL'.PHP_EOL;
echo \$test_summary;
// echo chr(27).'[0m'.PHP_EOL; // disable colors and add a line break
echo PHP_EOL;
exit(1);
}
echo 'PASS'.PHP_EOL;
// ------------------------------------------------------------------------
// passed
echo '+ All tests passed.'.PHP_EOL;
echo PHP_EOL;
exit(0);]]></content>
<tabTrigger>gitprecommitphp</tabTrigger>
<scope>text</scope>
<description>Git Pre-Commit Hook for PHP</description>
</snippet>