Pinq\Tests\Integration\Analysis\BasicExpressionAnalysisTest::testTernaryWithNativeTypes PHP Метод

testTernaryWithNativeTypes() публичный Метод

    public function testTernaryWithNativeTypes()
    {
        $asserts = [INativeType::TYPE_INT => [function () {
            true ? 1 : 2;
        }, function () {
            true ? 31 : -2;
        }, function () {
            true ? strlen('') : 2;
        }], INativeType::TYPE_DOUBLE => [function () {
            true ? 1.0 : 2.0;
        }, function () {
            true ? 1.23 : 2.34;
        }], INativeType::TYPE_BOOL => [function () {
            true ? true : false;
        }, function () {
            true ? true : (bool) 0;
        }, function () {
            true ?: (bool) 0;
        }], INativeType::TYPE_ARRAY => [function () {
            true ? [] : [];
        }, function () {
            true ? [] : [2434];
        }, function () {
            true ? [1, 2, []] : [4] + [];
        }], INativeType::TYPE_STRING => [function () {
            true ? '22' : '';
        }, function () {
            true ? 'abc' : '343';
        }, function () {
            true ? (string) 2 : '343';
        }], INativeType::TYPE_NUMERIC => [function () {
            true ? 1 : 2.0;
        }], INativeType::TYPE_MIXED => [function () {
            true ? strlen('') : 'abc';
        }, function () {
            true ? [] : 123;
        }, function () {
            true ? [] : new \stdClass();
        }, function () {
            true ? 2434 : new \stdClass();
        }, function () {
            true ? new \DateTime() : new \stdClass();
        }, function () {
            'abc' ?: new \stdClass();
        }]];
        foreach ($asserts as $expectedType => $expressions) {
            foreach ($expressions as $expression) {
                $this->assertReturnsNativeType($expression, $expectedType);
            }
        }
        $this->assertReturnsNativeType($expression, $expectedType);
    }