Passed
Push — master ( 743cc2...6ffec3 )
by Oleg
02:50
created

DeleteTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
B testGenerate() 0 24 2
A initDangerMessage() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Controllers;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Argument;
9
use Prophecy\Prophecy\ObjectProphecy;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Log\LoggerInterface;
12
use SlayerBirden\DFCodeGeneration\CodeLoader;
13
use SlayerBirden\DFCodeGeneration\PrintFileTrait;
14
use Zend\Diactoros\ServerRequest;
15
use Zend\Expressive\Handler\NotFoundHandler;
16
use Zend\Hydrator\ExtractionInterface;
17
18
class DeleteTest extends TestCase
19
{
20
    use PrintFileTrait;
21
    /**
22
     * @var ObjectProphecy
23
     */
24
    private $provider;
25
26
    protected function setUp()
27
    {
28
        $this->provider = $this->prophesize(DataProviderInterface::class);
29
        $this->provider->provide()->willReturn([
30
            'ns' => 'Dummy\\Controller',
31
            'entityName' => 'User',
32
            'hasUnique' => false,
33
            'uniqueIdxMessage' => 'Test Constraint violation',
34
            'useStatement' => 'Dummy\\Entities\\User',
35
            'dataRelationship' => '// testing here',
36
        ]);
37
        $this->provider->getClassName(Argument::type('string'))->willReturn('Dummy\\Controller\\DeleteUserAction');
38
    }
39
40
    public function testGenerate()
41
    {
42
        $generator = new Delete($this->provider->reveal());
43
44
        $body = $generator->generate();
45
46
        try {
47
            CodeLoader::loadCode($body, 'DeleteUserAction.php');
48
            $className = $generator->getClassName();
49
            $deleteAction = new $className(
50
                $this->prophesize(EntityManagerInterface::class)->reveal(),
51
                $this->prophesize(LoggerInterface::class)->reveal(),
52
                $this->prophesize(ExtractionInterface::class)->reveal()
53
            );
54
            $request = new ServerRequest();
55
            $delegator = $this->prophesize(NotFoundHandler::class);
56
            $this->initDangerMessage();
57
            $resp = $deleteAction->process($request, $delegator->reveal());
58
        } catch (\Throwable $exception) {
59
            echo 'File', PHP_EOL, $this->getPrintableFile($body), PHP_EOL;
60
            throw $exception;
61
        }
62
63
        $this->assertInstanceOf(ResponseInterface::class, $resp);
64
    }
65
66
    private function initDangerMessage()
67
    {
68
        $body = <<<'BODY'
69
<?php
70
71
namespace SlayerBirden\DataFlowServer\Notification;
72
class DangerMessage {}
73
BODY;
74
        CodeLoader::loadCode($body, 'danger.php');
75
    }
76
}
77