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

Commit

Permalink
Merge 5119680 into 4c68f2c
Browse files Browse the repository at this point in the history
  • Loading branch information
albertor24 committed Jul 8, 2019
2 parents 4c68f2c + 5119680 commit c893e49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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],
[[]],
];
}
}

0 comments on commit c893e49

Please sign in to comment.