1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shamaseen\Repository\Tests\Feature; |
4
|
|
|
|
5
|
|
|
use Shamaseen\Repository\PathResolver; |
6
|
|
|
use Shamaseen\Repository\Tests\TestCase; |
7
|
|
|
|
8
|
|
|
class GenerateFilesTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var mixed |
12
|
|
|
*/ |
13
|
|
|
private PathResolver $pathResolver; |
14
|
|
|
|
15
|
|
|
private array $filesToGenerate = ['Controller', 'Repository', 'Model', 'Request', 'Resource', 'Collection', 'Policy']; |
16
|
|
|
|
17
|
|
|
protected string $modelName = 'Test'; |
18
|
|
|
protected string $userPath = 'Tests'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param string $dataName |
22
|
|
|
*/ |
23
|
|
|
public function __construct(?string $name = null, array $data = [], $dataName = '') |
24
|
|
|
{ |
25
|
|
|
parent::__construct($name, $data, $dataName); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setUp(): void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
$this->pathResolver = new PathResolver($this->modelName, $this->userPath, config('repository.base_path')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testGenerate() |
35
|
|
|
{ |
36
|
|
|
$this->artisan("generate:repository $this->userPath/$this->modelName -f"); |
37
|
|
|
|
38
|
|
|
foreach ($this->filesToGenerate as $type) { |
39
|
|
|
$absolutePath = $this->pathResolver->absolutePath($type); |
40
|
|
|
|
41
|
|
|
$this->assertFileExists($absolutePath); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testGenerateMCROnly() |
46
|
|
|
{ |
47
|
|
|
$this->artisan("generate:repository $this->userPath/$this->modelName -f -mrc"); |
48
|
|
|
|
49
|
|
|
$filesToGenerate = ['Controller', 'Repository', 'Model']; |
50
|
|
|
foreach ($filesToGenerate as $type) { |
51
|
|
|
$absolutePath = $this->pathResolver->absolutePath($type); |
52
|
|
|
|
53
|
|
|
$this->assertFileExists($absolutePath); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|