Skip to content

Commit 317e47b

Browse files
arnaud-lbondrejmirtes
authored andcommitted
Fixing handling of boolean literals
Fixes #311
1 parent 66a847d commit 317e47b

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

src/Type/Doctrine/Query/QueryResultTypeWalker.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use function is_string;
4545
use function serialize;
4646
use function sprintf;
47+
use function strtolower;
4748
use function unserialize;
4849

4950
/**
@@ -1095,7 +1096,7 @@ public function walkLiteral($literal)
10951096
break;
10961097

10971098
case AST\Literal::BOOLEAN:
1098-
$value = $literal->value === 'true' ? 1 : 0;
1099+
$value = strtolower($literal->value) === 'true' ? 1 : 0;
10991100
$type = new ConstantIntegerType($value);
11001101
break;
11011102

tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php

+76
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,82 @@ public function getTestData(): array
667667
FROM QueryResult\Entities\Many m
668668
',
669669
],
670+
'Issue 311' => [
671+
$this->constantArray([
672+
[
673+
new ConstantIntegerType(1),
674+
TypeCombinator::union(
675+
new ConstantIntegerType(0),
676+
new ConstantIntegerType(1),
677+
new ConstantStringType('0'),
678+
new ConstantStringType('1')
679+
),
680+
],
681+
]),
682+
'
683+
SELECT CASE
684+
WHEN m.intColumn < 10 THEN true
685+
ELSE false
686+
END
687+
FROM QueryResult\Entities\Many m
688+
',
689+
],
690+
'Issue 311 - 2' => [
691+
$this->constantArray([
692+
[
693+
new ConstantIntegerType(1),
694+
TypeCombinator::union(
695+
new ConstantIntegerType(0),
696+
new ConstantIntegerType(1),
697+
new ConstantStringType('0'),
698+
new ConstantStringType('1')
699+
),
700+
],
701+
]),
702+
'
703+
SELECT CASE
704+
WHEN m.intColumn < 10 THEN TRUE
705+
ELSE FALSE
706+
END
707+
FROM QueryResult\Entities\Many m
708+
',
709+
],
710+
'Issue 311 - 3' => [
711+
$this->constantArray([
712+
[
713+
new ConstantIntegerType(1),
714+
TypeCombinator::union(
715+
new ConstantIntegerType(1),
716+
new ConstantStringType('1')
717+
),
718+
],
719+
[
720+
new ConstantIntegerType(2),
721+
TypeCombinator::union(
722+
new ConstantIntegerType(0),
723+
new ConstantStringType('0')
724+
),
725+
],
726+
[
727+
new ConstantIntegerType(3),
728+
TypeCombinator::union(
729+
new ConstantIntegerType(1),
730+
new ConstantStringType('1')
731+
),
732+
],
733+
[
734+
new ConstantIntegerType(4),
735+
TypeCombinator::union(
736+
new ConstantIntegerType(0),
737+
new ConstantStringType('0')
738+
),
739+
],
740+
]),
741+
'
742+
SELECT (TRUE), (FALSE), (true), (false)
743+
FROM QueryResult\Entities\Many m
744+
',
745+
],
670746
'new' => [
671747
new ObjectType(ManyId::class),
672748
'

0 commit comments

Comments
 (0)