Completed
Push — master ( 2668e0...a58114 )
by Iakov
03:15
created

FetchEntityByIdStepTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanBeConstructed() 0 6 1
A testGetRequiredArtifacts() 0 6 1
A testExecute() 0 16 1
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