コード例 #1
0
 /**
  * @dataProvider inverseProvider
  */
 public function testBuildComparisonExprWithUnidirectionalJoin($inverse)
 {
     $qb = $this->em->createQueryBuilder()->select('o.id, p1.id')->from('Stub:TestOrder', 'o')->leftJoin('o.products', 'p')->leftJoin('Stub:TestComment', 'c', 'WITH', 'c.products = p AND p.id = 5')->leftJoin('c.products', 'p1');
     $ds = $this->getFilterDatasourceAdapter($qb);
     $expr = $this->builder->buildComparisonExpr($ds, 'p1.orders', 'param1', 'test', $inverse);
     $qb->where($expr);
     $result = $qb->getDQL();
     $operator = $inverse ? 'NOT IN' : 'IN';
     $this->assertEquals('SELECT o.id, p1.id FROM Stub:TestOrder o' . ' LEFT JOIN o.products p' . ' LEFT JOIN Stub:TestComment c WITH c.products = p AND p.id = 5' . ' LEFT JOIN c.products p1' . ' WHERE p1 ' . $operator . '(' . 'SELECT filter_test' . ' FROM ' . self::NS . 'TestProduct filter_test' . ' INNER JOIN filter_test.orders filter_test_rel' . ' WHERE filter_test_rel IN(:param1))', $result);
 }
コード例 #2
0
ファイル: DictionaryTest.php プロジェクト: snorchel/platform
 public function testApplyNot()
 {
     $qb = $this->em->createQueryBuilder()->select('o.id')->from('Stub:TestEntity', 'o');
     $values = [new TestEnumValue('val1', 'Value1'), new TestEnumValue('val2', 'Value2')];
     $data = ['type' => ChoiceFilterType::TYPE_NOT_CONTAINS, 'value' => $values];
     $params = ['null_value' => ':empty:', FilterUtility::DATA_NAME_KEY => 'o.values'];
     $this->filter->init('test', $params);
     /** @var OrmFilterDatasourceAdapter|\PHPUnit_Framework_MockObject_MockObject $ds */
     $ds = $this->getMock('Oro\\Bundle\\FilterBundle\\Datasource\\Orm\\OrmFilterDatasourceAdapter', ['generateParameterName'], [$qb]);
     $ds->expects($this->any())->method('generateParameterName')->will($this->returnValue('param1'));
     $this->filter->apply($ds, $data);
     $result = $qb->getQuery()->getDQL();
     $this->assertEquals('SELECT o.id FROM Stub:TestEntity o WHERE test NOT IN(:param1)', $result);
     $this->assertEquals($values, $qb->getParameter('param1')->getValue());
 }
コード例 #3
0
 public function testIteratorInReverseDirection()
 {
     $records = [['a0' => '1'], ['a0' => '2'], ['a0' => '3']];
     $actualSqls = [];
     $statementCounter = 0;
     $statements = [$this->createFetchStatementMock([['sclr0' => count($records)]]), $this->createFetchStatementMock([$records[0], $records[1]]), $this->createFetchStatementMock([$records[2]])];
     $this->getDriverConnectionMock($this->em)->expects($this->any())->method('query')->will($this->returnCallback(function ($sql) use(&$statements, &$statementCounter, &$actualSqls) {
         $actualSqls[$statementCounter] = $sql;
         $statement = $statements[$statementCounter];
         $statementCounter++;
         return $statement;
     }));
     $source = $this->em->createQueryBuilder()->select('o')->from('Stub:Entity', 'o');
     $iterator = new BufferedQueryResultIterator($source);
     $iterator->setReverse(true);
     $iterator->setBufferSize(2);
     $this->assertEquals(count($records), $iterator->count());
     $count = 0;
     foreach ($iterator as $record) {
         $this->assertInstanceOf('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\ORM\\Query\\Stub\\Entity', $record);
         $this->assertEquals($records[$count]['a0'], $record->a);
         $count++;
     }
     $this->assertEquals(count($records), $count);
     $this->assertCount(3, $actualSqls);
     $this->assertEquals('SELECT count(e0_.a) AS sclr0 FROM Entity e0_', $actualSqls[0]);
     $this->assertEquals('SELECT e0_.a AS a0, e0_.b AS b1 FROM Entity e0_ LIMIT 2 OFFSET 2', $actualSqls[1]);
     $this->assertEquals('SELECT e0_.a AS a0, e0_.b AS b1 FROM Entity e0_ LIMIT 2 OFFSET 0', $actualSqls[2]);
 }
コード例 #4
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The "Entity\NotRoot" must be the root entity.
  */
 public function testAddFilterByTargetEntityWithInvalidActivityEntityClassSpecified()
 {
     $targetEntityClass = 'Oro\\Bundle\\ActivityBundle\\Tests\\Unit\\Fixtures\\Entity\\Target';
     $targetEntityId = 123;
     $qb = $this->em->createQueryBuilder()->select('activity, another')->from('Test:Activity', 'activity')->from('Test:Another', 'another')->where('another.id = activity.id');
     $this->manager->addFilterByTargetEntity($qb, $targetEntityClass, $targetEntityId, 'Entity\\NotRoot');
 }
コード例 #5
0
 public function testIteratorWithArrayHydrationMode()
 {
     $records = [['a0' => '1'], ['a0' => '2'], ['a0' => '3']];
     $actualSqls = [];
     $statementCounter = 0;
     $statements = [$this->createFetchStatementMock([['sclr0' => count($records)]]), $this->createFetchStatementMock([$records[0], $records[1], $records[2]])];
     $this->getDriverConnectionMock($this->em)->expects($this->any())->method('query')->will($this->returnCallback(function ($sql) use(&$statements, &$statementCounter, &$actualSqls) {
         $actualSqls[$statementCounter] = $sql;
         $statement = $statements[$statementCounter];
         $statementCounter++;
         return $statement;
     }));
     $source = $this->em->createQueryBuilder()->select('o')->from('Stub:Entity', 'o');
     $iterator = new BufferedQueryResultIterator($source);
     $iterator->setHydrationMode(Query::HYDRATE_ARRAY);
     $this->assertEquals(count($records), $iterator->count());
     $count = 0;
     foreach ($iterator as $record) {
         $this->assertEquals($records[$count]['a0'], $record['a']);
         $count++;
     }
     $this->assertEquals(count($records), $count);
     $this->assertEquals('SELECT count(e0_.a) AS sclr0 FROM Entity e0_', $actualSqls[0]);
     $this->assertEquals('SELECT e0_.a AS a0, e0_.b AS b1 FROM Entity e0_ LIMIT ' . BufferedQueryResultIterator::DEFAULT_BUFFER_SIZE . ' OFFSET 0', $actualSqls[1]);
 }
コード例 #6
0
 public function testApplyNullNot()
 {
     $qb = $this->em->createQueryBuilder()->select('o.id')->from('Stub:TestEntity', 'o');
     $data = ['type' => ChoiceFilterType::TYPE_NOT_CONTAINS, 'value' => [':empty:']];
     $params = ['null_value' => ':empty:', FilterUtility::DATA_NAME_KEY => 'o.values'];
     $this->filter->init('test', $params);
     $this->filter->apply(new OrmFilterDatasourceAdapter($qb), $data);
     $result = $qb->getQuery()->getDQL();
     $this->assertEquals('SELECT o.id FROM Stub:TestEntity o' . ' WHERE o IN(' . 'SELECT null_filter_test' . ' FROM Stub:TestEntity null_filter_test' . ' LEFT JOIN null_filter_test.values null_filter_test_rel' . ' WHERE null_filter_test_rel IS NOT NULL)', $result);
 }
コード例 #7
0
 /**
  * @dataProvider pageCallbackDataProvider
  */
 public function testPageCallback(array $statements, $bufferSize, $expectedPages)
 {
     $statementCounter = 0;
     $this->getDriverConnectionMock($this->em)->expects($this->any())->method('query')->will($this->returnCallback(function ($sql) use(&$statements, &$statementCounter, &$actualSqls) {
         $actualSqls[$statementCounter] = $sql;
         $statement = $statements[$statementCounter];
         $statementCounter++;
         return $statement;
     }));
     $source = $this->em->createQueryBuilder()->select('o')->from('Stub:Entity', 'o');
     $iterator = (new BufferedQueryResultIterator($source))->setBufferSize($bufferSize);
     $pages = 0;
     $iterator->setPageCallback(function () use(&$pages) {
         $pages++;
     });
     $this->assertEquals(0, $pages);
     iterator_to_array($iterator);
     $this->assertEquals($expectedPages, $pages);
 }