GetsActionCommandTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteDryRun() 0 17 1
testExecuteForce() 0 24 ?
A hp$0 ➔ testExecuteForce() 0 24 1
A hp$0 ➔ write() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Command\Controllers;
5
6
use PHPUnit\Framework\TestCase;
7
use SlayerBirden\DFCodeGeneration\Command\Hubby;
8
use SlayerBirden\DFCodeGeneration\Generator\Config\FileConfigProvider;
9
use SlayerBirden\DFCodeGeneration\Writer\WriteInterface;
10
use Symfony\Component\Console\Tester\CommandTester;
11
12
final class GetsActionCommandTest extends TestCase
13
{
14
    public function testExecuteDryRun()
15
    {
16
        $writer = $this->prophesize(WriteInterface::class);
17
        $tester = new CommandTester(new GetsActionCommand(null, $writer->reveal(), new FileConfigProvider()));
18
        $tester->execute([
19
            'entity' => Hubby::class,
20
        ]);
21
22
        $display = $tester->getDisplay();
23
24
        # controller
25
        $this->assertContains('GetHubbiesAction', $display);
26
        # config
27
        $this->assertContains('ConfigProvider', $display);
28
        # factories
29
        $this->assertContains('HubbyHydratorFactory', $display);
30
        $this->assertContains('HubbyRepositoryFactory', $display);
31
    }
32
33
    public function testExecuteForce()
34
    {
35
        $writer = new class implements WriteInterface {
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
36
            public $content = '';
37
38
            public function write(string $content, string $fileName): void
39
            {
40
                $this->content .= $content;
41
            }
42
        };
43
        $tester = new CommandTester(new GetsActionCommand(null, $writer, new FileConfigProvider()));
44
        $tester->execute([
45
            'entity' => Hubby::class,
46
            '--force' => true,
47
        ]);
48
49
        $content = $writer->content;
50
51
        $this->assertContains('GetHubbiesAction', $content);
52
        # config
53
        $this->assertContains('ConfigProvider', $content);
54
        # factories
55
        $this->assertContains('HubbyHydratorFactory', $content);
56
        $this->assertContains('HubbyRepositoryFactory', $content);
57
    }
58
}
59