Test Failed
Pull Request — master (#39)
by Roman
03:36
created

FetchEntityByIdStepTest::testExecuteFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Common;
4
5
use Doctrine\Bundle\DoctrineBundle\Registry;
6
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\FetchEntityByIdStep;
7
use Kami\ApiCoreBundle\Tests\Entity\MyModel;
8
use Kami\ApiCoreBundle\Tests\Repository\TestRepository;
9
use Kami\Component\RequestProcessor\Artifact;
10
use Kami\Component\RequestProcessor\ArtifactCollection;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\HttpFoundation\Request;
13
14
class FetchEntityByIdStepTest extends TestCase
15
{
16
17
    public function testCanBeConstructed()
18
    {
19
        $registry = $this->createMock(Registry::class);
20
21
        $step = new FetchEntityByIdStep($registry);
22
        $this->assertInstanceOf(FetchEntityByIdStep::class, $step);
23
    }
24
25
    public function testGetRequiredArtifacts()
26
    {
27
        $registry = $this->createMock(Registry::class);
28
29
        $step = new FetchEntityByIdStep($registry);
30
        $this->assertEquals(['reflection', 'access_granted'], $step->getRequiredArtifacts());
31
    }
32
33
    public function testExecute()
34
    {
35
        $repositoryMock = $this->createMock(TestRepository::class);
36
        $repositoryMock->expects($this->at(0))->method('find')->willReturn(new MyModel());
37
        $registry = $this->createMock(Registry::class);
38
        $registry->expects($this->any())->method('getRepository')->willReturn($repositoryMock);
39
40
        $step = new FetchEntityByIdStep($registry);
41
42
        $step->setArtifacts(new ArtifactCollection([
43
            new Artifact('reflection', new \ReflectionClass(MyModel::class))
44
        ]));
45
46
        $response = $step->execute(new Request());
47
        $this->assertInstanceOf(ArtifactCollection::class, $response);
48
        $this->assertInstanceOf(MyModel::class, $response->get('entity')->getValue());
49
    }
50
}
51