Commit e5d49898 by Scott

Update expandQueryParameters tests

parent 78b6181b
......@@ -12,36 +12,44 @@ class DbConnectionTest extends PHPUnit_Framework_TestCase
$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());
$this->assertSame('SELECT * FROM table WHERE field = 1', $result);
$result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field = 1', []);
$expected = ['SELECT * FROM table WHERE field = 1', []];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('SELECT * FROM table WHERE field = ?', array(1));
$this->assertSame('SELECT * FROM table WHERE field = ?', $result);
$result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field = ?', [1]);
$expected = ['SELECT * FROM table WHERE field = ?', [1]];
$this->assertSame($expected, $result);
$result = $this->dbConnection->applyArraySub('SELECT * FROM table WHERE field IN (?)', array(array(1)));
$this->assertSame('SELECT * FROM table WHERE field IN (?)', $result);
$result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field IN (?)', [[1]]);
$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)));
$this->assertSame('SELECT * FROM table WHERE field IN (?, ?)', $result);
$result = $this->dbConnection->expandQueryParameters('SELECT * FROM table WHERE field IN (?)', [[1, 2]]);
$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))));
$this->assertSame('INSERT INTO table(field) VALUES (?)', $result);
$result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field) VALUES ?', [[ [1] ]]);
$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))));
$this->assertSame('INSERT INTO table(field) VALUES (?), (?)', $result);
$result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field) VALUES ?', [[ [1], [2] ]]);
$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))));
$this->assertSame('INSERT INTO table(field1, field2) VALUES (?, ?)', $result);
$result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field1, field2) VALUES ?', [[ [1, 2] ]]);
$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))));
$this->assertSame('INSERT INTO table(field1, field2) VALUES (?, ?), (?, ?)', $result);
$result = $this->dbConnection->expandQueryParameters('INSERT INTO table(field1, field2) VALUES ?', [[ [1, 2], [3, 4] ]]);
$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->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