1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Loevgaard\DandomainConsignmentBundle\Tests; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Symfony\Component\Finder\Finder; |
9
|
|
|
use Symfony\Component\Yaml\Yaml; |
10
|
|
|
|
11
|
|
|
class YamlTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testRouting() |
14
|
|
|
{ |
15
|
|
|
$value = Yaml::parseFile(getcwd().'/Resources/config/routing.yml'); |
16
|
|
|
$this->assertTrue(is_array($value)); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testServices() |
20
|
|
|
{ |
21
|
|
|
$value = Yaml::parseFile(getcwd().'/Resources/config/services.yml'); |
22
|
|
|
$this->assertTrue(is_array($value)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testTranslationsValidYaml() |
26
|
|
|
{ |
27
|
|
|
$finder = new Finder(); |
28
|
|
|
$finder->files()->in(getcwd().'/Resources/translations'); |
29
|
|
|
foreach ($finder as $file) { |
30
|
|
|
$value = Yaml::parseFile($file->getPathname()); |
31
|
|
|
$this->assertTrue(is_array($value)); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testTranslations() |
36
|
|
|
{ |
37
|
|
|
$control = $this->flattenYamlFile(getcwd().'/Resources/translations/LoevgaardDandomainConsignmentBundle.en.yml'); |
38
|
|
|
|
39
|
|
|
$finder = new Finder(); |
40
|
|
|
$finder->files()->in(getcwd().'/Resources/translations'); |
41
|
|
|
foreach ($finder as $file) { |
42
|
|
|
$test = $this->flattenYamlFile($file->getPathname()); |
43
|
|
|
|
44
|
|
|
$this->assertSame($control, $test); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function flattenYamlFile(string $file): array |
49
|
|
|
{ |
50
|
|
|
$arr = Yaml::parseFile($file); |
51
|
|
|
$str = str_replace(['[', ']'], ['_', ''], urldecode(http_build_query($arr))); |
52
|
|
|
parse_str($str, $flat); |
53
|
|
|
|
54
|
|
|
$keys = array_keys($flat); |
55
|
|
|
sort($keys); |
56
|
|
|
|
57
|
|
|
return $keys; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|