Skip to content

Commit

Permalink
connection: restore queryArgs functionality mistakenly removed
Browse files Browse the repository at this point in the history
this fixes wrong refactoring in bef1ea9
  • Loading branch information
hrach committed Nov 1, 2020
1 parent ba8f015 commit cb29fc0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ public function query(...$args): Result
/** @inheritdoc */
public function queryArgs($query, array $args = []): Result
{
array_unshift($args, $query);
if (is_array($query)) {
$args = $query;
} else {
array_unshift($args, $query);
}
return $this->query(...$args);
}

Expand Down
43 changes: 43 additions & 0 deletions tests/cases/unit/ConnectionTest.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types = 1);

/**
* @testCase
*/

namespace NextrasTests\Dbal;

use Nextras\Dbal\Connection;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\ISqlProcessorFactory;
use Nextras\Dbal\SqlProcessor;
use Tester\Assert;
use Tester\Environment;


require_once __DIR__ . '/../../bootstrap.php';


class ConnectionTest extends TestCase
{
public function testQueryArgs()
{
$config = [];
$config['driver'] = $driver = \Mockery::spy(IDriver::class);
$config['sqlProcessorFactory'] = $factory = \Mockery::mock(ISqlProcessorFactory::class);

$sqlProcessor = \Mockery::mock(SqlProcessor::class);
$factory->shouldReceive('create')->with(\Mockery::type(Connection::class))->once()->andReturn($sqlProcessor);
$driver->shouldReceive('isConnected')->once()->andReturn(false);

$connection = new Connection($config);

$sqlProcessor->shouldReceive('process')->once()->with(['SELECT * FROM %table', 'table'])->andReturn('query');
$connection->queryArgs(['SELECT * FROM %table', 'table']);

Environment::$checkAssertions = false;
}
}


$test = new ConnectionTest();
$test->run();

0 comments on commit cb29fc0

Please sign in to comment.