public function testTernary()
{
$values = [INativeType::TYPE_INT => function () {
3.2 ? 1 : -56;
}, INativeType::TYPE_BOOL => function () {
'abc' ? true : false;
}, INativeType::TYPE_DOUBLE => function () {
3 ? 343.23 : 2.34;
}, INativeType::TYPE_STRING => function () {
false ? 'abce' : '1234.3';
}, INativeType::TYPE_ARRAY => function () {
false ? ['abc'] : [1, 2, 3];
}, INativeType::TYPE_NUMERIC => function () {
'' ? 3 : 4.3;
}, INativeType::TYPE_MIXED => function () {
'' ? '3' : 4.3;
}];
foreach ($values as $expectedType => $expression) {
$this->doAnalysisTest($expression, function (ITypeAnalysis $analysis, O\TernaryExpression $expression) use($expectedType) {
$this->assertTypeMatchesValue($analysis, $expression->getIfFalse());
$this->assertTypeMatchesValue($analysis, $expression->getIfTrue());
$this->assertEqualsNativeType($expectedType, $analysis->getReturnTypeOf($expression));
});
}
}