|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Incenteev\TranslationCheckerBundle\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Incenteev\TranslationCheckerBundle\Tests\FixtureApp\TestKernel; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
9
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
10
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
11
|
|
|
|
|
12
|
|
|
class FunctionalTest extends KernelTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public static function setUpBeforeClass(): void |
|
15
|
|
|
{ |
|
16
|
|
|
self::deleteTmpDir(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public static function tearDownAfterClass(): void |
|
20
|
|
|
{ |
|
21
|
|
|
self::deleteTmpDir(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @dataProvider provideComparisonCases |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testCompareCommand(string $locale, bool $valid) |
|
28
|
|
|
{ |
|
29
|
|
|
self::bootKernel(); |
|
30
|
|
|
|
|
31
|
|
|
$application = new Application(self::$kernel); |
|
32
|
|
|
$application->setAutoExit(false); |
|
33
|
|
|
$application->setCatchExceptions(false); |
|
34
|
|
|
|
|
35
|
|
|
$input = new ArrayInput(array('command' => 'incenteev:translation:compare', 'locale' => $locale, '-d' => array('test'))); |
|
36
|
|
|
$output = new NullOutput(); |
|
37
|
|
|
|
|
38
|
|
|
$expectedExitCode = $valid ? 0 : 1; |
|
39
|
|
|
|
|
40
|
|
|
$this->assertSame($expectedExitCode, $application->run($input, $output)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @dataProvider provideComparisonCases |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testCompareCommandWithIcuTranslations(string $locale, bool $valid) |
|
47
|
|
|
{ |
|
48
|
|
|
self::bootKernel(); |
|
49
|
|
|
|
|
50
|
|
|
$application = new Application(self::$kernel); |
|
51
|
|
|
$application->setAutoExit(false); |
|
52
|
|
|
$application->setCatchExceptions(false); |
|
53
|
|
|
|
|
54
|
|
|
$input = new ArrayInput(array('command' => 'incenteev:translation:compare', 'locale' => $locale, '-d' => array('test_icu'))); |
|
55
|
|
|
$output = new NullOutput(); |
|
56
|
|
|
|
|
57
|
|
|
$expectedExitCode = $valid ? 0 : 1; |
|
58
|
|
|
|
|
59
|
|
|
$this->assertSame($expectedExitCode, $application->run($input, $output)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function provideComparisonCases(): iterable |
|
63
|
|
|
{ |
|
64
|
|
|
return array( |
|
65
|
|
|
array('fr', true), |
|
66
|
|
|
array('de', false), |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected static function getKernelClass(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return TestKernel::class; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private static function deleteTmpDir(): void |
|
76
|
|
|
{ |
|
77
|
|
|
if (!file_exists($dir = sys_get_temp_dir().'/incenteev_translation_checker')) { |
|
78
|
|
|
return; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$fs = new Filesystem(); |
|
82
|
|
|
$fs->remove($dir); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|