Failed Conditions
Pull Request — master (#7878)
by
unknown
61:32
created

GH8061Class::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Types\Type;
9
use Doctrine\Tests\OrmTestCase;
10
use function sprintf;
11
12
/**
13
 * @group GH8061
14
 */
15
final class GH8061Test extends OrmTestCase
16
{
17
    public static function setUpBeforeClass() : void
18
    {
19
        Type::addType('GH8061Type', GH8061Type::class);
20
    }
21
22
    public function testConvertToPHPValueSQLForNewObjectExpression() : void
23
    {
24
        $dql           = 'SELECT NEW ' . GH8061Class::class . '(e.field) FROM ' . GH8061Entity::class . ' e';
25
        $entityManager = $this->_getTestEntityManager();
26
        $query         = $entityManager->createQuery($dql);
27
28
        self::assertRegExp('/SELECT DatabaseFunction\(\w+\.field\) AS /', $query->getSQL());
0 ignored issues
show
Bug introduced by
$query->getSQL() of type array is incompatible with the type string expected by parameter $string of PHPUnit\Framework\Assert::assertRegExp(). ( Ignorable by Annotation )

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

28
        self::assertRegExp('/SELECT DatabaseFunction\(\w+\.field\) AS /', /** @scrutinizer ignore-type */ $query->getSQL());
Loading history...
29
    }
30
}
31
32
/**
33
 * @Entity
34
 */
35
final class GH8061Entity
36
{
37
    /** @Id @Column(type="integer") @GeneratedValue */
38
    public $id;
39
40
    /** @Column(type="GH8061Type") */
41
    public $field;
42
}
43
44
final class GH8061Type extends Type
45
{
46
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
47
    {
48
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
49
    }
50
51
    public function getName() : string
52
    {
53
        return 'GH8061';
54
    }
55
56
    public function canRequireSQLConversion() : bool
57
    {
58
        return true;
59
    }
60
61
    public function convertToPHPValueSQL($sqlExpr, $platform) : string
62
    {
63
        return sprintf('DatabaseFunction(%s)', $sqlExpr);
64
    }
65
}
66
67
final class GH8061Class
68
{
69
    /** @var string */
70
    public $field;
71
72
    public function __construct(string $field)
73
    {
74
        $this->field = $field;
75
    }
76
}
77