|
14 | 14 | use PHPStan\Testing\PHPStanTestCase;
|
15 | 15 | use PHPStan\Type\Accessory\AccessoryNumericStringType;
|
16 | 16 | use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
|
| 17 | +use PHPStan\Type\Constant\ConstantFloatType; |
17 | 18 | use PHPStan\Type\Constant\ConstantIntegerType;
|
18 | 19 | use PHPStan\Type\Constant\ConstantStringType;
|
19 | 20 | use PHPStan\Type\ConstantTypeHelper;
|
@@ -681,6 +682,84 @@ public function getTestData(): iterable
|
681 | 682 | ',
|
682 | 683 | ];
|
683 | 684 |
|
| 685 | + yield 'aggregate on literal' => [ |
| 686 | + $this->constantArray([ |
| 687 | + [ |
| 688 | + new ConstantIntegerType(1), |
| 689 | + TypeCombinator::union( |
| 690 | + new ConstantStringType('1'), |
| 691 | + new ConstantIntegerType(1), |
| 692 | + new NullType() |
| 693 | + ), |
| 694 | + ], |
| 695 | + [ |
| 696 | + new ConstantIntegerType(2), |
| 697 | + TypeCombinator::union( |
| 698 | + new ConstantStringType('0'), |
| 699 | + new ConstantIntegerType(0), |
| 700 | + new ConstantStringType('1'), |
| 701 | + new ConstantIntegerType(1), |
| 702 | + new NullType() |
| 703 | + ), |
| 704 | + ], |
| 705 | + [ |
| 706 | + new ConstantIntegerType(3), |
| 707 | + TypeCombinator::union( |
| 708 | + new ConstantStringType('1'), |
| 709 | + new ConstantIntegerType(1), |
| 710 | + new NullType() |
| 711 | + ), |
| 712 | + ], |
| 713 | + [ |
| 714 | + new ConstantIntegerType(4), |
| 715 | + TypeCombinator::union( |
| 716 | + new ConstantStringType('0'), |
| 717 | + new ConstantIntegerType(0), |
| 718 | + new ConstantStringType('1'), |
| 719 | + new ConstantIntegerType(1), |
| 720 | + new NullType() |
| 721 | + ), |
| 722 | + ], |
| 723 | + [ |
| 724 | + new ConstantIntegerType(5), |
| 725 | + TypeCombinator::union( |
| 726 | + new ConstantStringType('1'), |
| 727 | + new ConstantIntegerType(1), |
| 728 | + new ConstantStringType('1.0'), |
| 729 | + new ConstantFloatType(1.0), |
| 730 | + new NullType() |
| 731 | + ), |
| 732 | + ], |
| 733 | + [ |
| 734 | + new ConstantIntegerType(6), |
| 735 | + TypeCombinator::union( |
| 736 | + $this->intStringified(), |
| 737 | + new FloatType(), |
| 738 | + new NullType() |
| 739 | + ), |
| 740 | + ], |
| 741 | + [ |
| 742 | + new ConstantIntegerType(7), |
| 743 | + TypeCombinator::addNull($this->intStringified()), |
| 744 | + ], |
| 745 | + [ |
| 746 | + new ConstantIntegerType(8), |
| 747 | + TypeCombinator::addNull($this->intStringified()), |
| 748 | + ], |
| 749 | + ]), |
| 750 | + ' |
| 751 | + SELECT MAX(1), |
| 752 | + MAX(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END), |
| 753 | + MIN(1), |
| 754 | + MIN(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END), |
| 755 | + AVG(1), |
| 756 | + AVG(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END), |
| 757 | + SUM(1), |
| 758 | + SUM(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END) |
| 759 | + FROM QueryResult\Entities\Many m |
| 760 | + ', |
| 761 | + ]; |
| 762 | + |
684 | 763 | yield 'literal' => [
|
685 | 764 | $this->constantArray([
|
686 | 765 | [
|
|
0 commit comments