Skip to content

Commit

Permalink
Improved readability in the functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
eisberg committed Nov 22, 2019
1 parent cefd2dd commit 8312053
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\Tests\DbalFunctionalTestCase;
use function array_key_exists;
use function extension_loaded;
use function is_int;

class StatementTest extends DbalFunctionalTestCase
{
Expand Down Expand Up @@ -40,15 +42,29 @@ public function testQueryConversion(string $query, array $params, array $expecte
}

/**
* Low-level approach to working with parameter binding
*
* @param mixed[] $params
* @param mixed[] $expected
*
* @dataProvider queryConversionProvider
*/
public function testQueryPrepare(string $query, array $params, array $expected) : void
public function testStatementBindParameters(string $query, array $params, array $expected) : void
{
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
$stmt = $this->connection->prepare($query);
$hasZeroIndex = array_key_exists(0, $params);

foreach ($params as $key => $val) {
if ($hasZeroIndex && is_int($key)) {
$param = $key + 1;
} else {
$param = $key;
}

$stmt->bindParam($param, $val);
}

$stmt->execute();

self::assertEquals(
$expected,
Expand All @@ -62,7 +78,7 @@ public function testQueryPrepare(string $query, array $params, array $expected)
public static function queryConversionProvider() : iterable
{
return [
'simple' => [
'positional' => [
'SELECT ? COL1 FROM DUAL',
[1],
['COL1' => 1],
Expand Down

0 comments on commit 8312053

Please sign in to comment.