Skip to content

Commit 41e2a82

Browse files
Tests: Remove deprecated methods and replace their usages
`setupTest()` had an empty function body, so no replacement is necessary.
1 parent 3c314dd commit 41e2a82

8 files changed

Lines changed: 150 additions & 340 deletions

File tree

tests/DeleteTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testFrom()
1919

2020
$this->query->from('table');
2121
$this->assertSame(['table'], $this->query->getFrom());
22-
$this->assertCorrectStatementAndValues('DELETE FROM table', []);
22+
$this->assertSql('DELETE FROM table', $this->query, []);
2323
}
2424

2525
public function testFromWithAlias()
@@ -28,7 +28,7 @@ public function testFromWithAlias()
2828

2929
$this->query->from('table t1');
3030
$this->assertSame(['table t1'], $this->query->getFrom());
31-
$this->assertCorrectStatementAndValues('DELETE FROM table t1', []);
31+
$this->assertSql('DELETE FROM table t1', $this->query, []);
3232
}
3333

3434
public function testFromWithArray()
@@ -37,6 +37,6 @@ public function testFromWithArray()
3737

3838
$this->query->from(['t1' => 'table']);
3939
$this->assertSame(['t1' => 'table'], $this->query->getFrom());
40-
$this->assertCorrectStatementAndValues('DELETE FROM table t1', []);
40+
$this->assertSql('DELETE FROM table t1', $this->query, []);
4141
}
4242
}

tests/HavingTest.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ class HavingTest extends TestCase
99
{
1010
public function testHavingStringFormat()
1111
{
12-
$this->setupTest();
13-
1412
$this->query->having('c1 = x');
1513
$this->query->having('c2 IS NULL');
1614
$this->query->having('c3 IS NOT NULL');
1715

18-
$this->assertCorrectStatementAndValues('HAVING (c1 = x) AND (c2 IS NULL) AND (c3 IS NOT NULL)', []);
16+
$this->assertSql('HAVING (c1 = x) AND (c2 IS NULL) AND (c3 IS NOT NULL)', $this->query, []);
1917
}
2018

2119
public function testHavingArrayFormat()
2220
{
23-
$this->setupTest();
24-
2521
$this->query->having(['c1 = x']);
2622
$this->query->having(['c2 = ?' => 1]);
2723
$this->query->having(['c3 > ?' => 1]);
@@ -30,37 +26,32 @@ public function testHavingArrayFormat()
3026
$this->query->having(['c6 IN (?)' => [1, 2, 3]]);
3127
$this->query->having(['c7 = ?' => 1, 'c8 = ?' => 1]);
3228

33-
$this->assertCorrectStatementAndValues(
29+
$this->assertSql(
3430
'HAVING (c1 = x) AND (c2 = ?) AND (c3 > ?) AND (c4 IS NULL)'
3531
. ' AND (c5 IS NOT NULL) AND (c6 IN (?, ?, ?)) AND ((c7 = ?) AND (c8 = ?))',
32+
$this->query,
3633
[1, 1, 1, 2, 3, 1, 1]
3734
);
3835
}
3936

4037
public function testWhereWithExpression()
4138
{
42-
$this->setupTest();
43-
4439
$expression = new Expression('c2 = ?', null, 1);
4540
$this->query->having($expression);
4641

47-
$this->assertCorrectStatementAndValues('HAVING c2 = ?', [1]);
42+
$this->assertSql('HAVING c2 = ?', $this->query, [1]);
4843
}
4944

5045
public function testWhereWithSelect()
5146
{
52-
$this->setupTest();
53-
5447
$select = (new Select())->columns('COUNT(*)')->from('t1')->where(['c2 = ?' => 1]);
5548
$this->query->having($select);
5649

57-
$this->assertCorrectStatementAndValues('HAVING (SELECT COUNT(*) FROM t1 WHERE c2 = ?)', [1]);
50+
$this->assertSql('HAVING (SELECT COUNT(*) FROM t1 WHERE c2 = ?)', $this->query, [1]);
5851
}
5952

6053
public function testResetHaving()
6154
{
62-
$this->setupTest();
63-
6455
$this->query->having('c1 = x');
6556
$this->assertSame(
6657
['AND', [['AND', ['c1 = x']]]],

tests/InsertTest.php

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,97 +15,79 @@ class InsertTest extends TestCase
1515

1616
public function testEmptyInsertInto()
1717
{
18-
$this->setupTest();
19-
2018
$this->assertSame(null, $this->query->getInto());
2119
$this->assertSame([], $this->query->getColumns());
2220
$this->assertSame([], $this->query->getValues());
2321
$this->assertSame(null, $this->query->getSelect());
24-
$this->assertCorrectStatementAndValues('() VALUES()', []); // TODO(el): Should we render anything here?
22+
$this->assertSql('() VALUES()', $this->query, []); // TODO(el): Should we render anything here?
2523
}
2624

2725
public function testIntoTableSpecification()
2826
{
29-
$this->setupTest();
30-
3127
$this->query->into('table');
3228

3329
$this->assertSame('table', $this->query->getInto());
34-
$this->assertCorrectStatementAndValues('INSERT INTO table () VALUES()', []);
30+
$this->assertSql('INSERT INTO table () VALUES()', $this->query, []);
3531
}
3632

3733
public function testIntoTableSpecificationWithSchema()
3834
{
39-
$this->setupTest();
40-
4135
$this->query->into('schema.table');
4236

4337
$this->assertSame('schema.table', $this->query->getInto());
44-
$this->assertCorrectStatementAndValues('INSERT INTO schema.table () VALUES()', []);
38+
$this->assertSql('INSERT INTO schema.table () VALUES()', $this->query, []);
4539
}
4640

4741
public function testColumns()
4842
{
49-
$this->setupTest();
50-
5143
$columns = ['c1', 'c2'];
5244
$this->query->columns($columns);
5345

5446
$this->assertSame($columns, $this->query->getColumns());
55-
$this->assertCorrectStatementAndValues('(c1,c2) VALUES()', []);
47+
$this->assertSql('(c1,c2) VALUES()', $this->query, []);
5648
}
5749

5850
public function testValues()
5951
{
60-
$this->setupTest();
61-
6252
$this->query->values(['c1' => 'v1']);
6353

6454
$this->assertSame(['c1'], $this->query->getColumns());
6555
$this->assertSame(['v1'], $this->query->getValues());
66-
$this->assertCorrectStatementAndValues('(c1) VALUES(?)', ['v1']);
56+
$this->assertSql('(c1) VALUES(?)', $this->query, ['v1']);
6757
}
6858

6959
public function testExpressionValue()
7060
{
71-
$this->setupTest();
72-
7361
$value = new Expression('x = ?', null, 1);
7462
$this->query->values(['c1' => $value]);
7563

7664
$this->assertSame(['c1'], $this->query->getColumns());
7765
$this->assertSame([$value], $this->query->getValues());
78-
$this->assertCorrectStatementAndValues('(c1) VALUES(x = ?)', [1]);
66+
$this->assertSql('(c1) VALUES(x = ?)', $this->query, [1]);
7967
}
8068

8169
public function testSelectValue()
8270
{
83-
$this->setupTest();
84-
8571
$value = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]);
8672
$this->query->values(['c1' => $value]);
8773

8874
$this->assertSame(['c1'], $this->query->getColumns());
8975
$this->assertSame([$value], $this->query->getValues());
90-
$this->assertCorrectStatementAndValues('(c1) VALUES((SELECT COUNT(*) FROM table2 WHERE active = ?))', [1]);
76+
$this->assertSql('(c1) VALUES((SELECT COUNT(*) FROM table2 WHERE active = ?))', $this->query, [1]);
9177
}
9278

9379
public function testColumnsAndValues()
9480
{
95-
$this->setupTest();
96-
9781
$this->query->columns(['c1', 'c2']);
9882
$this->query->values(['v1', 'v2']);
9983

10084
$this->assertSame(['c1', 'c2'], $this->query->getColumns());
10185
$this->assertSame(['v1', 'v2'], $this->query->getValues());
102-
$this->assertCorrectStatementAndValues('(c1,c2) VALUES(?,?)', ['v1', 'v2']);
86+
$this->assertSql('(c1,c2) VALUES(?,?)', $this->query, ['v1', 'v2']);
10387
}
10488

10589
public function testInsertIntoSelectStatement()
10690
{
107-
$this->setupTest();
108-
10991
$select = (new Select())
11092
->from('table')
11193
->columns(['c1', 'c2']);
@@ -116,29 +98,25 @@ public function testInsertIntoSelectStatement()
11698
->select($select);
11799

118100
$this->assertSame($select, $this->query->getSelect());
119-
$this->assertCorrectStatementAndValues('INSERT INTO table (c1,c2) SELECT c1, c2 FROM table', []);
101+
$this->assertSql('INSERT INTO table (c1,c2) SELECT c1, c2 FROM table', $this->query, []);
120102
}
121103

122104
public function testInsertIntoStatementWithValues()
123105
{
124-
$this->setupTest();
125-
126106
$this->query
127107
->into('table')
128108
->values(['c1' => 'v1', 'c2' => 'v2']);
129109

130-
$this->assertCorrectStatementAndValues('INSERT INTO table (c1,c2) VALUES(?,?)', ['v1', 'v2']);
110+
$this->assertSql('INSERT INTO table (c1,c2) VALUES(?,?)', $this->query, ['v1', 'v2']);
131111
}
132112

133113
public function testInsertIntoStatementWithColumnsAndValues()
134114
{
135-
$this->setupTest();
136-
137115
$this->query
138116
->into('table')
139117
->columns(['c1', 'c2'])
140118
->values(['v1', 'v2']);
141119

142-
$this->assertCorrectStatementAndValues('INSERT INTO table (c1,c2) VALUES(?,?)', ['v1', 'v2']);
120+
$this->assertSql('INSERT INTO table (c1,c2) VALUES(?,?)', $this->query, ['v1', 'v2']);
143121
}
144122
}

tests/Mssql/SelectTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,29 @@ class SelectTest extends TestCase
1111

1212
public function testLimitOffset()
1313
{
14-
$this->setupTest();
15-
1614
$this->query->columns('a')->from('b')->orderBy('a')->limit(10)->offset(20);
1715

18-
$this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY a OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY');
16+
$this->assertSql('SELECT a FROM b ORDER BY a OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY', $this->query);
1917
}
2018

2119
public function testLimitWithoutOffset()
2220
{
23-
$this->setupTest();
24-
2521
$this->query->columns('a')->from('b')->orderBy('a')->limit(10);
2622

27-
$this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY a OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY');
23+
$this->assertSql('SELECT a FROM b ORDER BY a OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $this->query);
2824
}
2925

3026
public function testOffsetWithoutLimit()
3127
{
32-
$this->setupTest();
33-
3428
$this->query->columns('a')->from('b')->orderBy('a')->offset(20);
3529

36-
$this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY a OFFSET 20 ROWS');
30+
$this->assertSql('SELECT a FROM b ORDER BY a OFFSET 20 ROWS', $this->query);
3731
}
3832

3933
public function testAutomaticallyFixesLimitWithoutOrder()
4034
{
41-
$this->setupTest();
42-
4335
$this->query->columns('a')->from('b')->limit(10)->offset(30);
4436

45-
$this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY 1 OFFSET 30 ROWS FETCH NEXT 10 ROWS ONLY');
37+
$this->assertSql('SELECT a FROM b ORDER BY 1 OFFSET 30 ROWS FETCH NEXT 10 ROWS ONLY', $this->query);
4638
}
4739
}

0 commit comments

Comments
 (0)