1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maestriam\Samurai\Tests; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Application; |
6
|
|
|
use Orchestra\Testbench\TestCase as BaseTestCase; |
7
|
|
|
use Maestriam\FileSystem\Providers\FileSystemProvider; |
8
|
|
|
use Maestriam\FileSystem\Support\FileSystem; |
9
|
|
|
use Maestriam\Samurai\Entities\Component; |
10
|
|
|
use Maestriam\Samurai\Entities\Includer; |
11
|
|
|
use Maestriam\Samurai\Entities\Theme; |
12
|
|
|
use Maestriam\Samurai\Providers\SamuraiServiceProvider; |
13
|
|
|
|
14
|
|
|
class TestCase extends BaseTestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritDoc} |
18
|
|
|
*/ |
19
|
|
|
public function setUp(): void |
20
|
|
|
{ |
21
|
|
|
parent::setUp(); |
22
|
|
|
$this->initSandBox(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritDoc} |
27
|
|
|
*/ |
28
|
|
|
public function tearDown() : void |
29
|
|
|
{ |
30
|
|
|
$this->clearSandBox(); |
31
|
|
|
parent::tearDown(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
protected function getPackageProviders($app): array |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
FileSystemProvider::class, |
41
|
|
|
SamuraiServiceProvider::class |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritDoc} |
47
|
|
|
*/ |
48
|
|
|
protected function getEnvironmentSetUp($app) |
49
|
|
|
{ |
50
|
|
|
$this->registerLaravelConfig($app); |
51
|
|
|
|
52
|
|
|
$app['config']->set('samurai', [ |
53
|
|
|
|
54
|
|
|
'prefix' => 'samurai-theme', |
55
|
|
|
'env_key' => 'THEME_CURRENT', |
56
|
|
|
'env_file' => '.env.testing', |
57
|
|
|
'publishable' => 'themes', |
58
|
|
|
'description' => 'A new awsome theme is comming!', |
59
|
|
|
'template_path' => __DIR__ . '/../stubs/', |
60
|
|
|
|
61
|
|
|
'species' => [ |
62
|
|
|
'component', 'include' |
63
|
|
|
], |
64
|
|
|
|
65
|
|
|
'themes' => [ |
66
|
|
|
'files' => 'src', |
67
|
|
|
'assets' => 'assets', |
68
|
|
|
'folder' => __DIR__ . '/../sandbox', |
69
|
|
|
], |
70
|
|
|
|
71
|
|
|
'author' => [ |
72
|
|
|
'name' => 'Giuliano Sampaio', |
73
|
|
|
'dist' => 'maestriam', |
74
|
|
|
'email' => '[email protected]', |
75
|
|
|
], |
76
|
|
|
|
77
|
|
|
'structure' => [ |
78
|
|
|
'composer' => '.', |
79
|
|
|
'include' => 'src/', |
80
|
|
|
'component' => 'src/', |
81
|
|
|
] |
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Afirma que a classe possui determinada função |
87
|
|
|
* |
88
|
|
|
* @param mixed $obj |
89
|
|
|
* @param string $function |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
protected function assertObjectHasFunction($obj, string $function) |
93
|
|
|
{ |
94
|
|
|
$exists = method_exists($obj, $function); |
95
|
|
|
|
96
|
|
|
$this->assertTrue($exists); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Afirma se a váriavel se trata de uma instância Theme válida. |
101
|
|
|
* |
102
|
|
|
* @param mixed $theme |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
protected function assertValidTheme($theme) |
106
|
|
|
{ |
107
|
|
|
$this->assertInstanceOf(Theme::class, $theme); |
108
|
|
|
$this->assertTrue($theme->exists()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Afirma se a váriavel se trata de uma instância Component válida. |
113
|
|
|
* |
114
|
|
|
* @param mixed $component |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
|
|
protected function assertValidComponent($component) |
118
|
|
|
{ |
119
|
|
|
$this->assertInstanceOf(Component::class, $component); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Afirma se a váriavel se trata de uma instância Includer válida. |
124
|
|
|
* |
125
|
|
|
* @param mixed $includer |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
|
|
protected function assertValidIncluder($includer) |
129
|
|
|
{ |
130
|
|
|
$this->assertInstanceOf(Includer::class, $includer); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Cria um novo diretório para testes |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
protected function initSandBox() |
139
|
|
|
{ |
140
|
|
|
$sandbox = config('samurai.themes.folder'); |
141
|
|
|
|
142
|
|
|
FileSystem::folder($sandbox)->create(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Retorna a instância de um tema |
147
|
|
|
* |
148
|
|
|
* @param string $package |
149
|
|
|
* @return Theme |
150
|
|
|
*/ |
151
|
|
|
protected function theme(string $package) : Theme |
152
|
|
|
{ |
153
|
|
|
return new Theme($package); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Remove o diretório de conteúdo de testes |
158
|
|
|
* |
159
|
|
|
* @return void |
160
|
|
|
*/ |
161
|
|
|
protected function clearSandBox($folder = null) |
|
|
|
|
162
|
|
|
{ |
163
|
|
|
$sandbox = config('samurai.themes.folder'); |
164
|
|
|
|
165
|
|
|
FileSystem::folder($sandbox)->delete(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Registra as configurações do Laravel para o pacote. |
170
|
|
|
* |
171
|
|
|
* @param Application $app |
172
|
|
|
* @return void |
173
|
|
|
*/ |
174
|
|
|
protected function registerLaravelConfig(Application $app) |
175
|
|
|
{ |
176
|
|
|
$app['config']->set('view', [ |
177
|
|
|
'compiled' => storage_path('framework/views'), |
178
|
|
|
'paths' => [resource_path('views')] |
179
|
|
|
]); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.