Skip to content

Commit 01f325c

Browse files
committed
Testing also initial query parameters
1 parent 9f7c2f6 commit 01f325c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/NetteDatabaseDataSource.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ class NetteDatabaseDataSource extends FilterableDataSource implements IDataSourc
5050
* @param Context $connection
5151
* @param array $sql
5252
*/
53-
public function __construct(Context $connection, $sql)
53+
public function __construct(Context $connection, $sql, array $params = [])
5454
{
5555
$this->connection = $connection;
5656
$this->sql = $sql;
5757

58-
$this->query_parameters = func_get_args();
59-
array_shift($this->query_parameters);
60-
array_shift($this->query_parameters);
58+
$this->query_parameters = $params;
6159

6260
$this->queryHelper = new QueryHelper($this->sql);
6361
}

tests/Cases/NetteDatabaseDataSource.php renamed to tests/Cases/NetteDatabaseDataSourceTest.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ final class NetteDatabaseDataSourceTest extends TestCase
3030

3131
public function setUp()
3232
{
33-
\Tracy\Debugger::enable();
3433
$connection = new Connection('.', NULL, NULL, ['lazy' => TRUE]);
3534

3635
$structure = new Structure($connection, new DevNullStorage);
@@ -87,9 +86,9 @@ public function testComplexQuery()
8786
ON p2.id = u.father_id
8887
JOIN (SELECT id, age FROM parent) p3
8988
ON p3.age = u.age
90-
WHERE p2.id != 2 OR p2.id NOT IN (3, 4)';
89+
WHERE p2.id != 2 OR p2.id NOT IN (?, ?)';
9190

92-
$s = new NetteDatabaseDataSource($this->db, $q);
91+
$s = new NetteDatabaseDataSource($this->db, $q, [3, 4]);
9392

9493
$filter1 = new FilterSelect('status', 'Status', [1 => 'Online', 0 => 'Offline'], 'user.status');
9594
$filter1->setValue(1);
@@ -100,7 +99,7 @@ public function testComplexQuery()
10099
$filter3 = new FilterRange('range', 'Range', 'id', 'To');
101100
$filter3->setValue(['from' => 2, 'to' => NULL]);
102101

103-
$filter4 = new FilterDateRange('date range', 'Date Range', 'created');
102+
$filter4 = new FilterDateRange('date range', 'Date Range', 'created', '-');
104103
$filter4->setValue(['from' => '1. 2. 2003', 'to' => '3. 12. 2149']);
105104

106105
$filter5 = new FilterDate('date', 'Date', 'date');
@@ -123,7 +122,7 @@ public function testComplexQuery()
123122
ON p2.id = u.father_id
124123
INNER JOIN (SELECT id, age FROM parent) p3
125124
ON p3.age = u.age
126-
WHERE (p2.id != 2 OR p2.id NOT IN (3, 4))
125+
WHERE (p2.id != 2 OR p2.id NOT IN (?, ?))
127126
AND user.status = ?
128127
AND ((name LIKE ?) OR (id LIKE ?))
129128
AND id >= ?
@@ -134,6 +133,8 @@ public function testComplexQuery()
134133
Assert::same(trim(preg_replace('/\s+/', ' ', $expected_query)), $q[0]);
135134

136135
$expected_params = [
136+
3,
137+
4,
137138
1,
138139
"%text%",
139140
"%text%",

0 commit comments

Comments
 (0)