1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TranslationFormBundle package. |
7
|
|
|
* |
8
|
|
|
* (c) David ALLIX <http://a2lix.fr> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace A2lix\TranslationFormBundle\Tests\Locale; |
15
|
|
|
|
16
|
|
|
use A2lix\TranslationFormBundle\Locale\SimpleProvider; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
18
|
|
|
|
19
|
|
|
class SimpleProviderTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
protected $locales; |
22
|
|
|
protected $defaultLocale; |
23
|
|
|
protected $requiredLocales; |
24
|
|
|
protected $provider; |
25
|
|
|
|
26
|
|
|
public function setUp(): void |
27
|
|
|
{ |
28
|
|
|
$this->locales = ['es', 'en', 'pt']; |
29
|
|
|
$this->defaultLocale = 'en'; |
30
|
|
|
$this->requiredLocales = ['es', 'en']; |
31
|
|
|
|
32
|
|
|
$this->provider = new SimpleProvider($this->locales, $this->defaultLocale, $this->requiredLocales); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testDefaultLocaleIsInLocales(): void |
36
|
|
|
{ |
37
|
|
|
// Get mock, without the constructor being called |
38
|
|
|
$mock = $this->getMockBuilder(SimpleProvider::class) |
39
|
|
|
->disableOriginalConstructor() |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
// Set expectations for constructor calls |
43
|
|
|
$this->expectException('InvalidArgumentException'); |
44
|
|
|
$this->expectExceptionMessage('Default locale `de` not found within the configured locales `[es,en]`.' |
45
|
|
|
.' Perhaps you need to add it to your `a2lix_translation_form.locales` bundle configuration?'); |
46
|
|
|
|
47
|
|
|
// Now call the constructor |
48
|
|
|
$reflectedClass = new \ReflectionClass(SimpleProvider::class); |
49
|
|
|
$constructor = $reflectedClass->getConstructor(); |
50
|
|
|
$constructor->invoke($mock, ['es', 'en'], 'de', []); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testRequiredLocaleAreInLocales(): void |
54
|
|
|
{ |
55
|
|
|
// Get mock, without the constructor being called |
56
|
|
|
$mock = $this->getMockBuilder(SimpleProvider::class) |
57
|
|
|
->disableOriginalConstructor() |
58
|
|
|
->getMock(); |
59
|
|
|
|
60
|
|
|
// Set expectations for constructor calls |
61
|
|
|
$this->expectException('InvalidArgumentException'); |
62
|
|
|
$this->expectExceptionMessage('Required locales should be contained in locales'); |
63
|
|
|
|
64
|
|
|
// Now call the constructor |
65
|
|
|
$reflectedClass = new \ReflectionClass(SimpleProvider::class); |
66
|
|
|
$constructor = $reflectedClass->getConstructor(); |
67
|
|
|
$constructor->invoke($mock, ['es', 'en'], 'en', ['en', 'pt']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testGetLocales(): void |
71
|
|
|
{ |
72
|
|
|
$expected = $this->provider->getLocales(); |
73
|
|
|
$locales = $this->locales; |
74
|
|
|
|
75
|
|
|
$this->assertSame(array_diff($expected, $locales), array_diff($locales, $expected)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testGetDefaultLocale(): void |
79
|
|
|
{ |
80
|
|
|
$expected = $this->provider->getDefaultLocale(); |
81
|
|
|
|
82
|
|
|
$this->assertSame($this->defaultLocale, $expected); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getRequiredLocales(): void |
86
|
|
|
{ |
87
|
|
|
$expected = $this->provider->getDefaultLocale(); |
88
|
|
|
$requiredLocales = $this->requiredLocales; |
89
|
|
|
|
90
|
|
|
$this->assertSame(array_diff($expected, $requiredLocales), array_diff($requiredLocales, $expected)); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths