FunctionalTest::testMaker()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 12
rs 9.9332
1
<?php
2
3
4
namespace Pfilsx\FormLayer\Tests;
5
6
use Pfilsx\FormLayer\Layer\EntityFormLayer;
7
use Pfilsx\FormLayer\Maker\MakeFormLayer;
8
use Pfilsx\FormLayer\Tests\app\Entity\Node;
9
use Symfony\Bundle\MakerBundle\Command\MakerCommand;
10
use Symfony\Component\Console\Input\ArrayInput;
11
use Symfony\Component\Console\Input\StringInput;
12
use Symfony\Component\Console\Output\BufferedOutput;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Filesystem\Filesystem;
15
use Symfony\Component\Process\InputStream;
16
17
class FunctionalTest extends KernelTestCase
18
{
19
    /**
20
     * @var string
21
     */
22
    private $app_path;
23
24
    protected function setUp(): void
25
    {
26
        $this->app_path = dirname(__DIR__) . '/app';
27
        parent::setUp();
28
    }
29
30
    public function testWiring()
31
    {
32
        $class = MakeFormLayer::class;
33
        $commandName = $class::getCommandName();
34
        $this->assertEquals('make:form-layer', $commandName);
35
        $command = $this->application->find($commandName);
36
        $this->assertInstanceOf(MakerCommand::class, $command);
37
    }
38
39
    /**
40
     * @dataProvider getCommands
41
     * @param $name
42
     * @param $entity
43
     * @param $result
44
     */
45
    public function testMaker($name, $entity, $result)
46
    {
47
        $input = new StringInput("make:form-layer $name $entity");
48
        $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
49
        $this->application->run($input, $output);
50
        $filePath = $this->app_path . "/FormLayer/$name.php";
51
        $this->assertTrue(is_file($filePath));
52
        $layerClass = "Pfilsx\\FormLayer\\Tests\\app\\FormLayer\\$name";
53
        $layer = new $layerClass();
54
        $this->assertInstanceOf(EntityFormLayer::class, $layer);
55
        $this->assertEquals($result, get_object_vars($layer));
56
        @unlink($filePath);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

56
        /** @scrutinizer ignore-unhandled */ @unlink($filePath);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
57
    }
58
59
    public function getCommands()
60
    {
61
        yield [
62
            'FooBarTestFormLayer',
63
            null,
64
            ['form_field' => null]
65
        ];
66
        yield [
67
            'NodeTestFormLayer',
68
            'Node',
69
            [
70
                'id' => null,
71
                'content' => null,
72
                'user' => null,
73
                'parentId' => null,
74
                'createdAt' => null,
75
                'mainNode' => null
76
            ]
77
        ];
78
        yield [
79
            'ModelTestFormLayer',
80
            'Model',
81
            [
82
                'id' => null,
83
                'content' => null,
84
                'createdAt' => null
85
            ]
86
        ];
87
    }
88
}
89