|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Incenteev\TranslationCheckerBundle\Tests\Translator\Extractor; |
|
4
|
|
|
|
|
5
|
|
|
use Incenteev\TranslationCheckerBundle\Translator\Extractor\SymfonyExtractor; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Prophecy\Argument; |
|
8
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
|
9
|
|
|
use Symfony\Component\Translation\MessageCatalogue; |
|
10
|
|
|
|
|
11
|
|
|
class SymfonyExtractorTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
use ProphecyTrait; |
|
14
|
|
|
|
|
15
|
|
|
private string $workingDir; |
|
16
|
|
|
|
|
17
|
|
|
public function testExtract() |
|
18
|
|
|
{ |
|
19
|
|
|
$symfonyExtractor = $this->prophesize('Symfony\Component\Translation\Extractor\ExtractorInterface'); |
|
20
|
|
|
|
|
21
|
|
|
$existingPaths = array( |
|
22
|
|
|
$this->workingDir.'/foo', |
|
23
|
|
|
$this->workingDir.'/bar', |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
foreach ($existingPaths as $dir) { |
|
27
|
|
|
mkdir($dir); |
|
28
|
|
|
} |
|
29
|
|
|
touch($this->workingDir.'/file'); |
|
30
|
|
|
|
|
31
|
|
|
$nonDirPaths = array( |
|
32
|
|
|
$this->workingDir.'/missing', |
|
33
|
|
|
$this->workingDir.'/file', |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
$paths = array_merge($existingPaths, $nonDirPaths); |
|
37
|
|
|
|
|
38
|
|
|
$catalogue = new MessageCatalogue('en'); |
|
39
|
|
|
|
|
40
|
|
|
$extractor = new SymfonyExtractor($symfonyExtractor->reveal(), $paths); |
|
41
|
|
|
|
|
42
|
|
|
$extractor->extract($catalogue); |
|
43
|
|
|
|
|
44
|
|
|
foreach ($existingPaths as $dir) { |
|
45
|
|
|
$symfonyExtractor->extract(Argument::exact($dir), Argument::exact($catalogue))->shouldHaveBeenCalled(); |
|
46
|
|
|
} |
|
47
|
|
|
foreach ($nonDirPaths as $path) { |
|
48
|
|
|
$symfonyExtractor->extract(Argument::exact($path), Argument::exact($catalogue))->shouldNotHaveBeenCalled(); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function setup(): void |
|
53
|
|
|
{ |
|
54
|
|
|
parent::setup(); |
|
55
|
|
|
|
|
56
|
|
|
$this->workingDir = sys_get_temp_dir().'/translation_checker'; |
|
57
|
|
|
|
|
58
|
|
|
if (is_dir($this->workingDir)) { |
|
59
|
|
|
$this->clean(); |
|
60
|
|
|
} else { |
|
61
|
|
|
mkdir($this->workingDir); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function tearDown(): void |
|
66
|
|
|
{ |
|
67
|
|
|
parent::tearDown(); |
|
68
|
|
|
$this->clean(); |
|
69
|
|
|
rmdir($this->workingDir); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function clean(): void |
|
73
|
|
|
{ |
|
74
|
|
|
foreach (glob($this->workingDir.'/*') ?: [] as $file) { |
|
75
|
|
|
if (is_dir($file)) { |
|
76
|
|
|
@rmdir($file); |
|
|
|
|
|
|
77
|
|
|
} else { |
|
78
|
|
|
@unlink($file); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: