File tree Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ public function loadNamespaces()
181
181
182
182
$ namespaces = new GeneratorNamespaces ();
183
183
184
- $ namespaces ->app = $ this -> command -> getLaravel ()->getNamespace ();
184
+ $ namespaces ->app = app ()->getNamespace ();
185
185
$ namespaces ->app = substr ($ namespaces ->app , 0 , strlen ($ namespaces ->app ) - 1 );
186
186
$ namespaces ->repository = config ('laravel_generator.namespace.repository ' , 'App\Repositories ' ).$ prefix ;
187
187
$ namespaces ->model = config ('laravel_generator.namespace.model ' , 'App\Models ' ).$ prefix ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use InfyOm \Generator \Facades \FileUtils ;
4
+ use InfyOm \Generator \Generators \API \APIControllerGenerator ;
5
+ use Mockery as m ;
6
+
7
+ beforeEach (function () {
8
+ FileUtils::fake ();
9
+ });
10
+
11
+ afterEach (function () {
12
+ m::close ();
13
+ });
14
+
15
+ test ('uses repository controller template ' , function () {
16
+
17
+ fakeGeneratorConfig ();
18
+
19
+ /** @var APIControllerGenerator $generator */
20
+ $ generator = app (APIControllerGenerator::class);
21
+
22
+ $ viewName = $ generator ->getViewName ();
23
+
24
+ expect ($ viewName )->toBe ('repository.controller ' );
25
+ });
26
+
27
+ test ('uses model controller template ' , function () {
28
+
29
+ config ()->set ('laravel_generator.options.repository_pattern ' , false );
30
+
31
+ fakeGeneratorConfig ();
32
+
33
+ /** @var APIControllerGenerator $generator */
34
+ $ generator = app (APIControllerGenerator::class);
35
+
36
+ $ viewName = $ generator ->getViewName ();
37
+
38
+ expect ($ viewName )->toBe ('model.controller ' );
39
+ });
40
+
41
+ test ('used resource repository controller template ' , function () {
42
+
43
+ config ()->set ('laravel_generator.options.resources ' , true );
44
+
45
+ fakeGeneratorConfig ();
46
+
47
+ /** @var APIControllerGenerator $generator */
48
+ $ generator = app (APIControllerGenerator::class);
49
+
50
+ $ viewName = $ generator ->getViewName ();
51
+
52
+ expect ($ viewName )->toBe ('repository.controller_resource ' );
53
+ });
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use Illuminate \Console \Command ;
4
+ use InfyOm \Generator \Common \GeneratorConfig ;
3
5
use Mockery as m ;
4
6
5
7
function mockShouldHaveCalledGenerateMethod (array $ shouldHaveCalledGenerators ): array
@@ -41,3 +43,33 @@ function mockShouldNotHaveCalledGenerateMethod(array $shouldNotHaveCalledGenerat
41
43
42
44
return $ mockedObjects ;
43
45
}
46
+
47
+ function fakeGeneratorConfig ()
48
+ {
49
+ $ fakeConfig = new GeneratorConfig ();
50
+ $ command = fakeGeneratorCommand ();
51
+ $ fakeConfig ->setCommand ($ command );
52
+ $ fakeConfig ->init ();
53
+
54
+ app ()->singleton (GeneratorConfig::class, function () use ($ fakeConfig ) {
55
+ return $ fakeConfig ;
56
+ });
57
+
58
+ return $ fakeConfig ;
59
+ }
60
+
61
+ function fakeGeneratorCommand ($ options = [])
62
+ {
63
+ $ mock = m::mock (Command::class);
64
+
65
+ $ mock ->shouldReceive ('argument ' )->withArgs (['model ' ])->andReturn ('FakeModel ' );
66
+ if (empty ($ options )) {
67
+ $ mock ->shouldReceive ('option ' )->withAnyArgs ()->andReturn ('' );
68
+ } else {
69
+ foreach ($ options as $ option => $ value ) {
70
+ $ mock ->shouldReceive ('option ' )->withArgs ([$ option ])->andReturn ($ value );
71
+ }
72
+ }
73
+
74
+ return $ mock ;
75
+ }
You can’t perform that action at this time.
0 commit comments