Completed
Pull Request — master (#9)
by Roman
03:36
created

GetReflectionFromRequestStepTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteFailure() 0 9 1
A testExecute() 0 11 1
A testRequiresBefore() 0 4 1
1
<?php
2
3
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Common;
4
5
use Kami\ApiCoreBundle\RequestProcessor\ProcessorResponse;
6
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetReflectionFromRequestStep;
7
use Kami\ApiCoreBundle\Tests\fixtures\Entity;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
12
class GetReflectionFromRequestStepTest extends TestCase
13
{
14
15
    public function testExecute()
16
    {
17
        $request = new Request();
18
        $request->attributes->set('_entity', Entity::class);
19
        $step = new GetReflectionFromRequestStep();
20
        $step->setRequest($request);
21
        $step->setPreviousResponse(new ProcessorResponse($request, []));
22
23
        $response = $step->execute();
24
        $this->assertInstanceOf(ProcessorResponse::class, $response);
25
        $this->assertInstanceOf(\ReflectionClass::class, $response->getData()['reflection']);
26
    }
27
28
    public function testExecuteFailure()
29
    {
30
        $request = new Request();
31
        $request->attributes->set('_entity', 'Not\Existing\Class');
32
        $step = new GetReflectionFromRequestStep();
33
        $step->setPreviousResponse(new ProcessorResponse($request, []));
34
        $step->setRequest($request);
35
        $this->expectException(NotFoundHttpException::class);
36
        $step->execute();
37
    }
38
39
    public function testRequiresBefore()
40
    {
41
        $step = new GetReflectionFromRequestStep();
42
        $this->assertEquals([], $step->requiresBefore());
43
    }
44
}
45