Completed
Push — master ( f81cf6...7fbbb0 )
by Oleg
03:40
created

AddActionCommandTest::testExecuteForce()

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
nc 1
nop 0
dl 0
loc 23
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A AddActionCommandTest.php$0 ➔ write() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Command;
5
6
use PHPUnit\Framework\TestCase;
7
use SlayerBirden\DFCodeGeneration\Command\Controllers\AddActionCommand;
8
use SlayerBirden\DFCodeGeneration\Util\CodeLoader;
9
use SlayerBirden\DFCodeGeneration\Writer\WriteInterface;
10
use Symfony\Component\Console\Tester\CommandTester;
11
12
class AddActionCommandTest extends TestCase
13
{
14
    public static function setUpBeforeClass()
15
    {
16
        $hubbyBody = <<<'HUBBY'
17
<?php
18
use Doctrine\ORM\Mapping as ORM;
19
/**
20
 * @ORM\Entity @ORM\Table(name="hubbies")
21
 */
22
class Hubby
23
{
24
    /**
25
     * @ORM\Id
26
     * @ORM\Column(type="string")
27
     * @var string
28
     */
29
    private $hubbyId;
30
    /**
31
     * @ORM\Column(type="string", nullable=true)
32
     * @var string
33
     */
34
    private $name;
35
}
36
HUBBY;
37
        CodeLoader::loadCode($hubbyBody, 'hubbyEntity.php');
38
    }
39
40
    public function testExecuteDryRun()
41
    {
42
        $writer = $this->prophesize(WriteInterface::class);
43
        $tester = new CommandTester(new AddActionCommand(null, $writer->reveal()));
44
        $tester->execute([
45
            'entity' => 'Hubby',
46
        ]);
47
48
        $display = $tester->getDisplay();
49
50
        # controller
51
        $this->assertContains('AddHubbyAction', $display);
52
        # config
53
        $this->assertContains('ConfigProvider', $display);
54
        # factories
55
        $this->assertContains('HubbyHydratorFactory', $display);
56
    }
57
58
    public function testExecuteForce()
59
    {
60
        $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...
61
            public $content = '';
62
63
            public function write(string $content, string $fileName): void
64
            {
65
                $this->content .= $content;
66
            }
67
        };
68
        $tester = new CommandTester(new AddActionCommand(null, $writer));
69
        $tester->execute([
70
            'entity' => 'Hubby',
71
            '--force' => true,
72
        ]);
73
74
        $content = $writer->content;
75
76
        $this->assertContains('AddHubbyAction', $content);
77
        # config
78
        $this->assertContains('ConfigProvider', $content);
79
        # factories
80
        $this->assertContains('HubbyHydratorFactory', $content);
81
    }
82
}
83