Skip to content

Commit

Permalink
Figured out how to test Laravel's App facade
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksamson committed Sep 11, 2015
1 parent 90910b8 commit 8d52ec1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/LocaleSwitcher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Lykegenes\LaravelLocaleSwitcher;

use Illuminate\Support\Facades\App;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

Expand Down Expand Up @@ -172,7 +173,9 @@ public function setAppLocale()
$this->switchLocale();

if ($this->sessionHasLocale()) {
app()->setLocale($this->session->get(static::SESSION_KEY));
$locale = $this->session->get(static::SESSION_KEY);
App::setLocale($locale);
return $locale;
}
}
}
16 changes: 16 additions & 0 deletions tests/LocaleSwitcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 8d52ec1

Please sign in to comment.