Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Fixes 381 - Allows zero as a parameter for the expression constructor #382

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Sql/Expression.php
Expand Up @@ -56,7 +56,7 @@ public function __construct($expression = '', $parameters = null, array $types =
}
}

if ($parameters) {
if ($parameters !== null) {
$this->setParameters($parameters);
}
}
Expand Down
31 changes: 31 additions & 0 deletions test/unit/Sql/ExpressionTest.php
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Db\Sql;

use PHPUnit\Framework\TestCase;
use Zend\Db\Sql\Exception\InvalidArgumentException;
use Zend\Db\Sql\Expression;

/**
Expand Down Expand Up @@ -179,4 +180,34 @@ public function testNumberOfReplacemensConsidersWhenSameVariableIsUsedManyTimes(
$expression = new Expression('uf.user_id = :user_id OR uf.friend_id = :user_id', ['user_id' => 1]);
$expression->getExpressionData();
}


/**
* @param mixed $falsyParameter
* @dataProvider falsyExpressionParametersProvider
*/
public function testConstructorWithFalsyValidParameters($falsyParameter)
{
$expression = new Expression('?', $falsyParameter);
self::assertSame($falsyParameter, $expression->getParameters());
}

public function testConstructorWithInvalidParameter()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expression parameters must be a scalar or array.');
new Expression('?', (object)[]);
}

public function falsyExpressionParametersProvider()
{
return [
[''],
['0'],
[0],
[0.0],
[false],
[[]],
];
}
}