1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Create; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\Reader; |
6
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\ProcessorResponse; |
|
|
|
|
7
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetEntityFromReflectionStep; |
8
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetReflectionFromRequestStep; |
9
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateResourceAccessStep; |
10
|
|
|
use Kami\ApiCoreBundle\RequestProcessor\Step\Create\BuildCreateFormStep; |
11
|
|
|
use Kami\ApiCoreBundle\Security\AccessManager; |
12
|
|
|
use Kami\ApiCoreBundle\Tests\Entity\MyModel; |
13
|
|
|
use Kami\Component\RequestProcessor\Artifact; |
14
|
|
|
use Kami\Component\RequestProcessor\ArtifactCollection; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
17
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
18
|
|
|
use Symfony\Component\Form\FormInterface; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
|
21
|
|
|
class BuildCreateFormStepTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
public function testCanBeConstructed() |
25
|
|
|
{ |
26
|
|
|
$formFactoryMock = $this->createMock(FormFactoryInterface::class); |
27
|
|
|
$accessManager = $this->createMock(AccessManager::class); |
28
|
|
|
$readerMock = $this->createMock(Reader::class); |
29
|
|
|
|
30
|
|
|
$step = new BuildCreateFormStep($formFactoryMock, $accessManager, $readerMock); |
31
|
|
|
|
32
|
|
|
$this->assertInstanceOf(BuildCreateFormStep::class, $step); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testExecute() |
37
|
|
|
{ |
38
|
|
|
$formMock = $this->createMock(FormInterface::class); |
39
|
|
|
$formBuilderInterfaceMock = $this->createMock(FormBuilderInterface::class); |
40
|
|
|
$formBuilderInterfaceMock->expects($this->any())->method('add')->willReturn($formBuilderInterfaceMock); |
41
|
|
|
$formBuilderInterfaceMock->expects($this->any())->method('getForm')->willReturn($formMock); |
42
|
|
|
$formFactoryMock = $this->createMock(FormFactoryInterface::class); |
43
|
|
|
$formFactoryMock->expects($this->any())->method('createNamedBuilder')->willReturn($formBuilderInterfaceMock); |
44
|
|
|
$accessManager = $this->createMock(AccessManager::class); |
45
|
|
|
$readerMock = $this->createMock(Reader::class); |
46
|
|
|
|
47
|
|
|
$step = new BuildCreateFormStep($formFactoryMock, $accessManager, $readerMock); |
48
|
|
|
|
49
|
|
|
$this->assertInstanceOf(BuildCreateFormStep::class, $step); |
50
|
|
|
|
51
|
|
|
$step->setArtifacts(new ArtifactCollection([ |
52
|
|
|
new Artifact('reflection', new \ReflectionClass(MyModel::class)), |
53
|
|
|
new Artifact('entity', new MyModel()) |
54
|
|
|
])); |
55
|
|
|
|
56
|
|
|
$artifacts = $step->execute(new Request()); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf(ArtifactCollection::class, $artifacts); |
59
|
|
|
$this->assertInstanceOf(FormInterface::class, $artifacts->get('form')->getValue()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetRequiredArtifacts() |
63
|
|
|
{ |
64
|
|
|
$formFactoryMock = $this->createMock(FormFactoryInterface::class); |
65
|
|
|
$accessManager = $this->createMock(AccessManager::class); |
66
|
|
|
$readerMock = $this->createMock(Reader::class); |
67
|
|
|
|
68
|
|
|
$step = new BuildCreateFormStep($formFactoryMock, $accessManager, $readerMock); |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->assertEquals(['reflection', 'access_granted', 'entity'], $step->getRequiredArtifacts()); |
72
|
|
|
} |
73
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths