|
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 AddTest 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\\AddUserAction'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testGenerate() |
|
43
|
|
|
{ |
|
44
|
|
|
$generator = new Add($this->provider->reveal()); |
|
45
|
|
|
|
|
46
|
|
|
$body = $generator->generate(); |
|
47
|
|
|
|
|
48
|
|
|
try { |
|
49
|
|
|
CodeLoader::loadCode($body, 'AddUserAction.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
|
|
|
$addAction = 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 = $addAction->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
|
|
|
|