44
55namespace Yiisoft \Validator \Tests ;
66
7- use PHPUnit \Framework \TestCase ;
8- use Yiisoft \Di \Container ;
9- use Yiisoft \Di \ContainerConfig ;
107use Yiisoft \Translator \CategorySource ;
118use Yiisoft \Translator \SimpleMessageFormatter ;
129use Yiisoft \Validator \RuleHandlerResolverInterface ;
1310use Yiisoft \Validator \SimpleRuleHandlerContainer ;
1411use Yiisoft \Validator \Validator ;
1512use Yiisoft \Validator \ValidatorInterface ;
1613
17- use function dirname ;
18- use function extension_loaded ;
19-
20- final class ConfigTest extends TestCase
14+ final class ConfigTest extends BaseConfigTest
2115{
2216 public function testBase (): void
2317 {
@@ -52,42 +46,6 @@ public function testCustomTranslationCategory(): void
5246 $ this ->assertSame ('yii-validator-custom ' , $ translationCategorySource ->getName ());
5347 }
5448
55- public function testIntlMessageFormatter (): void
56- {
57- if (!extension_loaded ('intl ' )) {
58- $ this ->markTestSkipped ('The intl extension must be available for this test. ' );
59- }
60-
61- $ container = $ this ->createContainer ();
62-
63- /** @var CategorySource $translationCategorySource */
64- $ translationCategorySource =
$ container->
get (
'[email protected] ' )[
0 ];
65- $ message = '{n, selectordinal, one{#-one} two{#-two} few{#-few} other{#-other}} ' ;
66- // The default formatter argument is ignored in favor of formatter set in config.
67- $ this ->assertSame (
68- '1-one ' ,
69- $ translationCategorySource ->format ($ message , ['n ' => 1 ], 'en ' , new SimpleMessageFormatter ()),
70- );
71- }
72-
73- public function testSimpleMessageFormatter (): void
74- {
75- if (extension_loaded ('intl ' )) {
76- $ this ->markTestSkipped ('The intl extension must be unavailable for this test. ' );
77- }
78-
79- $ container = $ this ->createContainer ();
80-
81- /** @var CategorySource $translationCategorySource */
82- $ translationCategorySource =
$ container->
get (
'[email protected] ' )[
0 ];
83- $ message = '{n, selectordinal, one{#-one} two{#-two} few{#-few} other{#-other}} ' ;
84- // The default formatter argument is ignored in favor of formatter set in config.
85- $ this ->assertSame (
86- '1 ' ,
87- $ translationCategorySource ->format ($ message , ['n ' => 1 ], 'en ' , new SimpleMessageFormatter ()),
88- );
89- }
90-
9149 public function testTranslationCategorySource (): void
9250 {
9351 $ container = $ this ->createContainer ();
@@ -102,24 +60,17 @@ public function testTranslationCategorySource(): void
10260 $ this ->assertSame ('Значение неверно. ' , $ translationCategorySource ->getMessage ('This value is invalid. ' , 'ru ' ));
10361 }
10462
105- private function createContainer (array |null $ params = null ): Container
106- {
107- $ config = ContainerConfig::create ()->withDefinitions ($ this ->getCommonDefinitions ($ params ));
108-
109- return new Container ($ config );
110- }
111-
112- private function getCommonDefinitions (array |null $ params ): array
63+ public function testIntlMessageFormatter (): void
11364 {
114- if ($ params === null ) {
115- $ params = $ this ->getParams ();
116- }
117-
118- return require dirname (__DIR__ ) . '/config/common.php ' ;
119- }
65+ $ container = $ this ->createContainer ();
12066
121- private function getParams (): array
122- {
123- return require dirname (__DIR__ ) . '/config/params.php ' ;
67+ /** @var CategorySource $translationCategorySource */
68+ $ translationCategorySource =
$ container->
get (
'[email protected] ' )[
0 ];
69+ $ message = '{n, selectordinal, one{#-one} two{#-two} few{#-few} other{#-other}} ' ;
70+ // The default formatter argument is ignored in favor of formatter set in config.
71+ $ this ->assertSame (
72+ '1-one ' ,
73+ $ translationCategorySource ->format ($ message , ['n ' => 1 ], 'en ' , new SimpleMessageFormatter ()),
74+ );
12475 }
12576}
0 commit comments