/
test
executable file
·89 lines (66 loc) · 2.14 KB
/
test
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
87
88
89
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
require __DIR__ . '/../vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php';
use CodeIgniter\CLI\CLI;
use Translations\Tests\AbstractTranslationTestCase;
$phpCsFixer = 'vendor/bin/php-cs-fixer';
$phpunit = 'vendor/bin/phpunit';
if (is_windows()) {
$phpCsFixer = strtr($phpCsFixer, '/', '\\');
$phpunit = strtr($phpunit, '/', '\\');
}
CLI::write('Running `composer update`...', 'black', 'green');
passthru('composer update --ansi');
CLI::write();
CLI::write('Fixing coding style...', 'black', 'green');
passthru("{$phpCsFixer} fix --verbose --diff");
CLI::write();
$testCase = new class () extends AbstractTranslationTestCase {
public function getTestCaseClassname(string $locale): string
{
$classname = array_flip(self::$locales)[$locale] ?? null;
if ($classname === null) {
CLI::write('Locale "' . $locale . '" not found.', 'light_gray', 'red');
exit(1);
}
$namespaces = explode('\\', $classname);
return end($namespaces);
}
};
if ($argc === 2) {
$locale = $argv[1];
$testClassname = $testCase->getTestCaseClassname($locale);
CLI::write('Running test...', 'black', 'green');
$command = "{$phpunit} --filter {$testClassname} --color=always";
CLI::write($command);
passthru($command, $resultCode);
exit($resultCode);
}
CLI::write(
'The following locales have untranslated items:',
'light_gray',
'red'
);
exec($phpunit, $output, $resultCode);
$untranslatedLocales = [];
foreach ($output as $line) {
$pattern = '/\A\d+\) Translations\\\\(.*)"(.+?)"/';
if (preg_match($pattern, $line, $matches) === 1) {
$locale = $matches[2];
$untranslatedLocales[$locale] = $locale;
}
}
ksort($untranslatedLocales);
foreach ($untranslatedLocales as $locale) {
CLI::write($locale);
}
exit($resultCode);