1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Create; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\Reader; |
6
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Create\BuildCreateFormStep; |
7
|
|
|
use Kami\ApiCoreBundle\Security\AccessManager; |
8
|
|
|
use Kami\ApiCoreBundle\Tests\Entity\MyModel; |
9
|
|
|
use Kami\Component\RequestProcessor\Artifact; |
10
|
|
|
use Kami\Component\RequestProcessor\ArtifactCollection; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
13
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
14
|
|
|
use Symfony\Component\Form\FormInterface; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
|
17
|
|
|
class BuildCreateFormStepTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
public function testCanBeConstructed() |
21
|
|
|
{ |
22
|
|
|
$formFactoryMock = $this->createMock(FormFactoryInterface::class); |
23
|
|
|
$accessManager = $this->createMock(AccessManager::class); |
24
|
|
|
$readerMock = $this->createMock(Reader::class); |
25
|
|
|
|
26
|
|
|
$step = new BuildCreateFormStep($formFactoryMock, $accessManager, $readerMock); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf(BuildCreateFormStep::class, $step); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testGetRequiredArtifacts() |
32
|
|
|
{ |
33
|
|
|
$formFactoryMock = $this->createMock(FormFactoryInterface::class); |
34
|
|
|
$accessManager = $this->createMock(AccessManager::class); |
35
|
|
|
$readerMock = $this->createMock(Reader::class); |
36
|
|
|
|
37
|
|
|
$step = new BuildCreateFormStep($formFactoryMock, $accessManager, $readerMock); |
38
|
|
|
$this->assertEquals(['reflection', 'access_granted', 'entity'], $step->getRequiredArtifacts()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testExecute() |
42
|
|
|
{ |
43
|
|
|
$formMock = $this->createMock(FormInterface::class); |
44
|
|
|
|
45
|
|
|
$formBuilderInterfaceMock = $this->createMock(FormBuilderInterface::class); |
46
|
|
|
$formBuilderInterfaceMock->expects($this->any())->method('add')->willReturn($formBuilderInterfaceMock); |
47
|
|
|
$formBuilderInterfaceMock->expects($this->any())->method('getForm')->willReturn($formMock); |
48
|
|
|
|
49
|
|
|
$formFactoryMock = $this->createMock(FormFactoryInterface::class); |
50
|
|
|
$formFactoryMock->expects($this->any())->method('createNamedBuilder')->willReturn($formBuilderInterfaceMock); |
51
|
|
|
|
52
|
|
|
$accessManager = $this->createMock(AccessManager::class); |
53
|
|
|
$accessManager->expects($this->any())->method('canCreateProperty')->willReturn(true); |
54
|
|
|
|
55
|
|
|
$readerMock = $this->createMock(Reader::class); |
56
|
|
|
$readerMock->expects($this->any())->method('getPropertyAnnotation')->willReturn([]); |
57
|
|
|
|
58
|
|
|
$step = new BuildCreateFormStep($formFactoryMock, $accessManager, $readerMock); |
59
|
|
|
|
60
|
|
|
$step->setArtifacts(new ArtifactCollection([ |
61
|
|
|
new Artifact('reflection', new \ReflectionClass(MyModel::class)), |
62
|
|
|
new Artifact('entity', new MyModel()) |
63
|
|
|
])); |
64
|
|
|
|
65
|
|
|
$response = $step->execute(new Request()); |
66
|
|
|
$this->assertInstanceOf(ArtifactCollection::class, $response); |
67
|
|
|
$this->assertInstanceOf(FormInterface::class, $response->get('form')->getValue()); |
68
|
|
|
} |
69
|
|
|
} |