File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed
Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -58,10 +58,9 @@ class Console
5858 */
5959 public function __construct (Language $ language = null )
6060 {
61- if ($ language === null ) {
62- $ language = new Language ( ' en ' );
61+ if ($ language ) {
62+ $ this -> setLanguage ( $ language );
6363 }
64- $ this ->language = $ language ->addDirectory (__DIR__ . '/Languages ' );
6564 global $ argv ;
6665 $ this ->prepare ($ argv ?? []);
6766 $ this ->setDefaultCommands ();
@@ -130,14 +129,30 @@ public function getArgument(int $position) : ?string
130129 return $ this ->arguments [$ position ] ?? null ;
131130 }
132131
132+ /**
133+ * Set the Language instance.
134+ *
135+ * @param Language|null $language
136+ *
137+ * @return static
138+ */
139+ public function setLanguage (Language $ language = null ) : static
140+ {
141+ $ this ->language = $ language ?? new Language ();
142+ $ this ->language ->addDirectory (__DIR__ . '/Languages ' );
143+ return $ this ;
144+ }
145+
133146 /**
134147 * Get the Language instance.
135148 *
136149 * @return Language
137150 */
138- #[Pure]
139151 public function getLanguage () : Language
140152 {
153+ if (!isset ($ this ->language )) {
154+ $ this ->setLanguage ();
155+ }
141156 return $ this ->language ;
142157 }
143158
Original file line number Diff line number Diff line change 1212use Framework \CLI \Command ;
1313use Framework \CLI \Streams \Stderr ;
1414use Framework \CLI \Streams \Stdout ;
15+ use Framework \Language \Language ;
1516use PHPUnit \Framework \TestCase ;
1617
1718final class ConsoleTest extends TestCase
@@ -29,6 +30,17 @@ protected function tearDown() : void
2930 Stdout::reset ();
3031 }
3132
33+ public function testLanguage () : void
34+ {
35+ $ language = new Language ();
36+ $ console = new ConsoleMock ($ language );
37+ self ::assertSame ($ language , $ console ->getLanguage ());
38+ self ::assertContains (
39+ \realpath (__DIR__ . '/../src/Languages ' ) . \DIRECTORY_SEPARATOR ,
40+ $ console ->getLanguage ()->getDirectories ()
41+ );
42+ }
43+
3244 public function testEmptyLine () : void
3345 {
3446 $ this ->console ->prepare ([
You can’t perform that action at this time.
0 commit comments