Skip to content

Commit 62a11a8

Browse files
author
Andy Wermke
committed
Now throwing an error on missing 'locales' config on refresh command run.
1 parent 2bb5827 commit 62a11a8

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/JsLocalization/Console/RefreshCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace JsLocalization\Console;
33

4+
use Config;
45
use Illuminate\Console\Command;
56
use JsLocalization\Facades\CachingService;
67
use Symfony\Component\Console\Input\InputOption;
@@ -22,7 +23,7 @@ class RefreshCommand extends Command
2223
* @var string
2324
*/
2425
protected $description = "Refresh message cache after changing the config file";
25-
26+
2627
/**
2728
* Execute the console command.
2829
*
@@ -32,7 +33,13 @@ public function fire()
3233
{
3334
$this->line('Refreshing the message cache...');
3435

36+
$locales = Config::get('js-localization::config.locales');
37+
38+
if(!is_array($locales)) {
39+
throw new \Exception('Please set the "locales" config! See https://github.com/andywer/laravel-js-localization#configuration');
40+
}
41+
3542
CachingService::refreshMessageCache();
3643
}
3744

38-
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use JsLocalization\Console\RefreshCommand;
5+
6+
class RefreshCommandTest extends TestCase
7+
{
8+
9+
public function setUp ()
10+
{
11+
parent::setUp();
12+
}
13+
14+
public function tearDown ()
15+
{
16+
m::close();
17+
18+
parent::tearDown();
19+
}
20+
21+
public function testNoLocalesConfigException ()
22+
{
23+
// Mock Config
24+
Illuminate\Support\Facades\Config::swap($config = m::mock('ConfigMock'));
25+
26+
$config->shouldReceive('get')->with('js-localization::config.locales')
27+
->andReturn(null);
28+
29+
30+
$this->setExpectedException('Exception');
31+
32+
$this->runCommand();
33+
}
34+
35+
protected function runCommand ()
36+
{
37+
$cmd = new RefreshCommand();
38+
39+
$cmd->run(
40+
new Symfony\Component\Console\Input\ArrayInput(array('package' => 'foo')),
41+
new Symfony\Component\Console\Output\NullOutput
42+
);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)