1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Added coverage to DDC-1521. Small CS changes.

This commit is contained in:
Guilherme Blanco 2011-12-20 00:05:14 -05:00
parent 6c4aaab2d6
commit f6eb83705a
4 changed files with 80 additions and 5 deletions

View File

@ -61,7 +61,6 @@ class SimplifiedYamlDriver extends YamlDriver
$this->_prefixes[$path] = $prefix;
}
public function getNamespacePrefixes()
{
return $this->_prefixes;

View File

@ -0,0 +1,77 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\OrmFunctionalTestCase;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
/**
* @group DDC-1521
*/
class DDC1521Test extends OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('navigation');
parent::setUp();
$config = $this->_em->getConfiguration();
$config->addCustomNumericFunction('TEST', __NAMESPACE__ . '\TestFunction');
}
public function testIssue()
{
$dql = 'SELECT TEST(p.lat, p.long, :lat, :lng) FROM Doctrine\Tests\Models\Navigation\NavPointOfInterest p WHERE p.name = :name';
$params = array('lat' => 1, 'lng' => 2, 'name' => 'My restaurant');
$query = $this->_em->createQuery($dql)->setParameters($params);
$this->assertEquals('SELECT ((12733.129728 + (n0_.nav_lat - ?) + (n0_.nav_long - ?)) * ((n0_.nav_lat - ?) / (12733.129728 * n0_.nav_long - ?))) AS sclr0 FROM navigation_pois n0_ WHERE n0_.name = ?', $query->getSQL());
$result = $query->getScalarResult();
$this->assertEquals(0, count($result));
}
}
class TestFunction extends FunctionNode
{
protected $fromLat;
protected $fromLng;
protected $toLat;
protected $toLng;
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->fromLat = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->fromLng = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->toLat = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->toLng = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
$fromLat = $this->fromLat->dispatch($sqlWalker);
$fromLng = $this->fromLng->dispatch($sqlWalker);
$toLat = $this->toLat->dispatch($sqlWalker);
$toLng = $this->toLng->dispatch($sqlWalker);
$earthDiameterInKM = 1.609344 * 3956 * 2;
return "(($earthDiameterInKM + ($fromLat - $toLat) + ($fromLng - $toLng)) * (($fromLat - $toLat) / ($earthDiameterInKM * $fromLng - $toLng)))";
}
}

View File

@ -2,14 +2,12 @@
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\Qelista\User;
use Doctrine\Tests\Models\Qelista\ShoppingList;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Tests\Models\CMS\CmsComment;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsUser;
require_once __DIR__ . '/../../../TestInit.php';
/**

View File

@ -46,6 +46,7 @@ class DDC1548E1
*/
public $rel;
}
/**
* @Entity
*/