Added coverage to DDC-1521. Small CS changes.
This commit is contained in:
parent
6c4aaab2d6
commit
f6eb83705a
@ -61,7 +61,6 @@ class SimplifiedYamlDriver extends YamlDriver
|
|||||||
$this->_prefixes[$path] = $prefix;
|
$this->_prefixes[$path] = $prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getNamespacePrefixes()
|
public function getNamespacePrefixes()
|
||||||
{
|
{
|
||||||
return $this->_prefixes;
|
return $this->_prefixes;
|
||||||
|
77
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1521Test.php
Normal file
77
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1521Test.php
Normal 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)))";
|
||||||
|
}
|
||||||
|
}
|
@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
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\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
use Doctrine\Tests\Models\CMS\CmsComment;
|
use Doctrine\Tests\Models\CMS\CmsComment;
|
||||||
use Doctrine\Tests\Models\CMS\CmsArticle;
|
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../TestInit.php';
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +46,7 @@ class DDC1548E1
|
|||||||
*/
|
*/
|
||||||
public $rel;
|
public $rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Entity
|
* @Entity
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user