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

UpdateTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
B testGenerate() 0 33 2
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
use Zend\Hydrator\HydratorInterface;
18
use Zend\InputFilter\InputFilterInterface;
19
20
class UpdateTest extends TestCase
21
{
22
    use PrintFileTrait;
23
    /**
24
     * @var ObjectProphecy
25
     */
26
    private $provider;
27
28
    protected function setUp()
29
    {
30
        $this->provider = $this->prophesize(DataProviderInterface::class);
31
        $this->provider->provide()->willReturn([
32
            'ns' => 'Dummy\\Controller',
33
            'entityName' => 'User',
34
            'hasUnique' => false,
35
            'uniqueIdxMessage' => 'Test Constraint violation',
36
            'useStatement' => 'Dummy\\Entities\\User',
37
            'dataRelationship' => '// testing here',
38
        ]);
39
        $this->provider->getClassName(Argument::type('string'))->willReturn('Dummy\\Controller\\UpdateUserAction');
40
    }
41
42
    public function testGenerate()
43
    {
44
        $generator = new Update($this->provider->reveal());
45
46
        $body = $generator->generate();
47
48
        try {
49
            CodeLoader::loadCode($body, 'UpdateUserAction.php');
50
            $className = $generator->getClassName();
51
52
            $inputFilter = $this->prophesize(InputFilterInterface::class);
53
            $inputFilter->setData(Argument::any())->shouldBeCalled();
54
            $inputFilter->isValid()->willReturn(false);
55
            $inputFilter->getInvalidInput()->willReturn([]);
56
57
            $action = new $className(
58
                $this->prophesize(EntityManagerInterface::class)->reveal(),
59
                $this->prophesize(HydratorInterface::class)->reveal(),
60
                $inputFilter->reveal(),
61
                $this->prophesize(LoggerInterface::class)->reveal(),
62
                $this->prophesize(ExtractionInterface::class)->reveal()
63
            );
64
65
            $request = new ServerRequest();
66
            $delegator = $this->prophesize(NotFoundHandler::class);
67
68
            $resp = $action->process($request, $delegator->reveal());
69
        } catch (\Throwable $exception) {
70
            echo 'File', PHP_EOL, $this->getPrintableFile($body), PHP_EOL;
71
            throw $exception;
72
        }
73
74
        $this->assertInstanceOf(ResponseInterface::class, $resp);
75
    }
76
}
77