Completed
Pull Request — master (#36)
by Roman
04:41
created

PersistStepTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetRequiredArtifacts() 0 5 1
A testCanBeConstructed() 0 3 1
A testExecute() 0 18 1
1
<?php
2
3
4
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Common;
5
6
7
use Doctrine\Bundle\DoctrineBundle\Registry;
8
use Doctrine\ORM\EntityManager;
9
use Doctrine\ORM\QueryBuilder;
10
use Kami\ApiCoreBundle\RequestProcessor\ProcessorResponse;
0 ignored issues
show
Bug introduced by
The type Kami\ApiCoreBundle\Reque...essor\ProcessorResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\PersistStep;
12
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateFormStep;
13
use Kami\ApiCoreBundle\Tests\Entity\MyModel;
14
use Kami\Component\RequestProcessor\Artifact;
15
use Kami\Component\RequestProcessor\ArtifactCollection;
16
use PHPUnit\Framework\TestCase;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
19
20
class PersistStepTest extends TestCase
21
{
22
    public function testCanBeConstructed()
23
    {
24
        $this->assertInstanceOf(PersistStep::class, new PersistStep($this->createMock(Registry::class)));
25
    }
26
27
    public function testExecute()
28
    {
29
        $entityManagerMock = $this->createMock(EntityManager::class);
30
31
        $registryMock = $this->createMock(Registry::class);
32
        $registryMock->expects($this->at(0))->method('getManager')->willReturn($entityManagerMock);
33
34
        $step = new PersistStep($registryMock);
35
        $step->setArtifacts(new ArtifactCollection([
36
            new Artifact('entity', new MyModel()),
37
            new Artifact('validation', true),
38
            new Artifact('query_builder', new QueryBuilder($this->createMock(EntityManager::class)))
39
        ]));
40
41
        $artifacts = $step->execute(new Request());
42
        $this->assertInstanceOf(ArtifactCollection::class, $artifacts);
43
        $this->assertEquals(200, $artifacts->get('status')->getValue());
44
        $this->assertInstanceOf(MyModel::class, $artifacts->get('response_data')->getValue());
45
    }
46
47
    public function testGetRequiredArtifacts()
48
    {
49
        $step = new PersistStep($this->createMock(Registry::class));
50
51
        $this->assertEquals(['validation', 'entity', 'access_granted'], $step->getRequiredArtifacts());
52
    }
53
}