Skip to content

Commit

Permalink
@fix: testProcessExpressionWorksWithNamedParameterPrefix - Numeric pr…
Browse files Browse the repository at this point in the history
…efix give an error.
  • Loading branch information
ZVanoZ committed Sep 28, 2021
1 parent e8e55c2 commit 70a4656
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions test/unit/Sql/AbstractSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Laminas\Db\Sql\Predicate;
use Laminas\Db\Sql\Select;
use LaminasTest\Db\TestAsset\TrustingSql92Platform;
use PHPUnit\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
Expand Down Expand Up @@ -147,11 +148,39 @@ public function testProcessExpressionWorksWithExpressionObjectWithPercentageSign
public function testProcessExpressionWorksWithNamedParameterPrefix()
{
$parameterContainer = new ParameterContainer();
$namedParameterPrefix = uniqid();
$namedParameterPrefix = 'prefix-' . uniqid();
$expression = new Expression('FROM_UNIXTIME(?)', [10000000]);
$this->invokeProcessExpressionMethod($expression, $parameterContainer, $namedParameterPrefix);

self::assertSame($namedParameterPrefix . '1', key($parameterContainer->getNamedArray()));
$expectedValue = $namedParameterPrefix . '1';
$currentValue = key($parameterContainer->getNamedArray());

self::assertSame($expectedValue, $currentValue);
}

/**
* Numeric prefix give an error.
*
* @see: https://discourse.laminas.dev/t/why-qa-check-of-laminas-db-220-is-fail/2521
* @see: https://github.com/laminas/laminas-db/pull/220
*/
public function testProcessExpressionWorksWithNamedParameterPrefixNumericIsFail()
{
$parameterContainer = new ParameterContainer();
$namedParameterPrefix = 61507378202901;
$expression = new Expression('FROM_UNIXTIME(?)', [10000000]);
$this->invokeProcessExpressionMethod($expression, $parameterContainer, $namedParameterPrefix);

$expectedValue = $namedParameterPrefix . '1';
$currentValue = key($parameterContainer->getNamedArray());
try {
self::assertSame($expectedValue, $currentValue);
} catch (Exception $e) {
$expectedValue = 'Failed asserting that 615073782029011 is identical to \'615073782029011\'.';
$currentValue = $e->getMessage();

self::assertSame($expectedValue, $currentValue);
}
}

public function testProcessExpressionWorksWithNamedParameterPrefixContainingWhitespace()
Expand Down

0 comments on commit 70a4656

Please sign in to comment.