Completed
Push — master ( 81ce9d...1672d9 )
by Oleg
03:54
created

ApiSuiteCommandTest::testExecuteWithTestsDryRun()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Command;
5
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Argument;
8
use Prophecy\Prophecy\ObjectProphecy;
9
use SlayerBirden\DFCodeGeneration\Util\CodeLoader;
10
use SlayerBirden\DFCodeGeneration\Writer\WriteInterface;
11
use Symfony\Component\Console\Application;
12
use Symfony\Component\Console\Tester\CommandTester;
13
14
class ApiSuiteCommandTest extends TestCase
15
{
16
    /**
17
     * @var ObjectProphecy
18
     */
19
    private $writer;
20
    /**
21
     * @var CommandTester
22
     */
23
    private $tester;
24
25
    public static function setUpBeforeClass()
26
    {
27
        $hubbyBody = <<<'HUBBY'
28
<?php
29
use Doctrine\ORM\Mapping as ORM;
30
/**
31
 * @ORM\Entity @ORM\Table(name="hubbies")
32
 */
33
class Hubby
34
{
35
    /**
36
     * @ORM\Id
37
     * @ORM\Column(type="string")
38
     * @var string
39
     */
40
    private $hubbyId;
41
    /**
42
     * @ORM\Column(type="string", nullable=true)
43
     * @var string
44
     */
45
    private $name;
46
}
47
HUBBY;
48
        CodeLoader::loadCode($hubbyBody, 'hubbyEntity.php');
49
50
    }
51
52
    protected function setUp()
53
    {
54
        $app = new Application();
55
56
        $this->writer = $this->prophesize(WriteInterface::class);
57
58
        $app->add(new ApiSuiteCommand(null, $this->writer->reveal()));
59
60
        $command = $app->find('generate:api');
61
        $this->tester = new CommandTester($command);
62
    }
63
64
    public function testExecuteWithoutTestsDryRun()
65
    {
66
        $this->tester->execute([
67
            'command' => 'generate:api',
68
            'entity' => 'Hubby',
69
        ]);
70
        $output = $this->tester->getDisplay();
71
72
        # controllers
73
        $this->assertContains('AddHubbyAction', $output);
74
        $this->assertContains('UpdateHubbyAction', $output);
75
        $this->assertContains('GetHubbyAction', $output);
76
        $this->assertContains('GetHubbiesAction', $output);
77
        $this->assertContains('DeleteHubbyAction', $output);
78
        # else
79
        $this->assertContains('HubbyRoutesDelegator', $output);
80
        $this->assertContains('ConfigProvider', $output);
81
82
        # no tests
83
        $this->assertNotContains('AddHubbyCest', $output);
84
    }
85
86
    public function testExecuteWithTestsDryRun()
87
    {
88
        $this->tester->execute([
89
            'command' => 'generate:api',
90
            'entity' => 'Hubby',
91
            '--tests' => true,
92
        ]);
93
        $output = $this->tester->getDisplay();
94
95
        # controllers
96
        $this->assertContains('AddHubbyAction', $output);
97
        $this->assertContains('UpdateHubbyAction', $output);
98
        $this->assertContains('GetHubbyAction', $output);
99
        $this->assertContains('GetHubbiesAction', $output);
100
        $this->assertContains('DeleteHubbyAction', $output);
101
        # else
102
        $this->assertContains('HubbyRoutesDelegator', $output);
103
        $this->assertContains('ConfigProvider', $output);
104
        # tests
105
        $this->assertContains('AddHubbyCest', $output);
106
        $this->assertContains('DeleteHubbyCest', $output);
107
        $this->assertContains('GetHubbyCest', $output);
108
        $this->assertContains('GetHubbiesCest', $output);
109
        $this->assertContains('UpdateHubbyCest', $output);
110
    }
111
112
    public function testExecuteWithoutTestsForce()
113
    {
114
        $this->tester->execute([
115
            'command' => 'generate:api',
116
            'entity' => 'Hubby',
117
            '--force' => true,
118
        ]);
119
120
        $this->writer->write(Argument::type('string'))->shouldHaveBeenCalledTimes(7);
121
122
        $output = $this->tester->getDisplay();
123
        $this->assertNotEmpty($output);
124
    }
125
126
    public function testExecuteWithTestsForce()
127
    {
128
        $this->tester->execute([
129
            'command' => 'generate:api',
130
            'entity' => 'Hubby',
131
            '--tests' => true,
132
            '--force' => true,
133
        ]);
134
135
        $this->writer->write(Argument::type('string'))->shouldHaveBeenCalledTimes(12);
136
137
        $output = $this->tester->getDisplay();
138
        $this->assertNotEmpty($output);
139
    }
140
}
141