diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fa38a9f..7c48514 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,26 +9,16 @@ jobs: strategy: matrix: os: [ubuntu-latest] - php: [8.2, 8.1, 8.0, 7.4] - laravel: [10.*, 9.*, 8.*] + php: [8.4, 8.3, 8.2] + laravel: [12.*, 11.*] stability: [prefer-lowest, prefer-stable] firebird: [v4.0, v3.0, v2.5.9-sc] include: - - laravel: 8.* - testbench: ^6.19 - - laravel: 9.* - testbench: ^7.0 - - laravel: 10.* - testbench: ^8.0 - exclude: - - laravel: 8.* - php: 8.2 - - laravel: 9.* - php: 7.4 - - laravel: 10.* - php: 8.0 - - laravel: 10.* - php: 7.4 + - laravel: 11.* + testbench: ^9.0 + - laravel: 12.* + testbench: ^10.0 + fail-fast: false name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, Firebird ${{ matrix.firebird }}, ${{ matrix.stability }} @@ -44,7 +34,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.gitignore b/.gitignore index 8227305..261ae4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea .php_cs .php_cs.cache +.phpunit.cache .phpunit.result.cache .DS_Store build diff --git a/composer.json b/composer.json index 949e711..711b282 100644 --- a/composer.json +++ b/composer.json @@ -4,15 +4,15 @@ "license": "MIT", "require": { "php": "^7.4|^8.0", - "illuminate/support": "^8.65|^9.33|^10.0", - "illuminate/container": "^8.65|^9.33|^10.0", - "illuminate/database": "^8.65|^9.33|^10.0", - "illuminate/events": "^8.65|^9.33|^10.0" + "illuminate/support": "^8.65|^9.33|^10.0|^11.0|^12.0", + "illuminate/container": "^8.65|^9.33|^10.0|^11.0|^12.0", + "illuminate/database": "^8.65|^9.33|^10.0|^11.0|^12.0", + "illuminate/events": "^8.65|^9.33|^10.0|^11.0|^12.0" }, "require-dev": { "mockery/mockery": "^1.4", - "phpunit/phpunit": "^9.5.10", - "orchestra/testbench": "^6.19|^7.0|^8.0", + "phpunit/phpunit": "^9.6.11|^10.0|^11.0", + "orchestra/testbench": "^6.19|^7.0|^8.0|^9.0|^10.0", "fakerphp/faker": "^1.15" }, "archive": { diff --git a/readme.md b/readme.md index 94ff4b5..807dd50 100644 --- a/readme.md +++ b/readme.md @@ -9,8 +9,8 @@ This package adds support for the Firebird PDO Database Driver in Laravel applic ## Version Support -- **PHP:** 7.4, 8.0, 8.1, 8.2 -- **Laravel:** 8.x, 9.x, 10.x +- **PHP:** 7.4, 8.0, 8.1, 8.2, 8.3 +- **Laravel:** 8.x, 9.x, 10.x, 11.x - **Firebird:** 2.5, 3.0, 4.0 ## Installation diff --git a/src/FirebirdConnection.php b/src/FirebirdConnection.php index 519034c..e9ad826 100755 --- a/src/FirebirdConnection.php +++ b/src/FirebirdConnection.php @@ -18,7 +18,7 @@ class FirebirdConnection extends DatabaseConnection */ protected function getDefaultQueryGrammar() { - return new FirebirdQueryGrammar; + return new FirebirdQueryGrammar($this); } /** @@ -52,7 +52,7 @@ public function getSchemaBuilder() */ protected function getDefaultSchemaGrammar() { - return $this->withTablePrefix(new FirebirdSchemaGrammar); + return $this->withTablePrefix(new FirebirdSchemaGrammar($this)); } /** diff --git a/src/Schema/Grammars/FirebirdGrammar.php b/src/Schema/Grammars/FirebirdGrammar.php index 5eed43a..2d871a7 100755 --- a/src/Schema/Grammars/FirebirdGrammar.php +++ b/src/Schema/Grammars/FirebirdGrammar.php @@ -22,6 +22,20 @@ class FirebirdGrammar extends Grammar */ protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger']; + /** + * Compile the query to determine the tables. + * + * @return string + */ + public function compileTables() + { + return 'select trim(trailing from rdb$relation_name) as "name" ' + .'from rdb$relations ' + .'where rdb$relation_type = 0 ' + .'and (rdb$system_flag is null or rdb$system_flag = 0) ' + .'order by rdb$relation_name'; + } + /** * Compile the query to determine if a table exists. * @@ -32,6 +46,34 @@ public function compileTableExists() return 'select rdb$relation_name from rdb$relations where rdb$relation_name = ?'; } + /** + * Compile the query to determine the views. + * + * @return string + */ + public function compileViews() + { + return 'select trim(trailing from rdb$relation_name) as "name", ' + .'rdb$view_source as "definition" ' + .'from rdb$relations ' + .'where rdb$view_blr is not null ' + .'and (rdb$system_flag is null or rdb$system_flag = 0)'; + } + + /** + * Compile the query to determine the columns. + * + * @param string $table + * @return string + */ + public function compileColumns($table) + { + return 'select trim(trailing from rdb$field_name) as "name" ' + .'from rdb$relation_fields ' + .'where rdb$relation_name = '.$this->quoteString($table).' ' + .'order by rdb$relation_name'; + } + /** * Compile the query to determine the list of columns. * diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 5526ceb..012e93d 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -54,9 +54,9 @@ public function it_can_select() $this->assertCount(3, (array) $result); - $this->assertObjectHasAttribute('name', $result); - $this->assertObjectHasAttribute('city', $result); - $this->assertObjectHasAttribute('country', $result); + $this->assertObjectHasProperty('name', $result); + $this->assertObjectHasProperty('city', $result); + $this->assertObjectHasProperty('country', $result); $this->assertEquals('Anna', $result->name); $this->assertEquals('Sydney', $result->city); @@ -82,9 +82,9 @@ public function it_can_select_with_aliases() $this->assertCount(3, (array) $result); - $this->assertObjectHasAttribute('USER_NAME', $result); - $this->assertObjectHasAttribute('user_city', $result); - $this->assertObjectHasAttribute('User_Country', $result); + $this->assertObjectHasProperty('USER_NAME', $result); + $this->assertObjectHasProperty('user_city', $result); + $this->assertObjectHasProperty('User_Country', $result); $this->assertEquals('Anna', $result->USER_NAME); $this->assertEquals('Sydney', $result->user_city); @@ -1050,11 +1050,11 @@ public function it_can_add_inner_join() ->get(); $this->assertCount(10, $results); - $this->assertObjectHasAttribute('name', $results->first()); - $this->assertObjectHasAttribute('email', $results->first()); - $this->assertObjectHasAttribute('state', $results->first()); - $this->assertObjectHasAttribute('price', $results->first()); - $this->assertObjectHasAttribute('quantity', $results->first()); + $this->assertObjectHasProperty('name', $results->first()); + $this->assertObjectHasProperty('email', $results->first()); + $this->assertObjectHasProperty('state', $results->first()); + $this->assertObjectHasProperty('price', $results->first()); + $this->assertObjectHasProperty('quantity', $results->first()); } /** @test */ @@ -1073,11 +1073,11 @@ public function it_can_add_inner_join_where() $this->assertCount(2, $results); $this->assertEquals(100, $results->first()->price); - $this->assertObjectHasAttribute('name', $results->first()); - $this->assertObjectHasAttribute('email', $results->first()); - $this->assertObjectHasAttribute('state', $results->first()); - $this->assertObjectHasAttribute('price', $results->first()); - $this->assertObjectHasAttribute('quantity', $results->first()); + $this->assertObjectHasProperty('name', $results->first()); + $this->assertObjectHasProperty('email', $results->first()); + $this->assertObjectHasProperty('state', $results->first()); + $this->assertObjectHasProperty('price', $results->first()); + $this->assertObjectHasProperty('quantity', $results->first()); } /** @test */ diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 4d9c92b..47d2634 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -25,6 +25,20 @@ public function it_has_column() $this->assertFalse(Schema::hasColumn('users', 'foo')); } + /** @test */ + public function it_has_view(): void + { + if (version_compare($this->app->version(), '10.34.0', '<')) { + $this->markTestSkipped('The hasView method is only available in Laravel 10.34.0 and above.'); + } + + $this->createViews(); + + $this->assertTrue(Schema::hasView('view_all_users')); + + $this->assertFalse(Schema::hasView(uniqid('view_'))); + } + /** @test */ public function it_has_columns() { diff --git a/tests/Support/MigrateDatabase.php b/tests/Support/MigrateDatabase.php index 43f5fe7..872ad1a 100644 --- a/tests/Support/MigrateDatabase.php +++ b/tests/Support/MigrateDatabase.php @@ -15,6 +15,8 @@ public function setUp(): void parent::setUp(); if (! MigrationState::$migrated) { + $this->dropViews(); + $this->dropTables(); $this->createTables(); @@ -100,4 +102,23 @@ public function dropProcedure() } } } + + public function createViews(): void + { + DB::select('CREATE VIEW "view_all_users" AS SELECT * FROM "users"'); + } + + public function dropViews(): void + { + try { + DB::select('DROP VIEW "view_all_users"'); + } catch (QueryException $e) { + // Suppress the "view does not exist" exception, as we want to + // replicate dropIfExists() functionality without using the Schema + // class. + if (! Str::contains($e->getMessage(), 'does not exist')) { + throw $e; + } + } + } }