Failed Conditions
Branch feature/refactoring-samurai (8cc7c1)
by Giuliano
03:49
created

testMakeExistingInclude()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Maestriam\Samurai\Tests\Feature\Console;
4
5
use Maestriam\FileSystem\Support\FileSystem;
6
use Maestriam\Samurai\Exceptions\DirectiveExistsException;
7
use Maestriam\Samurai\Exceptions\InvalidThemeNameException;
8
use Maestriam\Samurai\Tests\TestCase;
9
10
class MakeComponentCommandTest extends TestCase
11
{    
12
    public function testMakeValidComponent()
13
    {
14
        $theme = 'bands/sepultura';
15
        $name  = 'roots-blood-roots';
16
        $path  = $this->simulatePath($name);
17
        
18
        $this->theme($theme)->findOrCreate()->use();
19
20
        $info = sprintf('Component [%s] created into [%s]: %s', $name, $theme, $path);
21
22
        $cmd = sprintf("samurai:make-component %s %s", $name, $theme);
23
24
        $this->artisan($cmd)->expectsOutput($info)->assertExitCode(0);
25
    }
26
27
    public function testMakeComponentWithReverseOrder()
28
    {
29
        $theme = 'bands/sepultura';
30
        $name  = 'roots-blood-roots';
31
32
        $this->theme($theme)->findOrCreate()->use();
33
34
        $cmd = sprintf("samurai:make-component %s %s", $theme, $name);
35
36
        $this->artisan($cmd)->assertExitCode(InvalidThemeNameException::CODE);
0 ignored issues
show
Bug introduced by
Maestriam\Samurai\Except...hemeNameException::CODE of type string is incompatible with the type integer expected by parameter $exitCode of Illuminate\Testing\Pendi...mmand::assertExitCode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        $this->artisan($cmd)->assertExitCode(/** @scrutinizer ignore-type */ InvalidThemeNameException::CODE);
Loading history...
37
    }
38
39
    public function testMakeExistingInclude()
40
    {
41
        $theme = 'bands/sepultura';
42
        $name  = 'roots-blood-roots';
43
        $error = 'Error to create component: The [%s] directive already exists in [%s] theme.';
44
45
        $this->theme($theme)->findOrCreate()->use();
46
47
        $cmd = sprintf("samurai:make-component %s %s", $name, $theme);
48
        $msg = sprintf($error, $name, $theme);
49
50
        $this->artisan($cmd)
51
             ->assertExitCode(0);
52
53
        $this->artisan($cmd)
54
             ->expectsOutput($msg)
55
             ->assertExitCode(DirectiveExistsException::CODE);
0 ignored issues
show
Bug introduced by
Maestriam\Samurai\Except...veExistsException::CODE of type string is incompatible with the type integer expected by parameter $exitCode of Illuminate\Testing\Pendi...mmand::assertExitCode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
             ->assertExitCode(/** @scrutinizer ignore-type */ DirectiveExistsException::CODE);
Loading history...
56
57
    }
58
59
    private function simulatePath(string $sentence) : string
60
    {
61
        $base = config('samurai.structure.component');
62
63
        $ext = 'component.blade.php';
64
65
        $path = sprintf('/%s%s-%s', $base, $sentence, $ext); 
66
67
        return FileSystem::folder($path)->sanitize();
68
    }
69
}