Test Failed
Pull Request — master (#35)
by Iakov
09:44 queued 06:09
created

HandleRequestStepTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecute() 0 13 1
A testGetRequiredArtifacts() 0 4 1
A testExecuteFailure() 0 12 1
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