Skip to content

Commit 2d3c230

Browse files
janedbalondrejmirtes
authored andcommitted
QueryResultTypeWalkerTest: make dataset cases clickable in PHPStorm
1 parent 6051e97 commit 2d3c230

File tree

1 file changed

+119
-129
lines changed

1 file changed

+119
-129
lines changed

tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php

Lines changed: 119 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ public function test(Type $expectedType, string $dql, ?string $expectedException
254254
*/
255255
public function getTestData(): iterable
256256
{
257-
$ormVersion = InstalledVersions::getVersion('doctrine/orm');
258-
$hasOrm3 = $ormVersion !== null && strpos($ormVersion, '3.') === 0;
259-
260257
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');
261258
$hasDbal4 = $dbalVersion !== null && strpos($dbalVersion, '4.') === 0;
262259

@@ -537,48 +534,6 @@ public function getTestData(): iterable
537534
',
538535
];
539536

540-
if (property_exists(Column::class, 'enumType') && PHP_VERSION_ID >= 80100) {
541-
assert(class_exists(StringEnum::class));
542-
assert(class_exists(IntEnum::class));
543-
544-
// https://github.com/doctrine/orm/issues/9622
545-
if (!$this->isDoctrine211()) {
546-
yield 'enum' => [
547-
$this->constantArray([
548-
[new ConstantStringType('stringEnumColumn'), new ObjectType(StringEnum::class)],
549-
[new ConstantStringType('intEnumColumn'), new ObjectType(IntEnum::class)],
550-
]),
551-
'
552-
SELECT e.stringEnumColumn, e.intEnumColumn
553-
FROM QueryResult\EntitiesEnum\EntityWithEnum e
554-
',
555-
];
556-
}
557-
558-
yield 'enum in expression' => [
559-
$this->constantArray([
560-
[
561-
new ConstantIntegerType(1),
562-
new StringType(),
563-
],
564-
[
565-
new ConstantIntegerType(2),
566-
new IntegerType(),
567-
],
568-
[
569-
new ConstantIntegerType(3),
570-
$this->numericString(),
571-
],
572-
]),
573-
'
574-
SELECT COALESCE(e.stringEnumColumn, e.stringEnumColumn),
575-
COALESCE(e.intEnumColumn, e.intEnumColumn),
576-
COALESCE(e.intEnumOnStringColumn, e.intEnumOnStringColumn)
577-
FROM QueryResult\EntitiesEnum\EntityWithEnum e
578-
',
579-
];
580-
}
581-
582537
yield 'hidden' => [
583538
$this->constantArray([
584539
[new ConstantStringType('intColumn'), new IntegerType()],
@@ -1275,40 +1230,6 @@ public function getTestData(): iterable
12751230
',
12761231
];
12771232

1278-
if (!$hasOrm3) {
1279-
yield 'date_add function' => [
1280-
$this->constantArray([
1281-
[new ConstantIntegerType(1), new StringType()],
1282-
[new ConstantIntegerType(2), TypeCombinator::addNull(new StringType())],
1283-
[new ConstantIntegerType(3), TypeCombinator::addNull(new StringType())],
1284-
[new ConstantIntegerType(4), new StringType()],
1285-
]),
1286-
'
1287-
SELECT DATE_ADD(m.datetimeColumn, m.intColumn, \'day\'),
1288-
DATE_ADD(m.stringNullColumn, m.intColumn, \'day\'),
1289-
DATE_ADD(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'),
1290-
DATE_ADD(\'2020-01-01\', 7, \'day\')
1291-
FROM QueryResult\Entities\Many m
1292-
',
1293-
];
1294-
1295-
yield 'date_sub function' => [
1296-
$this->constantArray([
1297-
[new ConstantIntegerType(1), new StringType()],
1298-
[new ConstantIntegerType(2), TypeCombinator::addNull(new StringType())],
1299-
[new ConstantIntegerType(3), TypeCombinator::addNull(new StringType())],
1300-
[new ConstantIntegerType(4), new StringType()],
1301-
]),
1302-
'
1303-
SELECT DATE_SUB(m.datetimeColumn, m.intColumn, \'day\'),
1304-
DATE_SUB(m.stringNullColumn, m.intColumn, \'day\'),
1305-
DATE_SUB(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'),
1306-
DATE_SUB(\'2020-01-01\', 7, \'day\')
1307-
FROM QueryResult\Entities\Many m
1308-
',
1309-
];
1310-
}
1311-
13121233
yield 'date_diff function' => [
13131234
$this->constantArray([
13141235
[new ConstantIntegerType(1), $this->floatOrStringified()],
@@ -1325,26 +1246,6 @@ public function getTestData(): iterable
13251246
',
13261247
];
13271248

1328-
/*yield 'sqrt function' => [
1329-
$this->constantArray([
1330-
[new ConstantIntegerType(1), $this->floatStringified()],
1331-
[new ConstantIntegerType(2), TypeCombinator::addNull($this->floatStringified())],
1332-
[new ConstantIntegerType(3), $this->floatStringified()],
1333-
]),
1334-
'
1335-
SELECT SQRT(m.intColumn),
1336-
SQRT(NULLIF(m.intColumn, 1)),
1337-
SQRT(1)
1338-
FROM QueryResult\Entities\Many m
1339-
',
1340-
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '<3') && PHP_VERSION_ID >= 80100
1341-
? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated'
1342-
: null,
1343-
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3') && PHP_VERSION_ID >= 80100
1344-
? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated'
1345-
: null,
1346-
];*/
1347-
13481249
yield 'length function' => [
13491250
$this->constantArray([
13501251
[
@@ -1368,36 +1269,6 @@ public function getTestData(): iterable
13681269
',
13691270
];
13701271

1371-
if (PHP_VERSION_ID >= 70400) {
1372-
yield 'locate function' => [
1373-
$this->constantArray([
1374-
[new ConstantIntegerType(1), $this->uintOrStringified()],
1375-
[new ConstantIntegerType(2), TypeCombinator::addNull($this->uintOrStringified())],
1376-
[new ConstantIntegerType(3), TypeCombinator::addNull($this->uintOrStringified())],
1377-
[new ConstantIntegerType(4), $this->uintOrStringified()],
1378-
]),
1379-
'
1380-
SELECT LOCATE(m.stringColumn, m.stringColumn, 0),
1381-
LOCATE(m.stringNullColumn, m.stringColumn, 0),
1382-
LOCATE(m.stringColumn, m.stringNullColumn, 0),
1383-
LOCATE(\'f\', \'foo\', 0)
1384-
FROM QueryResult\Entities\Many m
1385-
',
1386-
null,
1387-
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3.4')
1388-
? null
1389-
: (
1390-
PHP_VERSION_ID >= 80100
1391-
? 'strpos(): Passing null to parameter #2 ($needle) of type string is deprecated'
1392-
: (
1393-
PHP_VERSION_ID < 80000
1394-
? 'strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior'
1395-
: null
1396-
)
1397-
),
1398-
];
1399-
}
1400-
14011272
yield 'lower function' => [
14021273
$this->constantArray([
14031274
[new ConstantIntegerType(1), new StringType()],
@@ -1609,6 +1480,125 @@ public function getTestData(): iterable
16091480
FROM QueryResult\Entities\One o
16101481
',
16111482
];
1483+
1484+
yield from $this->yieldConditionalDataset();
1485+
}
1486+
1487+
/**
1488+
* @return iterable<mixed>
1489+
*/
1490+
private function yieldConditionalDataset(): iterable
1491+
{
1492+
if (property_exists(Column::class, 'enumType') && PHP_VERSION_ID >= 80100) {
1493+
assert(class_exists(StringEnum::class));
1494+
assert(class_exists(IntEnum::class));
1495+
1496+
// https://github.com/doctrine/orm/issues/9622
1497+
if (!$this->isDoctrine211()) {
1498+
yield 'enum' => [
1499+
$this->constantArray([
1500+
[new ConstantStringType('stringEnumColumn'), new ObjectType(StringEnum::class)],
1501+
[new ConstantStringType('intEnumColumn'), new ObjectType(IntEnum::class)],
1502+
]),
1503+
'
1504+
SELECT e.stringEnumColumn, e.intEnumColumn
1505+
FROM QueryResult\EntitiesEnum\EntityWithEnum e
1506+
',
1507+
];
1508+
}
1509+
1510+
yield 'enum in expression' => [
1511+
$this->constantArray([
1512+
[
1513+
new ConstantIntegerType(1),
1514+
new StringType(),
1515+
],
1516+
[
1517+
new ConstantIntegerType(2),
1518+
new IntegerType(),
1519+
],
1520+
[
1521+
new ConstantIntegerType(3),
1522+
$this->numericString(),
1523+
],
1524+
]),
1525+
'
1526+
SELECT COALESCE(e.stringEnumColumn, e.stringEnumColumn),
1527+
COALESCE(e.intEnumColumn, e.intEnumColumn),
1528+
COALESCE(e.intEnumOnStringColumn, e.intEnumOnStringColumn)
1529+
FROM QueryResult\EntitiesEnum\EntityWithEnum e
1530+
',
1531+
];
1532+
}
1533+
1534+
if (PHP_VERSION_ID >= 70400) {
1535+
yield 'locate function' => [
1536+
$this->constantArray([
1537+
[new ConstantIntegerType(1), $this->uintOrStringified()],
1538+
[new ConstantIntegerType(2), TypeCombinator::addNull($this->uintOrStringified())],
1539+
[new ConstantIntegerType(3), TypeCombinator::addNull($this->uintOrStringified())],
1540+
[new ConstantIntegerType(4), $this->uintOrStringified()],
1541+
]),
1542+
'
1543+
SELECT LOCATE(m.stringColumn, m.stringColumn, 0),
1544+
LOCATE(m.stringNullColumn, m.stringColumn, 0),
1545+
LOCATE(m.stringColumn, m.stringNullColumn, 0),
1546+
LOCATE(\'f\', \'foo\', 0)
1547+
FROM QueryResult\Entities\Many m
1548+
',
1549+
null,
1550+
InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '>=3.4')
1551+
? null
1552+
: (
1553+
PHP_VERSION_ID >= 80100
1554+
? 'strpos(): Passing null to parameter #2 ($needle) of type string is deprecated'
1555+
: (
1556+
PHP_VERSION_ID < 80000
1557+
? 'strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior'
1558+
: null
1559+
)
1560+
),
1561+
];
1562+
}
1563+
1564+
$ormVersion = InstalledVersions::getVersion('doctrine/orm');
1565+
$hasOrm3 = $ormVersion !== null && strpos($ormVersion, '3.') === 0;
1566+
1567+
if ($hasOrm3) {
1568+
return;
1569+
}
1570+
1571+
yield 'date_add function' => [
1572+
$this->constantArray([
1573+
[new ConstantIntegerType(1), new StringType()],
1574+
[new ConstantIntegerType(2), TypeCombinator::addNull(new StringType())],
1575+
[new ConstantIntegerType(3), TypeCombinator::addNull(new StringType())],
1576+
[new ConstantIntegerType(4), new StringType()],
1577+
]),
1578+
'
1579+
SELECT DATE_ADD(m.datetimeColumn, m.intColumn, \'day\'),
1580+
DATE_ADD(m.stringNullColumn, m.intColumn, \'day\'),
1581+
DATE_ADD(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'),
1582+
DATE_ADD(\'2020-01-01\', 7, \'day\')
1583+
FROM QueryResult\Entities\Many m
1584+
',
1585+
];
1586+
1587+
yield 'date_sub function' => [
1588+
$this->constantArray([
1589+
[new ConstantIntegerType(1), new StringType()],
1590+
[new ConstantIntegerType(2), TypeCombinator::addNull(new StringType())],
1591+
[new ConstantIntegerType(3), TypeCombinator::addNull(new StringType())],
1592+
[new ConstantIntegerType(4), new StringType()],
1593+
]),
1594+
'
1595+
SELECT DATE_SUB(m.datetimeColumn, m.intColumn, \'day\'),
1596+
DATE_SUB(m.stringNullColumn, m.intColumn, \'day\'),
1597+
DATE_SUB(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'),
1598+
DATE_SUB(\'2020-01-01\', 7, \'day\')
1599+
FROM QueryResult\Entities\Many m
1600+
',
1601+
];
16121602
}
16131603

16141604
/**

0 commit comments

Comments
 (0)