Doctrine\Tests\ODM\PHPCR\Query\Builder\ConverterPhpcrTest::testGetQuery PHP Method

testGetQuery() public method

public testGetQuery ( )
    public function testGetQuery()
    {
        $me = $this;
        // setup the query, depends on the query builder
        // working properly..
        $this->qb->select()->field('alias_1.foobar');
        $this->qb->from('alias_1')->document('Fooar', 'alias_1');
        $this->qb->where()->fieldIsset('alias_1.foobar');
        $this->qb->orderBy()->asc()->name('alias_1');
        // setup the qomf factory to expect the right parameters for createQuery
        $this->qomfFactory->expects($this->once())->method('get')->will($this->returnCallback(function ($class, $args) use($me) {
            list($om, $source, $constraint, $orderings, $columns) = $args;
            $me->assertInstanceOf('PHPCR\\Query\\QOM\\SourceInterface', $source);
            // test that we append the phpcr:class and classparents constraints
            $me->assertInstanceOf('PHPCR\\Query\\QOM\\AndInterface', $constraint);
            $me->assertInstanceOf('PHPCR\\Query\\QOM\\PropertyExistenceInterface', $constraint->getConstraint1());
            $me->assertInstanceOf('PHPCR\\Query\\QOM\\OrInterface', $constraint->getConstraint2());
            $phpcrClassConstraint = $constraint->getConstraint2()->getConstraint1();
            $me->assertEquals('phpcr:class', $phpcrClassConstraint->getOperand1()->getPropertyName());
            $me->assertEquals('Fooar', $phpcrClassConstraint->getOperand2()->getLiteralValue());
            $phpcrClassParentsConstraint = $constraint->getConstraint2()->getConstraint2();
            $me->assertEquals('phpcr:classparents', $phpcrClassParentsConstraint->getOperand1()->getPropertyName());
            $me->assertEquals('Fooar', $phpcrClassParentsConstraint->getOperand2()->getLiteralValue());
            // test columns
            $me->assertCount(1, $columns);
            $column = $columns[0];
            $me->assertInstanceOf('PHPCR\\Query\\QOM\\ColumnInterface', $column);
            // test orderings
            $me->assertCount(1, $orderings);
            $ordering = $orderings[0];
            $me->assertInstanceOf('PHPCR\\Query\\QOM\\OrderingInterface', $ordering);
            // return something ..
            $qom = $me->getMockBuilder('PHPCR\\Query\\QOM\\QueryObjectModelInterface')->getMock();
            return $qom;
        }));
        $phpcrQuery = $this->converter->getQuery($this->qb);
        $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Query\\Query', $phpcrQuery);
    }