Skip to content

Commit

Permalink
- Adding Laravel 9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dash8x committed May 29, 2024
1 parent 3a6c627 commit 242278f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 72 deletions.
43 changes: 0 additions & 43 deletions src/BuilderMacros.php

This file was deleted.

29 changes: 27 additions & 2 deletions src/SchemaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;

class SchemaServiceProvider extends ServiceProvider
{
Expand All @@ -19,12 +20,36 @@ protected function registerBuilderMacros()

Builder::macro('getColumnComment', function (string $table, string $column, bool $fail_on_missing = false) {
/** @var $this Builder */
return BuilderMacros::getColumnComment($this, $table, $column, $fail_on_missing);
$column_info = $this->getColumns($table);

foreach ($column_info as $col) {
if ($col['name'] == $column) {
return $col['comment'];
}
}

if ($fail_on_missing) {
throw new InvalidArgumentException(sprintf("No such column [%s] in the table [%s].", $column, $table));
}

return null;
});

Builder::macro('getTableComment', function (string $table, bool $fail_on_missing = false) {
/** @var $this Builder */
return BuilderMacros::getTableComment($this, $table, $fail_on_missing);
$table_info = $this->getTables();

foreach ($table_info as $info) {
if ($info['name'] == $table) {
return $info['comment'];
}
}

if ($fail_on_missing) {
throw new InvalidArgumentException(sprintf("No such table [%s] in the database [%s].", $table, $builder->getConnection()->getDatabaseName()));
}

return null;

});
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Feature/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Javaabu\Schema\Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Schema;
use Javaabu\Schema\Tests\TestCase;
use Javaabu\Schema\Tests\TestSupport\Enums\CityStatus;

Expand All @@ -13,6 +14,11 @@ class BlueprintTest extends TestCase
/** @test */
public function it_can_create_an_enum_column(): void
{
$this->assertDatabaseColumnHasComment('cities', 'status', 'enum:' . CityStatus::class);
$this->assertTrue(Schema::hasColumn('cities', 'status'));
$this->assertEquals('varchar', Schema::getColumnType('cities', 'status'));

if (! static::isLaravel9()) {
$this->assertDatabaseColumnHasComment('cities', 'status', 'enum:' . CityStatus::class);
}
}
}
26 changes: 0 additions & 26 deletions tests/Unit/BuilderMacrosTest.php

This file was deleted.

0 comments on commit 242278f

Please sign in to comment.