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); |
|
|
|
|
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); |
|
|
|
|
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
|
|
|
} |