diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ed68b91..58bbdc4 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] os: ['ubuntu-latest'] include: - php: '5.6' @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} tools: phpcs @@ -51,18 +51,20 @@ jobs: runs-on: ${{ matrix.os }} env: - phpunit-version: 7.5.20 + phpunit-version: 8.5.15 strategy: fail-fast: false matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] os: ['ubuntu-latest'] include: - php: '5.6' phpunit-version: 5.7.27 - php: '7.0' phpunit-version: 6.5.14 + - php: '7.1' + phpunit-version: 7.5.20 steps: - name: Checkout code base diff --git a/tests/DeleteTest.php b/tests/DeleteTest.php index 3ce54de..51774ab 100644 --- a/tests/DeleteTest.php +++ b/tests/DeleteTest.php @@ -21,7 +21,7 @@ class DeleteTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTestTest() { $this->query = new Delete(); $this->queryBuilder = new QueryBuilder(new TestAdapter()); @@ -29,6 +29,8 @@ public function setUp() public function testFrom() { + $this->setupTestTest(); + $this->query->from('table'); $this->assertSame(['table'], $this->query->getFrom()); $this->assertCorrectStatementAndValues('DELETE FROM table', []); @@ -36,6 +38,8 @@ public function testFrom() public function testFromWithAlias() { + $this->setupTestTest(); + $this->query->from('table t1'); $this->assertSame(['table t1'], $this->query->getFrom()); $this->assertCorrectStatementAndValues('DELETE FROM table t1', []); @@ -43,6 +47,8 @@ public function testFromWithAlias() public function testFromWithArray() { + $this->setupTestTest(); + $this->query->from(['t1' => 'table']); $this->assertSame(['t1' => 'table'], $this->query->getFrom()); $this->assertCorrectStatementAndValues('DELETE FROM table t1', []); diff --git a/tests/HavingTest.php b/tests/HavingTest.php index 09d748e..c035d05 100644 --- a/tests/HavingTest.php +++ b/tests/HavingTest.php @@ -23,7 +23,7 @@ class HavingTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTest() { $this->query = new Select(); $this->queryBuilder = new QueryBuilder(new TestAdapter()); @@ -31,6 +31,8 @@ public function setUp() public function testHavingStringFormat() { + $this->setupTest(); + $this->query->having('c1 = x'); $this->query->having('c2 IS NULL'); $this->query->having('c3 IS NOT NULL'); @@ -40,6 +42,8 @@ public function testHavingStringFormat() public function testHavingArrayFormat() { + $this->setupTest(); + $this->query->having(['c1 = x']); $this->query->having(['c2 = ?' => 1]); $this->query->having(['c3 > ?' => 1]); @@ -57,6 +61,8 @@ public function testHavingArrayFormat() public function testWhereWithExpression() { + $this->setupTest(); + $expression = new Expression('c2 = ?', null, 1); $this->query->having($expression); @@ -65,6 +71,8 @@ public function testWhereWithExpression() public function testWhereWithSelect() { + $this->setupTest(); + $select = (new Select())->columns('COUNT(*)')->from('t1')->where(['c2 = ?' => 1]); $this->query->having($select); @@ -73,6 +81,8 @@ public function testWhereWithSelect() public function testResetHaving() { + $this->setupTest(); + $this->query->having('c1 = x'); $this->assertSame( ['AND', [['AND', ['c1 = x']]]], diff --git a/tests/InsertTest.php b/tests/InsertTest.php index 4672813..dd1a200 100644 --- a/tests/InsertTest.php +++ b/tests/InsertTest.php @@ -23,7 +23,7 @@ class InsertTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTest() { $this->query = new Insert(); $this->queryBuilder = new QueryBuilder(new TestAdapter()); @@ -31,6 +31,8 @@ public function setUp() public function testEmptyInsertInto() { + $this->setupTest(); + $this->assertSame(null, $this->query->getInto()); $this->assertSame([], $this->query->getColumns()); $this->assertSame([], $this->query->getValues()); @@ -40,6 +42,8 @@ public function testEmptyInsertInto() public function testIntoTableSpecification() { + $this->setupTest(); + $this->query->into('table'); $this->assertSame('table', $this->query->getInto()); @@ -48,6 +52,8 @@ public function testIntoTableSpecification() public function testIntoTableSpecificationWithSchema() { + $this->setupTest(); + $this->query->into('schema.table'); $this->assertSame('schema.table', $this->query->getInto()); @@ -56,6 +62,8 @@ public function testIntoTableSpecificationWithSchema() public function testColumns() { + $this->setupTest(); + $columns = ['c1', 'c2']; $this->query->columns($columns); @@ -65,6 +73,8 @@ public function testColumns() public function testValues() { + $this->setupTest(); + $this->query->values(['c1' => 'v1']); $this->assertSame(['c1'], $this->query->getColumns()); @@ -74,6 +84,8 @@ public function testValues() public function testExpressionValue() { + $this->setupTest(); + $value = new Expression('x = ?', null, 1); $this->query->values(['c1' => $value]); @@ -84,6 +96,8 @@ public function testExpressionValue() public function testSelectValue() { + $this->setupTest(); + $value = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->values(['c1' => $value]); @@ -94,6 +108,8 @@ public function testSelectValue() public function testColumnsAndValues() { + $this->setupTest(); + $this->query->columns(['c1', 'c2']); $this->query->values(['v1', 'v2']); @@ -104,6 +120,8 @@ public function testColumnsAndValues() public function testInsertIntoSelectStatement() { + $this->setupTest(); + $select = (new Select()) ->from('table') ->columns(['c1', 'c2']); @@ -119,6 +137,8 @@ public function testInsertIntoSelectStatement() public function testInsertIntoStatementWithValues() { + $this->setupTest(); + $this->query ->into('table') ->values(['c1' => 'v1', 'c2' => 'v2']); @@ -128,6 +148,8 @@ public function testInsertIntoStatementWithValues() public function testInsertIntoStatementWithColumnsAndValues() { + $this->setupTest(); + $this->query ->into('table') ->columns(['c1', 'c2']) diff --git a/tests/Mssql/SelectTest.php b/tests/Mssql/SelectTest.php index 1f95320..2f055f4 100644 --- a/tests/Mssql/SelectTest.php +++ b/tests/Mssql/SelectTest.php @@ -22,7 +22,7 @@ class SelectTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTest() { $this->query = new Select(); $this->queryBuilder = new QueryBuilder(new Mssql()); @@ -30,6 +30,8 @@ public function setUp() public function testLimitOffset() { + $this->setupTest(); + $this->query->columns('a')->from('b')->orderBy('a')->limit(10)->offset(20); $this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY a OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY'); @@ -37,6 +39,8 @@ public function testLimitOffset() public function testLimitWithoutOffset() { + $this->setupTest(); + $this->query->columns('a')->from('b')->orderBy('a')->limit(10); $this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY a OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'); @@ -44,6 +48,8 @@ public function testLimitWithoutOffset() public function testOffsetWithoutLimit() { + $this->setupTest(); + $this->query->columns('a')->from('b')->orderBy('a')->offset(20); $this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY a OFFSET 20 ROWS'); @@ -51,6 +57,8 @@ public function testOffsetWithoutLimit() public function testAutomaticallyFixesLimitWithoutOrder() { + $this->setupTest(); + $this->query->columns('a')->from('b')->limit(10)->offset(30); $this->assertCorrectStatementAndValues('SELECT a FROM b ORDER BY 1 OFFSET 30 ROWS FETCH NEXT 10 ROWS ONLY'); diff --git a/tests/SelectTest.php b/tests/SelectTest.php index e5305ea..f81a3b5 100644 --- a/tests/SelectTest.php +++ b/tests/SelectTest.php @@ -23,7 +23,7 @@ class SelectTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTest() { $this->query = new Select(); $this->queryBuilder = new QueryBuilder(new TestAdapter()); @@ -31,6 +31,8 @@ public function setUp() public function testDistinct() { + $this->setupTest(); + $this->query ->distinct() ->columns('1'); @@ -41,6 +43,8 @@ public function testDistinct() public function testColumns() { + $this->setupTest(); + $this->query->columns('1'); $this->assertSame(['1'], $this->query->getColumns()); @@ -49,6 +53,8 @@ public function testColumns() public function testColumnsWithAlias() { + $this->setupTest(); + $this->query->columns('1 AS one'); $this->assertSame(['1 AS one'], $this->query->getColumns()); @@ -57,6 +63,8 @@ public function testColumnsWithAlias() public function testColumnsWithArray() { + $this->setupTest(); + $this->query->columns(['1', '2']); $this->assertSame(['1', '2'], $this->query->getColumns()); @@ -65,6 +73,8 @@ public function testColumnsWithArray() public function testColumnsWithArrayAndAlias() { + $this->setupTest(); + $this->query->columns(['one' => '1', '2']); $this->assertSame(['one' => '1', '2'], $this->query->getColumns()); @@ -73,6 +83,8 @@ public function testColumnsWithArrayAndAlias() public function testColumnsWithExpression() { + $this->setupTest(); + $columns = ['three' => new Expression('? + ?', null, 1, 2)]; $this->query->columns($columns); @@ -82,6 +94,8 @@ public function testColumnsWithExpression() public function testColumnsWithSelect() { + $this->setupTest(); + $columns = [ 'customers' => (new Select()) ->columns('COUNT(*)') @@ -100,6 +114,8 @@ public function testColumnsWithSelect() public function testFrom() { + $this->setupTest(); + $this->query->from('table'); $this->assertSame(['table'], $this->query->getFrom()); @@ -108,6 +124,8 @@ public function testFrom() public function testFromWithAlias() { + $this->setupTest(); + $this->query->from('table t1'); $this->assertSame(['table t1'], $this->query->getFrom()); @@ -116,6 +134,8 @@ public function testFromWithAlias() public function testFromWithArray() { + $this->setupTest(); + $this->query->from(['t1' => 'table']); $this->assertSame(['t1' => 'table'], $this->query->getFrom()); @@ -124,6 +144,8 @@ public function testFromWithArray() public function testFromWithSelect() { + $this->setupTest(); + $from = ['t1' => (new Select()) ->columns('*') ->from('table') @@ -137,6 +159,8 @@ public function testFromWithSelect() public function testInnerJoin() { + $this->setupTest(); + $this->query->join('table2', 'table2.table1_id = table1.id'); $this->assertCorrectStatementAndValues('INNER JOIN table2 ON table2.table1_id = table1.id', []); @@ -144,6 +168,8 @@ public function testInnerJoin() public function testInnerJoinWithAlias() { + $this->setupTest(); + $this->query->join('table2 t2', 't2.table1_id = t1.id'); $this->assertCorrectStatementAndValues('INNER JOIN table2 t2 ON t2.table1_id = t1.id', []); @@ -151,6 +177,8 @@ public function testInnerJoinWithAlias() public function testInnerJoinWithArray() { + $this->setupTest(); + $this->query->join(['t2' => 'table2'], 't2.table1_id = t1.id'); $this->assertCorrectStatementAndValues('INNER JOIN table2 t2 ON t2.table1_id = t1.id', []); @@ -158,6 +186,8 @@ public function testInnerJoinWithArray() public function testInnerJoinWithComplexCondition() { + $this->setupTest(); + $this->query->join('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42']); $this->assertCorrectStatementAndValues( @@ -168,6 +198,8 @@ public function testInnerJoinWithComplexCondition() public function testInnerJoinWithOperatorAll() { + $this->setupTest(); + $this->query->join('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42'], Sql::ALL); $this->assertCorrectStatementAndValues( @@ -178,6 +210,8 @@ public function testInnerJoinWithOperatorAll() public function testInnerJoinWithOperatorAny() { + $this->setupTest(); + $this->query->join('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42'], Sql::ANY); $this->assertCorrectStatementAndValues( @@ -188,6 +222,8 @@ public function testInnerJoinWithOperatorAny() public function testInnerJoinWithParametrizedCondition() { + $this->setupTest(); + $this->query->join('table2', ['table2.table1_id = table1.id', 'table2.table3_id = ?' => 42]); $this->assertCorrectStatementAndValues( @@ -198,6 +234,8 @@ public function testInnerJoinWithParametrizedCondition() public function testInnerJoinWithSelect() { + $this->setupTest(); + $table2 = ['t2' => (new Select())->columns('*')->from('table2')->where(['active = ?' => 1])]; $this->query->join($table2, 't2.table1_id = t1.id'); @@ -209,6 +247,8 @@ public function testInnerJoinWithSelect() public function testInnerJoinWithExpressionCondition() { + $this->setupTest(); + $condition = new Expression('t2.table1_id = ?', null, 1); $this->query->join('table2', $condition); @@ -217,6 +257,8 @@ public function testInnerJoinWithExpressionCondition() public function testInnerJoinWithSelectCondition() { + $this->setupTest(); + $condition = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->join('table2', $condition); @@ -228,6 +270,8 @@ public function testInnerJoinWithSelectCondition() public function testLeftJoin() { + $this->setupTest(); + $this->query->joinLeft('table2', 'table2.table1_id = table1.id'); $this->assertCorrectStatementAndValues('LEFT JOIN table2 ON table2.table1_id = table1.id', []); @@ -235,6 +279,8 @@ public function testLeftJoin() public function testLeftJoinWithAlias() { + $this->setupTest(); + $this->query->joinLeft('table2 t2', 't2.table1_id = t1.id'); $this->assertCorrectStatementAndValues('LEFT JOIN table2 t2 ON t2.table1_id = t1.id', []); @@ -242,6 +288,8 @@ public function testLeftJoinWithAlias() public function testLeftJoinWithArray() { + $this->setupTest(); + $this->query->joinLeft(['t2' => 'table2'], 't2.table1_id = t1.id'); $this->assertCorrectStatementAndValues('LEFT JOIN table2 t2 ON t2.table1_id = t1.id', []); @@ -249,6 +297,8 @@ public function testLeftJoinWithArray() public function testLeftJoinWithComplexCondition() { + $this->setupTest(); + $this->query->joinLeft('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42']); $this->assertCorrectStatementAndValues( @@ -259,6 +309,8 @@ public function testLeftJoinWithComplexCondition() public function testLeftJoinWithOperatorAll() { + $this->setupTest(); + $this->query->joinLeft('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42'], Sql::ALL); $this->assertCorrectStatementAndValues( @@ -269,6 +321,8 @@ public function testLeftJoinWithOperatorAll() public function testLeftJoinWithOperatorAny() { + $this->setupTest(); + $this->query->joinLeft('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42'], Sql::ANY); $this->assertCorrectStatementAndValues( @@ -279,6 +333,8 @@ public function testLeftJoinWithOperatorAny() public function testLeftJoinWithParametrizedCondition() { + $this->setupTest(); + $this->query->joinLeft('table2', ['table2.table1_id = table1.id', 'table2.table3_id = ?' => 42]); $this->assertCorrectStatementAndValues( @@ -289,6 +345,8 @@ public function testLeftJoinWithParametrizedCondition() public function testLeftJoinWithSelect() { + $this->setupTest(); + $table2 = ['t2' => (new Select())->columns('*')->from('table2')->where(['active = ?' => 1])]; $this->query->joinLeft($table2, 't2.table1_id = t1.id'); @@ -300,6 +358,8 @@ public function testLeftJoinWithSelect() public function testLeftJoinWithExpressionCondition() { + $this->setupTest(); + $condition = new Expression('t2.table1_id = ?', null, 1); $this->query->joinLeft('table2', $condition); @@ -308,6 +368,8 @@ public function testLeftJoinWithExpressionCondition() public function testLeftJoinWithSelectCondition() { + $this->setupTest(); + $condition = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->joinLeft('table2', $condition); @@ -319,6 +381,8 @@ public function testLeftJoinWithSelectCondition() public function testRightJoin() { + $this->setupTest(); + $this->query->joinRight('table2', 'table2.table1_id = table1.id'); $this->assertCorrectStatementAndValues('RIGHT JOIN table2 ON table2.table1_id = table1.id', []); @@ -326,6 +390,8 @@ public function testRightJoin() public function testRightJoinWithAlias() { + $this->setupTest(); + $this->query->joinRight('table2 t2', 't2.table1_id = t1.id'); $this->assertCorrectStatementAndValues('RIGHT JOIN table2 t2 ON t2.table1_id = t1.id', []); @@ -333,6 +399,8 @@ public function testRightJoinWithAlias() public function testRightJoinWithArray() { + $this->setupTest(); + $this->query->joinRight(['t2' => 'table2'], 't2.table1_id = t1.id'); $this->assertCorrectStatementAndValues('RIGHT JOIN table2 t2 ON t2.table1_id = t1.id', []); @@ -340,6 +408,8 @@ public function testRightJoinWithArray() public function testRightJoinWithComplexCondition() { + $this->setupTest(); + $this->query->joinRight('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42']); $this->assertCorrectStatementAndValues( @@ -350,6 +420,8 @@ public function testRightJoinWithComplexCondition() public function testRightJoinWithOperatorAll() { + $this->setupTest(); + $this->query->joinRight('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42'], Sql::ALL); $this->assertCorrectStatementAndValues( @@ -360,6 +432,8 @@ public function testRightJoinWithOperatorAll() public function testRightJoinWithOperatorAny() { + $this->setupTest(); + $this->query->joinRight('table2', ['table2.table1_id = table1.id', 'table2.table3_id = 42'], Sql::ANY); $this->assertCorrectStatementAndValues( @@ -370,6 +444,8 @@ public function testRightJoinWithOperatorAny() public function testRightJoinWithParametrizedCondition() { + $this->setupTest(); + $this->query->joinRight('table2', ['table2.table1_id = table1.id', 'table2.table3_id = ?' => 42]); $this->assertCorrectStatementAndValues( @@ -380,6 +456,8 @@ public function testRightJoinWithParametrizedCondition() public function testRightJoinWithSelect() { + $this->setupTest(); + $table2 = ['t2' => (new Select())->columns('*')->from('table2')->where(['active = ?' => 1])]; $this->query->joinRight($table2, 't2.table1_id = t1.id'); @@ -391,6 +469,8 @@ public function testRightJoinWithSelect() public function testRightJoinWithExpressionCondition() { + $this->setupTest(); + $condition = new Expression('t2.table1_id = ?', null, 1); $this->query->joinRight('table2', $condition); @@ -399,6 +479,8 @@ public function testRightJoinWithExpressionCondition() public function testRightJoinWithSelectCondition() { + $this->setupTest(); + $condition = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->joinRight('table2', $condition); @@ -410,6 +492,8 @@ public function testRightJoinWithSelectCondition() public function testGroupBy() { + $this->setupTest(); + $this->query->groupBy(['a', 'b']); $this->assertCorrectStatementAndValues('GROUP BY a, b', []); @@ -417,6 +501,8 @@ public function testGroupBy() public function testGroupByWithAlias() { + $this->setupTest(); + $this->query->groupBy(['t.a', 't.b']); $this->assertCorrectStatementAndValues('GROUP BY t.a, t.b', []); @@ -424,6 +510,8 @@ public function testGroupByWithAlias() public function testGroupByWithExpression() { + $this->setupTest(); + $column = new Expression('x = ?', null, 1); $this->query->groupBy([$column]); @@ -432,6 +520,8 @@ public function testGroupByWithExpression() public function testGroupByWithSelect() { + $this->setupTest(); + $column = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->groupBy([$column]); @@ -440,6 +530,8 @@ public function testGroupByWithSelect() public function testOrderBy() { + $this->setupTest(); + $this->query->orderBy(['a', 'b' => 'ASC'], 'DESC'); $this->assertCorrectStatementAndValues('ORDER BY a DESC, b ASC', []); @@ -447,6 +539,8 @@ public function testOrderBy() public function testOrderByWithExpression() { + $this->setupTest(); + $column = new Expression('x = ?', null, 1); $this->query->orderBy($column, 'DESC'); @@ -455,6 +549,8 @@ public function testOrderByWithExpression() public function testOrderByWithExpressionAndExplicitDirection() { + $this->setupTest(); + $column = new Expression('x = ?', null, 1); $this->query->orderBy([[$column, 'DESC']]); @@ -463,6 +559,8 @@ public function testOrderByWithExpressionAndExplicitDirection() public function testOrderByWithSelect() { + $this->setupTest(); + $column = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->orderBy($column, 'DESC'); @@ -471,6 +569,8 @@ public function testOrderByWithSelect() public function testLimitOffset() { + $this->setupTest(); + $this->query = (new Select())->columns(['a'])->from('b')->limit(4)->offset(1); $this->assertCorrectStatementAndValues( 'SELECT a FROM b LIMIT 4 OFFSET 1', @@ -480,6 +580,8 @@ public function testLimitOffset() public function testLimitWithoutOffset() { + $this->setupTest(); + $this->query = (new Select())->columns(['a'])->from('b')->limit(4); $this->assertCorrectStatementAndValues( 'SELECT a FROM b LIMIT 4', @@ -489,6 +591,8 @@ public function testLimitWithoutOffset() public function testOffsetWithoutLimit() { + $this->setupTest(); + $this->query = (new Select())->columns(['a'])->from('b')->offset(1); $this->assertCorrectStatementAndValues( 'SELECT a FROM b OFFSET 1', @@ -498,6 +602,8 @@ public function testOffsetWithoutLimit() public function testUnion() { + $this->setupTest(); + $unionQuery = (new Select()) ->columns('a') ->from('table2') @@ -517,6 +623,8 @@ public function testUnion() public function testUnionAll() { + $this->setupTest(); + $unionQuery = (new Select()) ->columns('a') ->from('table2') @@ -536,6 +644,8 @@ public function testUnionAll() public function testElementOrder() { + $this->setupTest(); + $this->query ->distinct() ->columns(['c.id', 'c.name', 'orders' => 'COUNT(o.customer)']) @@ -564,6 +674,8 @@ public function testElementOrder() public function testRollupMysql() { + $this->setupTest(); + $this->query ->columns([ 'division' => 'di.name', @@ -587,6 +699,8 @@ public function testRollupMysql() public function testRollupPostgresql() { + $this->setupTest(); + $this->query ->columns([ 'division' => 'di.name', @@ -610,6 +724,8 @@ public function testRollupPostgresql() public function testJustAUnionRendersAsSelect() { + $this->setupTest(); + $unionQuery = (new Select()) ->columns('a') ->from('table2') @@ -626,6 +742,8 @@ public function testJustAUnionRendersAsSelect() public function testMoreThanOneUnionWithoutSelect() { + $this->setupTest(); + $union1 = (new Select()) ->columns('a') ->from('table1') @@ -648,6 +766,8 @@ public function testMoreThanOneUnionWithoutSelect() public function testMoreThanOneUnionWithSelect() { + $this->setupTest(); + $union1 = (new Select()) ->columns('a') ->from('table1') @@ -674,6 +794,8 @@ public function testMoreThanOneUnionWithSelect() public function testCountDistinct() { + $this->setupTest(); + $this->query = $this->query ->distinct() ->from('table') diff --git a/tests/UpdateTest.php b/tests/UpdateTest.php index f6a2fe1..a743804 100644 --- a/tests/UpdateTest.php +++ b/tests/UpdateTest.php @@ -23,7 +23,7 @@ class UpdateTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTest() { $this->query = new Update(); $this->queryBuilder = new QueryBuilder(new TestAdapter()); @@ -31,6 +31,8 @@ public function setUp() public function testEmptyUpdateTable() { + $this->setupTest(); + $this->assertSame(null, $this->query->getTable()); $this->assertSame([], $this->query->getSet()); $this->assertCorrectStatementAndValues('SET ', []); @@ -38,6 +40,8 @@ public function testEmptyUpdateTable() public function testTableSpecification() { + $this->setupTest(); + $this->query->table('table'); $this->assertSame(['table'], $this->query->getTable()); @@ -46,6 +50,8 @@ public function testTableSpecification() public function testTableSpecificationWithSchema() { + $this->setupTest(); + $this->query->table('schema.table'); $this->assertSame(['schema.table'], $this->query->getTable()); @@ -54,6 +60,8 @@ public function testTableSpecificationWithSchema() public function testSet() { + $this->setupTest(); + $this->query->set(['c1' => 'v1', 'c2' => 'v2']); $this->assertSame(['c1' => 'v1', 'c2' => 'v2'], $this->query->getSet()); @@ -62,6 +70,8 @@ public function testSet() public function testExpressionValue() { + $this->setupTest(); + $value = new Expression('x = ?', null, 1); $this->query->set(['c1' => $value]); @@ -71,6 +81,8 @@ public function testExpressionValue() public function testSelectValue() { + $this->setupTest(); + $value = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]); $this->query->set(['c1' => $value]); @@ -80,6 +92,8 @@ public function testSelectValue() public function testUpdateStatementWithSet() { + $this->setupTest(); + $this->query ->table('table') ->set(['c1' => 'v1', 'c2' => 'v2']); diff --git a/tests/WhereTest.php b/tests/WhereTest.php index b501e94..67a9950 100644 --- a/tests/WhereTest.php +++ b/tests/WhereTest.php @@ -23,7 +23,7 @@ class WhereTest extends \PHPUnit\Framework\TestCase */ protected $queryBuilder; - public function setUp() + public function setupTest() { $this->query = new Select(); $this->queryBuilder = new QueryBuilder(new TestAdapter()); @@ -31,6 +31,8 @@ public function setUp() public function testWhereStringFormat() { + $this->setupTest(); + $this->query->where('c1 = x'); $this->query->where('c2 IS NULL'); $this->query->where('c3 IS NOT NULL'); @@ -40,6 +42,8 @@ public function testWhereStringFormat() public function testWhereArrayFormat() { + $this->setupTest(); + $this->query->where(['c1 = x']); $this->query->where(['c2 = ?' => 1]); $this->query->where(['c3 > ?' => 1]); @@ -57,6 +61,8 @@ public function testWhereArrayFormat() public function testSingleNotWhere() { + $this->setupTest(); + $this->query->notWhere('foo = bar'); $this->assertCorrectStatementAndValues('WHERE NOT (foo = bar)', []); @@ -64,12 +70,16 @@ public function testSingleNotWhere() public function testVariadicWhereUsedVariadic() { + $this->setupTest(); + $this->query->where('a IN (?) AND b < ?', [1, 2, 3], 4); $this->assertCorrectStatementAndValues('WHERE a IN (?, ?, ?) AND b < ?', [1, 2, 3, 4]); } public function testNotWhereCombiningVariadicAndArrayStyle() { + $this->setupTest(); + $this->query->where('a = ?', 1); $this->query->notWhere('a IN (?) AND b < ?', [2, 3, 4], 5); $this->query->notWhere(['a = ?' => 6, 'b = ?' => 7], Sql::ANY); @@ -81,6 +91,8 @@ public function testNotWhereCombiningVariadicAndArrayStyle() public function testNotWhereArrayFormat() { + $this->setupTest(); + $this->query->notWhere(['c1 = x']); $this->query->notWhere(['c2 = ?' => 1]); $this->query->notWhere(['c3 IN (?)' => [1, 2, 3]]); @@ -94,6 +106,8 @@ public function testNotWhereArrayFormat() public function testWhereWithArrayBeforeScalar() { + $this->setupTest(); + $this->query->where(['INTERVAL(a, ?) < ?' => [[1, 2, 3], 4]]); $this->assertCorrectStatementAndValues( @@ -104,6 +118,8 @@ public function testWhereWithArrayBeforeScalar() public function testWhereWithArrayAfterScalar() { + $this->setupTest(); + $this->query->where(['? < INTERVAL(a, ?)' => [1, [2, 3, 4]]]); $this->assertCorrectStatementAndValues( @@ -114,6 +130,8 @@ public function testWhereWithArrayAfterScalar() public function testWhereWithArrayAfterArray() { + $this->setupTest(); + $this->query->where(['a IN (?) AND b IN (?)' => [[1, 2], [3, 4]]]); $this->assertCorrectStatementAndValues( @@ -124,6 +142,8 @@ public function testWhereWithArrayAfterArray() public function testWhereWithManyPlaceholders() { + $this->setupTest(); + $this->query->where([ 'c1 IN(?) AND c2 = ? AND INTERVAL(?, ?, 10, 100, ?) < ?' => [[1, 2, 3], 4, [5, 6], 7, 8, 9] ]); @@ -136,6 +156,8 @@ public function testWhereWithManyPlaceholders() public function testMixedWhere() { + $this->setupTest(); + $this->query->where('c1 = 1'); $this->query->orWhere(['c2 = ?' => 2]); $this->query->notWhere(['c3 = 3', 'c4 = ?' => 4]); @@ -151,6 +173,8 @@ public function testMixedWhere() public function testWhereNestedArrays() { + $this->setupTest(); + $this->query->where([ Sql::ANY, [ @@ -179,6 +203,8 @@ public function testWhereNestedArrays() public function testPartiallyPreparedWhere() { + $this->setupTest(); + $this->query->where([ [ Sql::ALL, @@ -204,6 +230,8 @@ public function testPartiallyPreparedWhere() public function testWhereWithExpression() { + $this->setupTest(); + $expression = new Expression('c2 = ?', null, 1); $this->query->where($expression); @@ -212,6 +240,8 @@ public function testWhereWithExpression() public function testWhereWithSelect() { + $this->setupTest(); + $select = (new Select())->columns('COUNT(*)')->from('t1')->where(['c2 = ?' => 1]); $this->query->where($select); @@ -220,6 +250,8 @@ public function testWhereWithSelect() public function testWhereWithSelectAndExpression() { + $this->setupTest(); + $select = (new Select())->columns('1')->from('t1')->where(['c2 = ?' => 1])->limit(1); $this->query->where(['EXISTS ?' => $select]); @@ -228,6 +260,8 @@ public function testWhereWithSelectAndExpression() public function testWhereWithExpressionThatCanBeRenderedToString() { + $this->setupTest(); + $this->query->where( new ExpressionThatCanBeRenderedToString("COALESCE('a', ?) = ?"), [1, 2], @@ -239,6 +273,8 @@ public function testWhereWithExpressionThatCanBeRenderedToString() public function testResetWhere() { + $this->setupTest(); + $this->query->where('c1 = x'); $this->assertSame( ['AND', [['AND', ['c1 = x']]]],