diff --git a/src/LocaleSwitcher.php b/src/LocaleSwitcher.php index c503cb9..b0d70df 100644 --- a/src/LocaleSwitcher.php +++ b/src/LocaleSwitcher.php @@ -1,5 +1,6 @@ switchLocale(); if ($this->sessionHasLocale()) { - app()->setLocale($this->session->get(static::SESSION_KEY)); + $locale = $this->session->get(static::SESSION_KEY); + App::setLocale($locale); + return $locale; } } } diff --git a/tests/LocaleSwitcherTest.php b/tests/LocaleSwitcherTest.php index d288e5f..2287b09 100644 --- a/tests/LocaleSwitcherTest.php +++ b/tests/LocaleSwitcherTest.php @@ -115,4 +115,20 @@ public function it_uses_request_over_cookie() $this->assertEquals('fr', $newLocale); } + /** @test */ + public function it_sets_app_locale() + { + $this->request->shouldReceive('input')->zeroOrMoreTimes()->andReturn('fr'); + $this->session->shouldReceive('has')->zeroOrMoreTimes()->andReturn(true); + $this->session->shouldReceive('get')->zeroOrMoreTimes()->andReturn('fr'); + Illuminate\Support\Facades\App::shouldReceive('setLocale')->once(); + + $newLocale = $this->localeSwitcher->setAppLocale(); + + $this->assertTrue($this->localeSwitcher->localeWasSwitched()); + $this->assertNotEquals('', $newLocale); + $this->assertNotEquals('en', $newLocale); + $this->assertEquals('fr', $newLocale); + } + }