Pinq\Tests\Integration\Analysis\BasicExpressionAnalysisTest::testTernaryWithObjectTypes PHP Method

testTernaryWithObjectTypes() public method

    public function testTernaryWithObjectTypes()
    {
        $asserts = ['stdClass' => [function () {
            true ? new \stdClass() : new \stdClass();
        }, function () {
            true ? new \stdClass() : (object) [];
        }, function () {
            true ? (object) [1, 2, 4] : (object) [];
        }], 'Traversable' => [function (\Iterator $a, \IteratorAggregate $b) {
            true ? $a : $b;
        }], 'ArrayObject' => [function (\ArrayObject $a, \ArrayObject $b) {
            true ? $a : $b;
        }]];
        foreach ($asserts as $expectedType => $expressions) {
            foreach ($expressions as $expression) {
                $this->assertReturnsObjectType($expression, $expectedType);
            }
        }
        $this->assertReturnsType(function (\ArrayObject $a, \ArrayIterator $b) {
            0 ? $a : $b;
        }, $this->typeSystem->getCompositeType([$this->typeSystem->getObjectType('Countable'), $this->typeSystem->getObjectType('ArrayAccess'), $this->typeSystem->getObjectType('Traversable'), $this->typeSystem->getObjectType('Serializable')]));
    }