1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: tony |
5
|
|
|
* Date: 12.03.19 |
6
|
|
|
* Time: 16:39 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Foundation\Tests; |
10
|
|
|
|
11
|
|
|
use Foundation\Generator\Events\CommandGeneratedEvent; |
12
|
|
|
use Foundation\Generator\Events\ControllerGeneratedEvent; |
13
|
|
|
use Foundation\Generator\Events\EventGeneratedEvent; |
14
|
|
|
use Foundation\Generator\Events\ListenerGeneratedEvent; |
15
|
|
|
use Foundation\Generator\Events\ModelGeneratedEvent; |
16
|
|
|
use Foundation\Generator\Events\ProviderGeneratedEvent; |
17
|
|
|
use Foundation\Generator\Events\ServiceGeneratedEvent; |
18
|
|
|
use Foundation\Generator\Events\TestGeneratedEvent; |
19
|
|
|
use Foundation\Generator\Factories\ModuleFactory; |
20
|
|
|
use Foundation\Traits\DisableRefreshDatabase; |
21
|
|
|
use Foundation\Traits\DispatchedEvents; |
22
|
|
|
use Illuminate\Support\Facades\Event; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class ModuleGeneratorTest |
26
|
|
|
* @package Foundation\Tests |
27
|
|
|
*/ |
28
|
|
|
class ModuleGeneratorTest extends \Foundation\Abstracts\Tests\TestCase |
29
|
|
|
{ |
30
|
|
|
use DisableRefreshDatabase, DispatchedEvents; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ModuleFactory |
34
|
|
|
*/ |
35
|
|
|
protected $moduleFactory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws \Nwidart\Modules\Exceptions\FileAlreadyExistException |
39
|
|
|
*/ |
40
|
|
|
public function setUp(): void |
41
|
|
|
{ |
42
|
|
|
parent::setUp(); |
43
|
|
|
$this->moduleFactory = new ModuleFactory("ARandomTestModule"); |
44
|
|
|
|
45
|
|
|
/* Do not remove this line. It prevents the listener that generates the file from executing */ |
46
|
|
|
Event::fake(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
|
|
public function testPiping() |
53
|
|
|
{ |
54
|
|
|
$this->moduleFactory->addController('TestController'); |
55
|
|
|
$this->moduleFactory->addTest('ServiceTest', 'service'); |
56
|
|
|
$pipeline = $this->moduleFactory->getPipeline(); |
57
|
|
|
|
58
|
|
|
$this->assertIsArray($pipeline); |
59
|
|
|
$this->assertEquals('Controller', $pipeline[0]['name']); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testModuleGeneration() |
63
|
|
|
{ |
64
|
|
|
$this->moduleFactory->addController('AController'); |
65
|
|
|
|
66
|
|
|
$this->moduleFactory->addModel('AModel', true, true); |
67
|
|
|
|
68
|
|
|
$this->moduleFactory->addTest('AServiceTest', 'service'); |
69
|
|
|
$this->moduleFactory->addTest('AHttpTest', 'http'); |
70
|
|
|
$this->moduleFactory->addTest('AUnitTest', 'unit'); |
71
|
|
|
|
72
|
|
|
$this->moduleFactory->addCommand('ACommand', 'command:dosomething'); |
73
|
|
|
|
74
|
|
|
$this->moduleFactory->addEvent('WasCreatedEvent'); |
75
|
|
|
$this->moduleFactory->addEvent('WasUpdatedEvent'); |
76
|
|
|
$this->moduleFactory->addEvent('WasDeletedEvent'); |
77
|
|
|
|
78
|
|
|
$this->moduleFactory->addListener('AListener', 'WasCreatedEvent'); |
79
|
|
|
|
80
|
|
|
$this->moduleFactory->addService('AService'); |
81
|
|
|
|
82
|
|
|
$this->moduleFactory->addRequest('ARequest'); |
83
|
|
|
|
84
|
|
|
$this->moduleFactory->addRoute('v1'); |
85
|
|
|
|
86
|
|
|
$this->moduleFactory->addComposer(); |
87
|
|
|
|
88
|
|
|
$this->moduleFactory->addMiddleware('AMiddleware'); |
89
|
|
|
|
90
|
|
|
$this->moduleFactory->addPolicy('APolicy'); |
91
|
|
|
|
92
|
|
|
$this->moduleFactory->addFactory('AModel'); |
93
|
|
|
|
94
|
|
|
$this->moduleFactory->addServiceProvider('AServiceProvider'); |
95
|
|
|
|
96
|
|
|
$this->moduleFactory->build(); |
97
|
|
|
|
98
|
|
|
/* @var ControllerGeneratedEvent $event */ |
99
|
|
|
$event = $this->getFirstDispatchedEvent(ControllerGeneratedEvent::class); |
100
|
|
|
$this->assertNotNull($event); |
101
|
|
|
$this->assertEquals("AController", $event->getClassName()); |
102
|
|
|
|
103
|
|
|
/* @var ModelGeneratedEvent $event */ |
104
|
|
|
$event = $this->getFirstDispatchedEvent(ModelGeneratedEvent::class); |
105
|
|
|
Event::assertDispatched(ModelGeneratedEvent::class, 1); |
106
|
|
|
$this->assertNotNull($event); |
107
|
|
|
$this->assertEquals("AModel", $event->getClassName()); |
108
|
|
|
$this->assertTrue($event->isMongoModel()); |
109
|
|
|
$this->assertTrue($event->includesMigration()); |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
/* @var TestGeneratedEvent[] $events */ |
113
|
|
|
$events = $this->getDispatchedEvents(TestGeneratedEvent::class); |
114
|
|
|
$this->assertNotEmpty($events); |
115
|
|
|
|
116
|
|
|
$this->assertEquals($events[0]->getClassName(), "AServiceTest"); |
117
|
|
|
$this->assertEquals($events[0]->getType(), "service"); |
118
|
|
|
|
119
|
|
|
$this->assertEquals($events[1]->getClassName(), "AHttpTest"); |
120
|
|
|
$this->assertEquals($events[1]->getType(), "http"); |
121
|
|
|
|
122
|
|
|
$this->assertEquals($events[2]->getClassName(), "AUnitTest"); |
123
|
|
|
$this->assertEquals($events[2]->getType(), "unit"); |
124
|
|
|
|
125
|
|
|
Event::assertDispatched(CommandGeneratedEvent::class, 1); |
126
|
|
|
|
127
|
|
|
/* @var CommandGeneratedEvent $event */ |
128
|
|
|
$event = $this->getFirstDispatchedEvent(CommandGeneratedEvent::class); |
129
|
|
|
$this->assertEquals("ACommand", $event->getClassName()); |
130
|
|
|
$this->assertEquals("command:dosomething", $event->getConsoleCommand()); |
131
|
|
|
$this->assertNotNull($event); |
132
|
|
|
|
133
|
|
|
/* @var EventGeneratedEvent $event */ |
134
|
|
|
Event::assertDispatched(EventGeneratedEvent::class, 3); |
135
|
|
|
$event = $this->getFirstDispatchedEvent(EventGeneratedEvent::class); |
136
|
|
|
$this->assertEquals("WasCreatedEvent", $event->getClassName()); |
137
|
|
|
$this->assertNotNull($event); |
138
|
|
|
|
139
|
|
|
/* @var ListenerGeneratedEvent $event */ |
140
|
|
|
$event = $this->getFirstDispatchedEvent(ListenerGeneratedEvent::class); |
141
|
|
|
$this->assertEquals("AListener", $event->getClassName()); |
142
|
|
|
$this->assertNotNull($event); |
143
|
|
|
|
144
|
|
|
/* @var ServiceGeneratedEvent $event */ |
145
|
|
|
$event = $this->getFirstDispatchedEvent(ServiceGeneratedEvent::class); |
146
|
|
|
$this->assertEquals("AService", $event->getClassName()); |
147
|
|
|
$this->assertNotNull($event); |
148
|
|
|
|
149
|
|
|
/* @var ProviderGeneratedEvent $event */ |
150
|
|
|
$event = $this->getFirstDispatchedEvent(ProviderGeneratedEvent::class); |
151
|
|
|
$this->assertEquals("AServiceProvider", $event->getClassName()); |
152
|
|
|
$this->assertNotNull($event); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|