Passed
Push — master ( 590453...ad5a85 )
by Arthur
24:49
created

ModuleGeneratorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testPiping() 0 8 1
A testModuleGeneration() 0 43 1
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\TestGeneratedEvent;
14
use Foundation\Generator\Generators\ModuleGenerator;
15
use Foundation\Traits\DisableRefreshDatabase;
16
use Foundation\Traits\DispatchedEvents;
17
use Illuminate\Support\Facades\Event;
18
19
/**
20
 * Class ModuleGeneratorTest
21
 * @package Foundation\Tests
22
 */
23
class ModuleGeneratorTest extends \Foundation\Abstracts\Tests\TestCase
24
{
25
    use DisableRefreshDatabase, DispatchedEvents;
26
27
28
    /**
29
     * @var ModuleGenerator
30
     */
31
    protected $generator;
32
33
    /**
34
     * @throws \Nwidart\Modules\Exceptions\FileAlreadyExistException
35
     */
36
    public function setUp(): void
37
    {
38
        parent::setUp();
39
        $this->generator = new ModuleGenerator("ARandomTestModule");
40
41
        /* Do not remove this line. It prevents the listener that generates the file from executing */
42
        Event::fake();
43
    }
44
45
46
    /**
47
     *
48
     */
49
    public function testPiping()
50
    {
51
        $this->generator->addController('TestController');
52
        $this->generator->addTest('ServiceTest', 'service');
53
        $pipeline = $this->generator->getPipeline();
54
55
        $this->assertIsArray($pipeline);
56
        $this->assertEquals('Controller', $pipeline[0]['name']);
57
    }
58
59
    public function testModuleGeneration()
60
    {
61
62
63
        $this->generator->addController($controller = 'AController');
64
65
        $this->generator->addTest($serviceTest = 'AServiceTest', $serviceType ='service');
66
        $this->generator->addTest($httpTest = 'AHttpTest', $httpType ='http');
67
        $this->generator->addTest($unitTest = 'AUnitTest', $unitType ='unit');
68
69
        $this->generator->addCommand($command = 'ACommand', $commandName = 'command:dosomething');
70
71
72
        $this->generator->generate();
73
74
        /* @var ControllerGeneratedEvent $event */
75
        $event = $this->getFirstDispatchedEvent(ControllerGeneratedEvent::class);
76
        $this->assertNotNull($event);
77
        $this->assertEquals($controller, $event->getClassName());
78
79
80
        Event::assertDispatched(TestGeneratedEvent::class, 3);
81
82
        /* @var TestGeneratedEvent[] $events */
83
        $events = $this->getDispatchedEvents(TestGeneratedEvent::class);
84
        $this->assertNotEmpty($events);
85
86
        //TODO FIX TESTS!
87
        /*$this->assertEquals($events[0]->getClassName(),$serviceTest);
88
        $this->assertEquals($events[0]->getType(),$serviceType);
89
90
        $this->assertEquals($events[1]->getClassName(),$httpTest);
91
        $this->assertEquals($events[1]->getType(),$httpType);
92
93
        $this->assertEquals($events[2]->getClassName(),$unitTest);
94
        $this->assertEquals($events[2]->getType(),$unitType);*/
95
96
        Event::assertDispatched(CommandGeneratedEvent::class, 1);
97
98
        /* @var CommandGeneratedEvent $event */
99
        $event = $this->getFirstDispatchedEvent(CommandGeneratedEvent::class);
100
        $this->assertEquals($commandName, $event->getConsoleCommand());
101
        $this->assertNotNull($event);
102
103
104
    }
105
}
106