Details
Description
Hi,
I'm using master branch of Doctrine 2. Including an Expr with a numeric 0 value (not a string):
$value = 0; $qb->expr()->gte($field, $qb->expr()->literal($value));
Expr::literal method will return an empty string ('') instead of '0', which causes that this expression be something like:
entity.myField >=
instead of:
entity.miField >= '0''
This makes the query fail. Tracking the issue down I've found this on Expr\Base::add method:
public function add($arg) { if ( ! empty($arg) || ($arg instanceof self && $arg->count() > 0)) { // If we decide to keep Expr\Base instances, we can use this check if ( ! is_string($arg)) { $class = get_class($arg); if ( ! in_array($class, $this->_allowedClasses)) { throw new \InvalidArgumentException("Expression of type '$class' not allowed in this context."); } } $this->_parts[] = $arg; } }
The problem is that empty function returns true if you pass '0', so a call to Expr\Base::add would end on NOT adding '0' to $this->_parts array. That's why it finally returns ''.
I wanted to make the fix for this but I'm having issues running the phing build task. Which are the steps to follow to run the tests? Running phing build task I get on the "test" task:
Could not create task/type: 'nativephpunit'. Make sure that this class has been declared using taskdef / typedef.
Thanks!
Assigned to guilherme, i suppose we could change the !empty($arg) to $arg !== null ?