Commit e5d49898 by Scott

Update expandQueryParameters tests

parent 78b6181b
...@@ -12,36 +12,44 @@ class DbConnectionTest extends PHPUnit_Framework_TestCase ...@@ -12,36 +12,44 @@ class DbConnectionTest extends PHPUnit_Framework_TestCase
$this->dbConnection = new DbConnection(); $this->dbConnection = new DbConnection();
} }
public function test__applyArraySub_success() public function test__expandQueryParameters_success()
{ {
$result = $this->dbConnection->applyArraySub('SELECT * FROM table WHERE field = 1', array()); $result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field = 1', []);
$this->assertSame('SELECT * FROM table WHERE field = 1', $result); $expected = ['SELECT * FROM table WHERE field = 1', []];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('SELECT * FROM table WHERE field = ?', array(1)); $result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field = ?', [1]);
$this->assertSame('SELECT * FROM table WHERE field = ?', $result); $expected = ['SELECT * FROM table WHERE field = ?', [1]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('SELECT * FROM table WHERE field IN (?)', array(array(1))); $result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field IN (?)', [[1]]);
$this->assertSame('SELECT * FROM table WHERE field IN (?)', $result); $expected = ['SELECT * FROM table WHERE field IN (?)', [1]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('SELECT * FROM table WHERE field IN (?)', array(array(1, 2))); $result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field IN (?)', [[1, 2]]);
$this->assertSame('SELECT * FROM table WHERE field IN (?, ?)', $result); $expected = ['SELECT * FROM table WHERE field IN (?, ?)', [1, 2]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('INSERT INTO table(field) VALUES ?', array(array(array(1)))); $result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field) VALUES ?', [[ [1] ]]);
$this->assertSame('INSERT INTO table(field) VALUES (?)', $result); $expected = ['INSERT INTO table(field) VALUES (?)', [1]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('INSERT INTO table(field) VALUES ?', array(array(array(1), array(2)))); $result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field) VALUES ?', [[ [1], [2] ]]);
$this->assertSame('INSERT INTO table(field) VALUES (?), (?)', $result); $expected = ['INSERT INTO table(field) VALUES (?), (?)', [1, 2]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('INSERT INTO table(field1, field2) VALUES ?', array(array(array(1, 2)))); $result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field1, field2) VALUES ?', [[ [1, 2] ]]);
$this->assertSame('INSERT INTO table(field1, field2) VALUES (?, ?)', $result); $expected = ['INSERT INTO table(field1, field2) VALUES (?, ?)', [1, 2]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('INSERT INTO table(field1, field2) VALUES ?', array(array(array(1, 2), array(3, 4)))); $result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field1, field2) VALUES ?', [[ [1, 2], [3, 4] ]]);
$this->assertSame('INSERT INTO table(field1, field2) VALUES (?, ?), (?, ?)', $result); $expected = ['INSERT INTO table(field1, field2) VALUES (?, ?), (?, ?)', [1, 2, 3, 4]];
$this->assertSame($expected, $result);
} }
public function test__applyArraySub_parameter_groups_with_different_element_count_error() public function test__expandQueryParameters_incorrect_groups_error()
{ {
$this->setExpectedException('Q2A\Database\Exceptions\SelectSpecException'); $this->setExpectedException('Q2A\Database\Exceptions\SelectSpecException');
$this->dbConnection->applyArraySub('INSERT INTO table(field1, field2) VALUES ?', array(array(array(1, 2), array(3)))); $this->dbConnection->expandQueryParameters('INSERT INTO table(field1, field2) VALUES ?', [[ [1, 2], [3] ]]);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment