Failed Conditions
Pull Request — master (#6735)
by Matthias
11:21
created

GH6443Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 1
A testIssue() 0 22 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\DBAL\Logging\DebugStack;
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\Tests\DbalTypes\Rot13Type;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
/**
11
 * @group 6443
12
 */
13
class GH6443Test extends OrmFunctionalTestCase
14
{
0 ignored issues
show
introduced by
There must be exactly 0 empty lines after class opening brace.
Loading history...
15
16
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH6443Test::$rot13Type with single line content, use one-line comment instead.
Loading history...
17
     * @var Rot13Type
18
     */
19
    private $rot13Type;
20
21
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH6443Test::$sqlLogger with single line content, use one-line comment instead.
Loading history...
22
     * @var DebugStack
23
     */
24
    private $sqlLogger;
25
26
    /**
27
     * when having an entity, that has a non scalar identifier, the type will not be guessed / converted correctly
28
     */
29
    public function testIssue()
30
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
31
32
        $entity = new GH6443Post();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
        $entity->id = 'Foo';
34
35
        $dql = 'SELECT p FROM ' . GH6443Post::class . ' p WHERE p = ?1';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
        $query = $this->_em->createQuery($dql);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6443Test. Did you maybe forget to declare it?
Loading history...
37
38
        // we do not know that the internal type is a rot13, so we can not add the type parameter here
39
        $query->setParameter(1, $entity);
40
41
        // we do not need the result, but we need to execute it to log the SQL-Statement
42
        $query->getResult();
43
44
        $lastSql = $this->sqlLogger->queries[count($this->sqlLogger->queries)];
0 ignored issues
show
introduced by
Function count() should not be referenced via a fallback global name, but via a use statement.
Loading history...
45
46
        // the entity's identifier is of type "rot13" so the query parameter needs to be this type too
47
        $this->assertSame(
48
            $this->rot13Type->getName(),
49
            $lastSql['types'][0],
50
            "asserting that the entity's identifier type is correctly inferred"
51
        );
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    protected function setUp(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
58
    {
59
        parent::setUp();
60
61
        $this->sqlLogger = new DebugStack();
62
        $this->_em->getConnection()->getConfiguration()->setSQLLogger($this->sqlLogger);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6443Test. Did you maybe forget to declare it?
Loading history...
63
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
64
65
        $this->_schemaTool->createSchema([
0 ignored issues
show
Bug introduced by
The property _schemaTool does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6443Test. Did you mean schemaTool?
Loading history...
66
            $this->_em->getClassMetadata(GH6443Post::class),
67
        ]);
68
69
        $this->rot13Type = Type::getType('rot13');
70
    }
71
72
}
0 ignored issues
show
introduced by
There must be exactly 0 empty lines before class closing brace.
Loading history...
73
74
/** @Entity */
75
class GH6443Post
76
{
77
    /** @Id @Column(type="rot13") */
78
    public $id;
79
}
80