Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
15.00% |
6 / 40 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| lint_test | |
15.00% |
6 / 40 |
|
25.00% |
1 / 4 |
153.18 | |
0.00% |
0 / 1 |
| setUpBeforeClass | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| test_lint | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| lint_data | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| check | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class lint_test extends phpbb_test_case |
| 15 | { |
| 16 | protected static $php_binary; |
| 17 | |
| 18 | static public function setUpBeforeClass(): void |
| 19 | { |
| 20 | // Try to use PHP_BINARY constant if available so lint tests are run |
| 21 | // using the same php binary as phpunit. If not available (pre PHP |
| 22 | // 5.4), assume binary is called 'php' and is in PATH. |
| 23 | self::$php_binary = defined('PHP_BINARY') ? escapeshellcmd(PHP_BINARY) : 'php'; |
| 24 | |
| 25 | $output = array(); |
| 26 | $status = 1; |
| 27 | exec(sprintf('(%s --version) 2>&1', self::$php_binary), $output, $status); |
| 28 | if ($status) |
| 29 | { |
| 30 | $output = implode("\n", $output); |
| 31 | if (self::$php_binary === 'php') |
| 32 | { |
| 33 | self::markTestSkipped(sprintf('php is not in PATH or broken. Output: %s', $output)); |
| 34 | } |
| 35 | else |
| 36 | { |
| 37 | self::markTestSkipped(sprintf('Could not run PHP_BINARY %s. Output: %s', self::$php_binary, $output)); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @dataProvider lint_data |
| 44 | */ |
| 45 | public function test_lint($path) |
| 46 | { |
| 47 | $cmd = sprintf('(%s -l %s) 2>&1', self::$php_binary, escapeshellarg($path)); |
| 48 | $output = array(); |
| 49 | $status = 1; |
| 50 | exec($cmd, $output, $status); |
| 51 | $output = implode("\n", $output); |
| 52 | $this->assertEquals(0, $status, "PHP lint failed for $path:\n$output"); |
| 53 | } |
| 54 | |
| 55 | public static function lint_data(): array |
| 56 | { |
| 57 | return self::check(__DIR__ . '/..'); |
| 58 | } |
| 59 | |
| 60 | protected static function check($root): array |
| 61 | { |
| 62 | $files = array(); |
| 63 | $dh = opendir($root); |
| 64 | |
| 65 | if ($dh === false) |
| 66 | { |
| 67 | return $files; |
| 68 | } |
| 69 | |
| 70 | while (($filename = readdir($dh)) !== false) |
| 71 | { |
| 72 | if ($filename == '.' || $filename == '..') |
| 73 | { |
| 74 | continue; |
| 75 | } |
| 76 | $path = $root . '/' . $filename; |
| 77 | // skip symlinks to avoid infinite loops |
| 78 | if (is_link($path)) |
| 79 | { |
| 80 | continue; |
| 81 | } |
| 82 | if (is_dir($path) && !in_array($path, array( |
| 83 | __DIR__ . '/../.git', |
| 84 | __DIR__ . '/../build/new_version', |
| 85 | __DIR__ . '/../build/old_versions', |
| 86 | __DIR__ . '/../phpBB/cache', |
| 87 | __DIR__ . '/../phpBB/ext', |
| 88 | __DIR__ . '/../phpBB/store', |
| 89 | // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20 |
| 90 | // https://gist.github.com/e003913ffd493da63cbc |
| 91 | __DIR__ . '/../phpBB/vendor', |
| 92 | __DIR__ . '/../node_modules', |
| 93 | ))) |
| 94 | { |
| 95 | $files = array_merge($files, self::check($path)); |
| 96 | } |
| 97 | else if (substr($filename, strlen($filename)-4) == '.php') |
| 98 | { |
| 99 | $files[] = array($path); |
| 100 | } |
| 101 | } |
| 102 | return $files; |
| 103 | } |
| 104 | } |