JsLocalizationServiceProviderTest::testBindings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use JsLocalization\JsLocalizationServiceProvider;
4
use Symfony\Component\Console\Tester\CommandTester;
5
6
class JsLocalizationServiceProviderTest extends Orchestra\Testbench\TestCase
7
{
8
9
    protected function getPackageProviders($app)
10
    {
11
        return ['JsLocalization\JsLocalizationServiceProvider'];
12
    }
13
14
15
    public function testProvidesArray() {
16
        $service = new JsLocalizationServiceProvider($this->app);
17
18
        $this->assertEquals( $service->provides(), ['js-localization'] );
19
    }
20
21
    public function testRegisteredNamespaces()
22
    {
23
        $this->assertEquals(['en'], Config::get('js-localization.locales'));
24
        $this->assertEquals([], Config::get('js-localization.messages'));
25
        
26
        $this->assertArrayHasKey(
27
            'js-localization', View::getFinder()->getHints(),
28
            'View namespace not registered: js-localization'
29
        );
30
    }
31
32
    public function testRegisteredCommands()
33
    {
34
        $allCommands = Artisan::all();
35
        
36
        /** @var \Symfony\Component\Console\Command\Command $command */
37
        foreach ($allCommands as $command) {
38
            if ($command->getName() === 'js-localization:refresh') { break; }
39
        }
40
        
41
        $refreshCommand = $command;
0 ignored issues
show
Bug introduced by
The variable $command seems to be defined by a foreach iteration on line 37. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
42
        $this->assertInstanceOf('JsLocalization\Console\RefreshCommand', $refreshCommand);
43
44
        $commandTester = new CommandTester($refreshCommand);
45
        $commandTester->execute([]);
46
        $this->assertEquals("Refreshing the message cache...\n", $commandTester->getDisplay());
47
    }
48
49
    public function testBindings()
50
    {
51
        $helper = App::make('JsLocalizationHelper');
52
        $this->assertInstanceOf('JsLocalization\Utils\Helper', $helper);
53
54
        $cachingService = App::make('JsLocalizationMessageCachingService');
55
        $this->assertInstanceOf('JsLocalization\Caching\MessageCachingService', $cachingService);
56
    }
57
58
}
59