Skip to content

Commit

Permalink
Merge pull request #33 from Icinga/support-php8
Browse files Browse the repository at this point in the history
Support PHP 8
  • Loading branch information
nilmerg authored Apr 8, 2021
2 parents e8cffd1 + 0dfc281 commit 34bde04
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 11 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,34 @@ class DeleteTest extends \PHPUnit\Framework\TestCase
*/
protected $queryBuilder;

public function setUp()
public function setupTestTest()
{
$this->query = new Delete();
$this->queryBuilder = new QueryBuilder(new TestAdapter());
}

public function testFrom()
{
$this->setupTestTest();

$this->query->from('table');
$this->assertSame(['table'], $this->query->getFrom());
$this->assertCorrectStatementAndValues('DELETE FROM table', []);
}

public function testFromWithAlias()
{
$this->setupTestTest();

$this->query->from('table t1');
$this->assertSame(['table t1'], $this->query->getFrom());
$this->assertCorrectStatementAndValues('DELETE FROM table t1', []);
}

public function testFromWithArray()
{
$this->setupTestTest();

$this->query->from(['t1' => 'table']);
$this->assertSame(['t1' => 'table'], $this->query->getFrom());
$this->assertCorrectStatementAndValues('DELETE FROM table t1', []);
Expand Down
12 changes: 11 additions & 1 deletion tests/HavingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ class HavingTest extends \PHPUnit\Framework\TestCase
*/
protected $queryBuilder;

public function setUp()
public function setupTest()
{
$this->query = new Select();
$this->queryBuilder = new QueryBuilder(new TestAdapter());
}

public function testHavingStringFormat()
{
$this->setupTest();

$this->query->having('c1 = x');
$this->query->having('c2 IS NULL');
$this->query->having('c3 IS NOT NULL');
Expand All @@ -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]);
Expand All @@ -57,6 +61,8 @@ public function testHavingArrayFormat()

public function testWhereWithExpression()
{
$this->setupTest();

$expression = new Expression('c2 = ?', null, 1);
$this->query->having($expression);

Expand All @@ -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);

Expand All @@ -73,6 +81,8 @@ public function testWhereWithSelect()

public function testResetHaving()
{
$this->setupTest();

$this->query->having('c1 = x');
$this->assertSame(
['AND', [['AND', ['c1 = x']]]],
Expand Down
24 changes: 23 additions & 1 deletion tests/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ class InsertTest extends \PHPUnit\Framework\TestCase
*/
protected $queryBuilder;

public function setUp()
public function setupTest()
{
$this->query = new Insert();
$this->queryBuilder = new QueryBuilder(new TestAdapter());
}

public function testEmptyInsertInto()
{
$this->setupTest();

$this->assertSame(null, $this->query->getInto());
$this->assertSame([], $this->query->getColumns());
$this->assertSame([], $this->query->getValues());
Expand All @@ -40,6 +42,8 @@ public function testEmptyInsertInto()

public function testIntoTableSpecification()
{
$this->setupTest();

$this->query->into('table');

$this->assertSame('table', $this->query->getInto());
Expand All @@ -48,6 +52,8 @@ public function testIntoTableSpecification()

public function testIntoTableSpecificationWithSchema()
{
$this->setupTest();

$this->query->into('schema.table');

$this->assertSame('schema.table', $this->query->getInto());
Expand All @@ -56,6 +62,8 @@ public function testIntoTableSpecificationWithSchema()

public function testColumns()
{
$this->setupTest();

$columns = ['c1', 'c2'];
$this->query->columns($columns);

Expand All @@ -65,6 +73,8 @@ public function testColumns()

public function testValues()
{
$this->setupTest();

$this->query->values(['c1' => 'v1']);

$this->assertSame(['c1'], $this->query->getColumns());
Expand All @@ -74,6 +84,8 @@ public function testValues()

public function testExpressionValue()
{
$this->setupTest();

$value = new Expression('x = ?', null, 1);
$this->query->values(['c1' => $value]);

Expand All @@ -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]);

Expand All @@ -94,6 +108,8 @@ public function testSelectValue()

public function testColumnsAndValues()
{
$this->setupTest();

$this->query->columns(['c1', 'c2']);
$this->query->values(['v1', 'v2']);

Expand All @@ -104,6 +120,8 @@ public function testColumnsAndValues()

public function testInsertIntoSelectStatement()
{
$this->setupTest();

$select = (new Select())
->from('table')
->columns(['c1', 'c2']);
Expand All @@ -119,6 +137,8 @@ public function testInsertIntoSelectStatement()

public function testInsertIntoStatementWithValues()
{
$this->setupTest();

$this->query
->into('table')
->values(['c1' => 'v1', 'c2' => 'v2']);
Expand All @@ -128,6 +148,8 @@ public function testInsertIntoStatementWithValues()

public function testInsertIntoStatementWithColumnsAndValues()
{
$this->setupTest();

$this->query
->into('table')
->columns(['c1', 'c2'])
Expand Down
10 changes: 9 additions & 1 deletion tests/Mssql/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,43 @@ class SelectTest extends \PHPUnit\Framework\TestCase
*/
protected $queryBuilder;

public function setUp()
public function setupTest()
{
$this->query = new Select();
$this->queryBuilder = new QueryBuilder(new Mssql());
}

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');
}

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');
}

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');
}

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');
Expand Down
Loading

0 comments on commit 34bde04

Please sign in to comment.