1 | <?php |
||||
2 | |||||
3 | namespace Maestriam\Samurai\Tests\Feature\Console; |
||||
4 | |||||
5 | use Maestriam\Samurai\Exceptions\ThemeExistsException; |
||||
6 | use Maestriam\Samurai\Support\Samurai; |
||||
7 | use Maestriam\Samurai\Tests\TestCase; |
||||
8 | |||||
9 | class InitThemeCommandTest extends TestCase |
||||
10 | { |
||||
11 | /** |
||||
12 | * Verifica se consegue percorrer por todas as pessoas |
||||
13 | * |
||||
14 | * @param string $theme |
||||
15 | * @param string $author |
||||
16 | * @param string $desc |
||||
17 | * @return void |
||||
18 | */ |
||||
19 | public function testWizardPassesAllQuests() |
||||
20 | { |
||||
21 | $theme = 'bands/jethro-tull'; |
||||
22 | $author = 'Ian Anderson <ian@jethro tull.com>'; |
||||
23 | $descr = 'Aqualung, my friend'; |
||||
24 | |||||
25 | $this->assertSuccessfulWizard($theme, $author, $descr); |
||||
26 | } |
||||
27 | |||||
28 | /** |
||||
29 | * Verifica se consegue exibir a mensagem de erro |
||||
30 | * ao tentar criar um tema já existente com o wizard |
||||
31 | * |
||||
32 | * @return void |
||||
33 | */ |
||||
34 | public function testWizardWithExistingTheme() |
||||
35 | { |
||||
36 | $theme = 'bands/jethro-tull'; |
||||
37 | $error = 'The theme [%s] already exists in project.'; |
||||
38 | |||||
39 | Samurai::theme($theme)->make(); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
40 | |||||
41 | $this->assertFailedWizard($theme, $error); |
||||
42 | } |
||||
43 | |||||
44 | /** |
||||
45 | * Verifica se o wizard passou por todos os passos corretamente |
||||
46 | * e conseguiu criar o tema esperado. |
||||
47 | * |
||||
48 | * @param string $theme |
||||
49 | * @param string $author |
||||
50 | * @param string $desc |
||||
51 | * @return void |
||||
52 | */ |
||||
53 | private function assertSuccessfulWizard(string $theme, string $author, string $desc) |
||||
54 | { |
||||
55 | $quests = $this->getQuestions(); |
||||
56 | |||||
57 | $confirm = $this->getConfirmQuestions($theme, $author, $desc); |
||||
58 | |||||
59 | $output = sprintf('Theme [%s] created successful.', $theme); |
||||
60 | |||||
61 | $this->artisan('samurai:init') |
||||
62 | ->expectsQuestion($quests->theme->ask, $theme) |
||||
63 | ->expectsQuestion($quests->author->ask, $author) |
||||
64 | ->expectsQuestion($quests->desc->ask, $desc) |
||||
65 | ->expectsConfirmation($confirm->ask, 'yes') |
||||
66 | ->expectsOutput($output) |
||||
67 | ->assertExitCode(0); |
||||
68 | } |
||||
69 | |||||
70 | /** |
||||
71 | * Retorna as questões que serão utilizadas no Wizard. |
||||
72 | * |
||||
73 | * @return void |
||||
74 | */ |
||||
75 | private function getQuestions() : object |
||||
76 | { |
||||
77 | $theme = Samurai::wizard()->theme(); |
||||
0 ignored issues
–
show
The method
wizard() does not exist on Maestriam\Samurai\Support\Samurai . Since you implemented __callStatic , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
78 | $author = Samurai::wizard()->author(); |
||||
79 | $descr = Samurai::wizard()->description(); |
||||
80 | |||||
81 | return (object) [ |
||||
0 ignored issues
–
show
|
|||||
82 | 'theme' => $theme, |
||||
83 | 'author' => $author, |
||||
84 | 'desc' => $descr, |
||||
85 | ]; |
||||
86 | } |
||||
87 | |||||
88 | private function getConfirmQuestions($theme, $author, $desc) |
||||
89 | { |
||||
90 | return Samurai::wizard()->confirm($theme, $author, $desc); |
||||
91 | } |
||||
92 | |||||
93 | private function assertFailedWizard($theme, $error) |
||||
94 | { |
||||
95 | $error = sprintf($error, $theme); |
||||
96 | |||||
97 | $quests = $this->getQuestions(); |
||||
98 | $author = $quests->author->default; |
||||
99 | $desc = $quests->desc->default; |
||||
100 | |||||
101 | $confirm = $this->getConfirmQuestions($theme, $author, $desc); |
||||
102 | $message = sprintf('Error to create theme: %s', $error); |
||||
103 | |||||
104 | $this->artisan('samurai:init') |
||||
105 | ->expectsQuestion($quests->theme->ask, $theme) |
||||
106 | ->expectsQuestion($quests->author->ask, $author) |
||||
107 | ->expectsQuestion($quests->desc->ask, $desc) |
||||
108 | ->expectsConfirmation($confirm->ask, 'yes') |
||||
109 | ->expectsOutput($message); |
||||
110 | } |
||||
111 | } |