|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maestriam\Samurai\Tests\Feature\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
6
|
|
|
use Maestriam\FileSystem\Support\FileSystem; |
|
7
|
|
|
use Maestriam\Samurai\Exceptions\DirectiveExistsException; |
|
8
|
|
|
use Maestriam\Samurai\Exceptions\InvalidThemeNameException; |
|
9
|
|
|
use Maestriam\Samurai\Tests\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class MakeIncludeCommandTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testMakeValidInclude() |
|
14
|
|
|
{ |
|
15
|
|
|
$theme = 'bands/slayer'; |
|
16
|
|
|
$name = 'songs/world-painted-blood'; |
|
17
|
|
|
$path = $this->simulatePath($name); |
|
18
|
|
|
|
|
19
|
|
|
$this->theme($theme)->findOrCreate()->use(); |
|
20
|
|
|
|
|
21
|
|
|
$info = sprintf('Include [%s] created into [%s]: %s', $name, $theme, $path); |
|
22
|
|
|
|
|
23
|
|
|
$cmd = sprintf("samurai:make-include %s %s", $name, $theme); |
|
24
|
|
|
|
|
25
|
|
|
$this->artisan($cmd)->expectsOutput($info)->assertExitCode(0); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testMakeIncludeWithReverseOrder() |
|
29
|
|
|
{ |
|
30
|
|
|
$theme = 'bands/slayer'; |
|
31
|
|
|
$name = 'mandatory-suicide'; |
|
32
|
|
|
|
|
33
|
|
|
$this->theme($theme)->findOrCreate()->use(); |
|
34
|
|
|
|
|
35
|
|
|
$cmd = sprintf("samurai:make-include %s %s", $theme, $name); |
|
36
|
|
|
|
|
37
|
|
|
$this->artisan($cmd)->assertExitCode(InvalidThemeNameException::CODE); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testMakeExistingInclude() |
|
41
|
|
|
{ |
|
42
|
|
|
$theme = 'bands/slayer'; |
|
43
|
|
|
$name = 'bloodline'; |
|
44
|
|
|
$code = DirectiveExistsException::CODE; |
|
45
|
|
|
$error = 'Error to create include: The [%s] directive already exists in [%s] theme.'; |
|
46
|
|
|
|
|
47
|
|
|
$this->theme($theme)->findOrCreate()->use(); |
|
48
|
|
|
|
|
49
|
|
|
$cmd = sprintf("samurai:make-include %s %s", $name, $theme); |
|
50
|
|
|
$msg = sprintf($error, $name, $theme); |
|
51
|
|
|
|
|
52
|
|
|
$this->artisan($cmd)->assertExitCode(0); |
|
53
|
|
|
$this->artisan($cmd)->expectsOutput($msg)->assertExitCode($code); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
private function simulatePath(string $sentence) : string |
|
57
|
|
|
{ |
|
58
|
|
|
$base = config('samurai.structure.include'); |
|
59
|
|
|
|
|
60
|
|
|
$path = sprintf('%s%s-include.blade.php', $base, $sentence); |
|
61
|
|
|
|
|
62
|
|
|
return FileSystem::folder($path)->sanitize(); |
|
63
|
|
|
} |
|
64
|
|
|
} |