Test Failed
Pull Request — master (#34)
by Iakov
06:37
created

HandleRequestStepTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Common;
4
5
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\HandleRequestStep;
6
use Kami\Component\RequestProcessor\Artifact;
7
use Kami\Component\RequestProcessor\ArtifactCollection;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\Form\Form;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
12
13
class HandleRequestStepTest extends TestCase
14
{
15
16
    public function testExecute()
17
    {
18
        $formMock = $this->createMock(Form::class);
19
        $formMock->expects($this->any())->method('isSubmitted')->willReturn(true);
20
        $step = new HandleRequestStep();
21
        $request = new Request();
22
        $step->setArtifacts(new ArtifactCollection([
23
            new Artifact('form', $formMock),
24
            new Artifact('access_granted', true)
25
        ]));
26
        $response = $step->execute($request);
27
        $this->assertInstanceOf(ArtifactCollection::class, $response);
28
        $this->assertTrue($response->get('handled_request')->getValue());
29
    }
30
31
    public function testExecuteFailure()
32
    {
33
        $formMock = $this->createMock(Form::class);
34
        $formMock->expects($this->any())->method('isSubmitted')->willReturn(false);
35
        $step = new HandleRequestStep();
36
        $step->setArtifacts(new ArtifactCollection([
37
            new Artifact('form', $formMock),
38
            new Artifact('access_granted', true)
39
        ]));
40
        $request = new Request();
41
        $this->expectException(BadRequestHttpException::class);
42
        $step->execute($request);
43
    }
44
    
45
    public function testGetRequiredArtifacts()
46
    {
47
        $step = new HandleRequestStep();
48
        $this->assertEquals(['form', 'access_granted'], $step->getRequiredArtifacts());
49
    }
50
}
51