public function testBackAndForth()
 {
     foreach ($this->qomQueries as $name => $originalQomQuery) {
         $originalSql2Query = $this->sql2Queries[$name];
         if (is_array($originalSql2Query)) {
             $this->assertGreaterThan(0, count($originalSql2Query), 'empty list of queries');
             $passed = false;
             $sql2 = 'None of the QOM statements matched';
             foreach ($originalSql2Query as $query) {
                 $qom = $this->sql2Parser->parse($query);
                 if ($originalQomQuery->getStatement() == $qom->getStatement()) {
                     $sql2 = $this->qomParser->convert($qom);
                     if ($sql2 == $query) {
                         $passed = true;
                         break;
                     }
                 }
             }
             $this->assertTrue($passed, "QOM-->SQL2->QOM: Query variation {$name} resulted in SQL2 that is not found: {$sql2}");
         } else {
             $qom = $this->sql2Parser->parse($originalSql2Query);
             $this->assertEquals($originalQomQuery, $qom, "QOM-->SQL2: Original query = {$originalSql2Query}");
             $sql2 = $this->qomParser->convert($qom);
             $this->assertEquals($originalSql2Query, $sql2, "SQL2-->QOM: Original query = {$originalSql2Query}");
         }
     }
 }
 /**
  * Assert that a QOM query specified by its source, columns, constraint and orderings
  * will be converted in the expected SQL2 query.
  *
  * @param string              $expectedSql2 The expected SQL2 query
  * @param SourceInterface     $source       The source of the QOM query
  * @param array               $columns      The columns of the QOM query
  * @param ConstraintInterface $constraint   The contraint of the QOM query
  * @param array               $ordering     The orderings of the QOM query
  */
 protected function assertQuery($expectedSql2, $source, $columns = array(), $constraint = null, $ordering = array())
 {
     // TODO: test this without relying on jackalope implementation
     $factory = $this->getMockBuilder('Jackalope\\FactoryInterface')->disableOriginalConstructor()->getMock();
     $om = $this->getMockBuilder('Jackalope\\ObjectManager')->disableOriginalConstructor()->getMock();
     $query = new QOM\QueryObjectModel($factory, $om, $source, $constraint, $ordering, $columns);
     $result = $this->parser->convert($query);
     if (is_array($expectedSql2)) {
         $this->assertTrue(in_array($result, $expectedSql2), "The statement '{$result}' does not match an expected variation");
     } else {
         $this->assertEquals($expectedSql2, $result);
     }
 }
Example #3
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getStatement()
 {
     $converter = new QomToSql2QueryConverter(new Sql2Generator());
     return $converter->convert($this);
 }
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getStatement()
 {
     $valueConverter = $this->factory->get('PHPCR\\Util\\ValueConverter');
     $converter = new QomToSql2QueryConverter(new Sql2Generator($valueConverter));
     return $converter->convert($this);
 }