File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,20 @@ public function store($locale)
7575 }
7676 }
7777
78+ /**
79+ * Set the supported locales.
80+ *
81+ * @param array $locales
82+ *
83+ * @return \CodeZero\Localizer\Localizer
84+ */
85+ public function setSupportedLocales (array $ locales )
86+ {
87+ $ this ->locales = $ locales ;
88+
89+ return $ this ;
90+ }
91+
7892 /**
7993 * Check if the given locale is supported.
8094 *
Original file line number Diff line number Diff line change @@ -99,4 +99,20 @@ public function it_accepts_class_names_instead_of_instances_in_the_constructor()
9999 $ localizer ->detect ();
100100 $ localizer ->store ('nl ' );
101101 }
102+
103+ /** @test */
104+ public function you_can_set_the_supported_locales_at_runtime ()
105+ {
106+ $ supportedLocales = ['en ' ];
107+ $ detectors = [
108+ Mockery::mock (Detector::class)->allows ()->detect ()->andReturns ('en ' )->getMock (),
109+ Mockery::mock (Detector::class)->allows ()->detect ()->andReturns ('nl ' )->getMock (),
110+ ];
111+
112+ $ localizer = new Localizer ($ supportedLocales , $ detectors );
113+ $ value = $ localizer ->setSupportedLocales (['nl ' ]);
114+
115+ $ this ->assertEquals ('nl ' , $ localizer ->detect ());
116+ $ this ->assertEquals ($ localizer , $ value );
117+ }
102118}
You can’t perform that action at this time.
0 commit comments