|
14 | 14 | use Symfony\Contracts\Translation\TranslatorInterface; |
15 | 15 | use Twig\Test\IntegrationTestCase; |
16 | 16 |
|
17 | | -/** |
18 | | - * Class FileSizeExtensionTest. |
19 | | - */ |
20 | | -class FileSizeExtensionTest extends IntegrationTestCase |
| 17 | +final class FileSizeExtensionTest extends IntegrationTestCase |
21 | 18 | { |
22 | | - /** |
23 | | - * @param string $locale |
24 | | - */ |
25 | | - protected $locale; |
26 | | - |
27 | | - /** |
28 | | - * @param array $suffixes |
29 | | - */ |
30 | | - protected $suffixes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB']; |
31 | | - |
32 | | - /** |
33 | | - * @param TranslatorInterface|MockObject |
34 | | - */ |
35 | | - protected $translatorMock; |
36 | | - |
37 | | - /** |
38 | | - * @param ConfigResolverInterface|MockObject |
39 | | - */ |
40 | | - protected $configResolverInterfaceMock; |
41 | | - |
42 | | - /** |
43 | | - * @param LocaleConverterInterface|MockObject |
44 | | - */ |
45 | | - protected $localeConverterInterfaceMock; |
46 | | - |
47 | | - /** |
48 | | - * @param string $locale |
49 | | - * @param string $defaultLocale |
50 | | - */ |
| 19 | + protected string $locale = ''; |
| 20 | + |
| 21 | + /** @var string[] */ |
| 22 | + protected array $suffixes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB']; |
| 23 | + |
| 24 | + protected TranslatorInterface & MockObject $translatorMock; |
| 25 | + |
| 26 | + protected ConfigResolverInterface & MockObject $configResolverInterfaceMock; |
| 27 | + |
| 28 | + protected LocaleConverterInterface & MockObject $localeConverterInterfaceMock; |
| 29 | + |
51 | 30 | protected function setConfigurationLocale( |
52 | | - $locale, |
53 | | - $defaultLocale |
54 | | - ) { |
| 31 | + string $locale, |
| 32 | + string $defaultLocale |
| 33 | + ): void { |
55 | 34 | locale_set_default($defaultLocale); |
56 | 35 | $this->locale = $locale; |
57 | 36 | } |
58 | 37 |
|
59 | | - /** |
60 | | - * @return string $locale |
61 | | - */ |
62 | | - public function getLocale() |
| 38 | + public function getLocale(): string |
63 | 39 | { |
64 | | - return [$this->locale]; |
| 40 | + return $this->locale; |
65 | 41 | } |
66 | 42 |
|
67 | | - /** |
68 | | - * @return array |
69 | | - */ |
70 | | - protected function getExtensions() |
| 43 | + protected function getExtensions(): array |
71 | 44 | { |
72 | 45 | return [ |
73 | 46 | new FileSizeExtension($this->getTranslatorInterfaceMock(), $this->suffixes, $this->getConfigResolverInterfaceMock(), $this->getLocaleConverterInterfaceMock()), |
74 | 47 | ]; |
75 | 48 | } |
76 | 49 |
|
77 | | - protected function getFixturesDir(): string |
| 50 | + protected static function getFixturesDirectory(): string |
78 | 51 | { |
79 | 52 | return __DIR__ . '/_fixtures/functions/ibexa_file_size'; |
80 | 53 | } |
81 | 54 |
|
82 | | - /** |
83 | | - * @return ConfigResolverInterface|MockObject |
84 | | - */ |
85 | | - protected function getConfigResolverInterfaceMock() |
| 55 | + protected function getConfigResolverInterfaceMock(): ConfigResolverInterface & MockObject |
86 | 56 | { |
87 | 57 | $configResolverInterfaceMock = $this->createMock(ConfigResolverInterface::class); |
88 | | - $configResolverInterfaceMock->expects(self::any()) |
| 58 | + $configResolverInterfaceMock->expects(self::atLeastOnce()) |
89 | 59 | ->method('getParameter') |
90 | 60 | ->with('languages') |
91 | | - ->will(self::returnValue($this->getLocale())); |
| 61 | + ->willReturn([$this->getLocale()]); |
92 | 62 |
|
93 | 63 | return $configResolverInterfaceMock; |
94 | 64 | } |
95 | 65 |
|
96 | | - /** |
97 | | - * @return LocaleConverterInterface|MockObject |
98 | | - */ |
99 | | - protected function getLocaleConverterInterfaceMock() |
| 66 | + protected function getLocaleConverterInterfaceMock(): LocaleConverterInterface & MockObject |
100 | 67 | { |
101 | 68 | $this->localeConverterInterfaceMock = $this->createMock(LocaleConverterInterface::class); |
102 | | - $this->localeConverterInterfaceMock->expects(self::any()) |
| 69 | + $this->localeConverterInterfaceMock->expects(self::atLeastOnce()) |
103 | 70 | ->method('convertToPOSIX') |
104 | | - ->will( |
105 | | - self::returnValueMap( |
106 | | - [ |
107 | | - ['fre-FR', 'fr-FR'], |
108 | | - ['eng-GB', 'en-GB'], |
109 | | - ] |
110 | | - ) |
| 71 | + ->willReturnMap( |
| 72 | + [ |
| 73 | + ['fre-FR', 'fr-FR'], |
| 74 | + ['eng-GB', 'en-GB'], |
| 75 | + ] |
111 | 76 | ); |
112 | 77 |
|
113 | 78 | return $this->localeConverterInterfaceMock; |
114 | 79 | } |
115 | 80 |
|
116 | | - /** |
117 | | - * @return TranslatorInterface|MockObject |
118 | | - */ |
119 | | - protected function getTranslatorInterfaceMock() |
| 81 | + protected function getTranslatorInterfaceMock(): TranslatorInterface & MockObject |
120 | 82 | { |
121 | | - $that = $this; |
122 | 83 | $this->translatorMock = $this->createMock(TranslatorInterface::class); |
123 | 84 | $this->translatorMock |
124 | | - ->expects(self::any())->method('trans')->will( |
125 | | - self::returnCallback( |
126 | | - static function ($suffixes) use ($that) { |
127 | | - foreach ($that->getLocale() as $value) { |
128 | | - if ($value === 'fre-FR') { |
129 | | - return $suffixes . ' French version'; |
130 | | - } elseif ($value === 'eng-GB') { |
131 | | - return $suffixes . ' English version'; |
132 | | - } else { |
133 | | - return $suffixes . ' wrong local so we take the default one which is en-GB here'; |
134 | | - } |
135 | | - } |
136 | | - } |
137 | | - ) |
| 85 | + ->expects(self::atLeastOnce()) |
| 86 | + ->method('trans')->willReturnCallback( |
| 87 | + function ($suffixes): string { |
| 88 | + return match ($this->getLocale()) { |
| 89 | + 'fre-FR' => $suffixes . ' French version', |
| 90 | + 'eng-GB' => $suffixes . ' English version', |
| 91 | + default => $suffixes . ' wrong locale so we take the default one which is en-GB here', |
| 92 | + }; |
| 93 | + } |
138 | 94 | ); |
139 | 95 |
|
140 | 96 | return $this->translatorMock; |
|
0 commit comments