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

ValidateResourceAccessStepTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Kami\ApiCoreBundle\Tests\RequestProcessor\Step\Common;
4
5
use JMS\Serializer\Serializer;
6
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\GetReflectionFromRequestStep;
7
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\PersistStep;
8
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateFormStep;
9
use Kami\ApiCoreBundle\RequestProcessor\Step\Common\ValidateResourceAccessStep;
10
use Kami\ApiCoreBundle\Security\AccessManager;
11
use Kami\ApiCoreBundle\Tests\Entity\MyModel;
12
use Kami\Component\RequestProcessor\Artifact;
13
use Kami\Component\RequestProcessor\ArtifactCollection;
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\HttpFoundation\Request;
16
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...
17
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
18
19
class ValidateResourceAccessStepTest extends TestCase
20
{
21
22
    public function testCanBeConstructed()
23
    {
24
        $accessManagerMock = $this->createMock(AccessManager::class);
25
26
        $step = new ValidateResourceAccessStep($accessManagerMock);
27
        $this->assertInstanceOf(ValidateResourceAccessStep::class, $step);
28
    }
29
30
    public function testExecute()
31
    {
32
        $accessManagerMock = $this->createMock(AccessManager::class);
33
        $accessManagerMock->method('canAccessResource')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $accessManagerMock->/** @scrutinizer ignore-call */ 
34
                            method('canAccessResource')->willReturn(true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        $step = new ValidateResourceAccessStep($accessManagerMock);
35
36
        $step->setArtifacts(new ArtifactCollection([
37
            new Artifact('reflection', new \ReflectionClass(MyModel::class))
38
        ]));
39
40
        $artifacts = $step->execute(new Request());
41
42
        $this->assertInstanceOf(ArtifactCollection::class, $artifacts);
43
        $this->assertTrue(true, $artifacts->get('access_granted')->getValue());
44
    }
45
46
    public function testGetRequiredArtifacts()
47
    {
48
        $accessManagerMock = $this->createMock(AccessManager::class);
49
        $step = new ValidateResourceAccessStep($accessManagerMock);
50
51
        $this->assertEquals(['reflection'], $step->getRequiredArtifacts());
52
    }
53
}
54