AclWalkerTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 9
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testWalker() 0 37 1
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\Helper\Security\Acl;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
use Doctrine\ORM\AbstractQuery;
8
use Doctrine\ORM\Configuration;
9
use Doctrine\ORM\EntityManager;
10
use Doctrine\ORM\Mapping\ClassMetadata;
11
use Doctrine\ORM\Mapping\QuoteStrategy;
12
use Doctrine\ORM\Query\AST\FromClause;
13
use Doctrine\ORM\Query\AST\IdentificationVariableDeclaration;
14
use Doctrine\ORM\Query\AST\IndexBy;
15
use Doctrine\ORM\Query\AST\PathExpression;
16
use Doctrine\ORM\Query\AST\RangeVariableDeclaration;
17
use Doctrine\ORM\Query\ParserResult;
18
use Doctrine\ORM\Query\ResultSetMapping;
19
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclWalker;
20
use PHPUnit\Framework\TestCase;
21
22
class AclWalkerTest extends TestCase
23
{
24
    public function testWalker()
25
    {
26
        $range = new RangeVariableDeclaration('someschema', 's');
27
        $expr = new PathExpression('int', 'id');
28
        $indexBy = new IndexBy($expr);
29
        $from = new FromClause([new IdentificationVariableDeclaration($range, $indexBy, [])]);
30
31
        $meta = $this->createMock(ClassMetadata::class);
32
        $strategy = $this->createMock(QuoteStrategy::class);
33
        $config = $this->createMock(Configuration::class);
34
35
        $platform = $this->createMock(AbstractPlatform::class);
36
        $platform->expects($this->once())->method('appendLockHint')->willReturn($from);
37
38
        $conn = $this->createMock(Connection::class);
39
        $conn->expects($this->once())->method('getDatabasePlatform')->willReturn($platform);
40
41
        $em = $this->createMock(EntityManager::class);
42
        $query = $this->createMock(AbstractQuery::class);
43
        $mapping = $this->createMock(ResultSetMapping::class);
44
        $result = $this->createMock(ParserResult::class);
45
46
        $meta->expects($this->once())->method('getTableName')->willReturn('sometable');
47
        $strategy->expects($this->once())->method('getTableName')->willReturn('sometable');
48
        $config->expects($this->once())->method('getQuoteStrategy')->willReturn($strategy);
49
50
        $query->expects($this->once())->method('getEntityManager')->willReturn($em);
51
        $query->expects($this->exactly(4))->method('getHint')->will($this->onConsecutiveCalls('sometable', 'sometable', 's', null));
52
        $em->expects($this->once())->method('getConnection')->willReturn($conn);
53
        $em->expects($this->once())->method('getConfiguration')->willReturn($config);
54
        $em->expects($this->once())->method('getClassMetaData')->willReturn($meta);
55
        $result->expects($this->once())->method('getResultSetMapping')->willReturn($mapping);
56
57
        $aclWalker = new AclWalker($query, $result, []);
0 ignored issues
show
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\AbstractQuery>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$result is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\Query\ParserResult>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
        $sql = $aclWalker->walkFromClause($from);
59
        $this->assertRegExp('/(JOIN \(\) ta_ ON s0_\.id = ta_.id)$/', $sql);
60
    }
61
}
62