From 8aed29ae10df2203dc10e91ae3e4659e6efbf623 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Thu, 17 Oct 2024 22:35:22 +0200 Subject: [PATCH 1/6] Add WordPressBuilderTest --- .../Orm/Schemas/WordPressBuilderTest.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/WordPress/Orm/Schemas/WordPressBuilderTest.php diff --git a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php new file mode 100644 index 00000000..1fefe3f5 --- /dev/null +++ b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php @@ -0,0 +1,82 @@ + + */ + +namespace Dbout\WpOrm\Tests\WordPress\Orm\Schemas; + +use Dbout\WpOrm\Orm\Database; +use Dbout\WpOrm\Orm\Schemas\WordPressBuilder; +use Dbout\WpOrm\Tests\WordPress\TestCase; +use Illuminate\Database\Schema\Blueprint; + +class WordPressBuilderTest extends TestCase +{ + private Database $database; + private WordPressBuilder $schema; + + /** + * @return void + */ + public function setUp(): void + { + $this->database = Database::getInstance(); + + /** @var WordPressBuilder $schema */ + $schema = $this->database->getSchemaBuilder(); + $this->schema = $schema; + + $this->schema->create('project', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->integer('author'); + $table->string('address'); + }); + } + + /** + * @return void + * @covers WordPressBuilder::create + * @covers WordPressBuilder::hasTable + * @covers WordPressBuilder::getColumns + * @covers WordPressBuilder::hasColumn + */ + public function testCreate(): void + { + $this->schema->create('architect', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->string('slug'); + $table->json('data')->nullable(); + }); + + $this->assertTrue($this->schema->hasTable('architect')); + $columns = $this->schema->getColumns('architect'); + $table = $this->database->getTablePrefix() . 'architect'; + $this->assertCount(4, $columns); + $this->assertTrue($this->schema->hasColumn($table, 'id')); + $this->assertTrue($this->schema->hasColumn($table, 'name')); + $this->assertTrue($this->schema->hasColumn($table, 'slug')); + $this->assertTrue($this->schema->hasColumn($table, 'data')); + } + + /** + * @return void + * @covers WordPressBuilder::table + * @covers WordPressBuilder::hasTable + */ + public function testUpdate(): void + { + $this->schema->table('project', function (Blueprint $table) { + $table->string('country'); + $table->boolean('finish'); + }); + + $table = $this->database->getTablePrefix() . 'project'; + $this->assertTrue($this->schema->hasColumn($table, 'country')); + $this->assertTrue($this->schema->hasColumn($table, 'finish')); + } +} From cb6dabeaa6b7bcf6fd9e7c9585f38fa4fff894ba Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Thu, 17 Oct 2024 22:39:11 +0200 Subject: [PATCH 2/6] Update WordPressBuilderTest --- .../Orm/Schemas/WordPressBuilderTest.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php index 1fefe3f5..201040e7 100644 --- a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php +++ b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php @@ -18,6 +18,19 @@ class WordPressBuilderTest extends TestCase private Database $database; private WordPressBuilder $schema; + /** + * @return void + */ + public function setUpBeforeClass(): void + { + Database::getInstance()->getSchemaBuilder()->create('project', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->integer('author'); + $table->string('address'); + }); + } + /** * @return void */ @@ -28,13 +41,6 @@ public function setUp(): void /** @var WordPressBuilder $schema */ $schema = $this->database->getSchemaBuilder(); $this->schema = $schema; - - $this->schema->create('project', function (Blueprint $table) { - $table->id(); - $table->string('name'); - $table->integer('author'); - $table->string('address'); - }); } /** From 404efb4308bbb14b4701cacc1edf5e2ad5537dad Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Thu, 17 Oct 2024 22:46:40 +0200 Subject: [PATCH 3/6] Update WordPressBuilderTest --- tests/WordPress/Orm/Schemas/WordPressBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php index 201040e7..389a35d4 100644 --- a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php +++ b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php @@ -21,7 +21,7 @@ class WordPressBuilderTest extends TestCase /** * @return void */ - public function setUpBeforeClass(): void + public static function setUpBeforeClass(): void { Database::getInstance()->getSchemaBuilder()->create('project', function (Blueprint $table) { $table->id(); From 83d9b3fd2153b06e2c2f974a127eea4be1be74ac Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Thu, 17 Oct 2024 22:50:20 +0200 Subject: [PATCH 4/6] Update WordPressBuilderTest --- tests/WordPress/Orm/Schemas/WordPressBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php index 389a35d4..27d40ad4 100644 --- a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php +++ b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php @@ -60,8 +60,8 @@ public function testCreate(): void }); $this->assertTrue($this->schema->hasTable('architect')); - $columns = $this->schema->getColumns('architect'); $table = $this->database->getTablePrefix() . 'architect'; + $columns = $this->schema->getColumns($table); $this->assertCount(4, $columns); $this->assertTrue($this->schema->hasColumn($table, 'id')); $this->assertTrue($this->schema->hasColumn($table, 'name')); From 71dc493d501bc5f126c67d8df10821ceae41a082 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sat, 19 Oct 2024 17:25:25 +0200 Subject: [PATCH 5/6] Update WordPressBuilderTest --- .../Orm/Schemas/WordPressBuilderTest.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php index 27d40ad4..306b214c 100644 --- a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php +++ b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php @@ -85,4 +85,47 @@ public function testUpdate(): void $this->assertTrue($this->schema->hasColumn($table, 'country')); $this->assertTrue($this->schema->hasColumn($table, 'finish')); } + + /** + * @return void + * @covers WordPressBuilder::drop + */ + public function testDrop(): void + { + $this->schema->create('company', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->string('slug'); + }); + + $this->assertTrue($this->schema->hasTable('company')); + $this->schema->drop('company'); + $this->assertFalse($this->schema->hasTable('company')); + } + + /** + * @return void + * @covers WordPressBuilder::dropColumns + */ + public function testDropColumn(): void + { + $this->schema->create('address', function (Blueprint $table) { + $table->id(); + $table->string('firstname'); + $table->string('lastname'); + $table->string('street_1'); + $table->string('street_2'); + $table->string('street_3'); + }); + + $table = $this->database->getTablePrefix() . 'address'; + $columns = $this->schema->getColumns($table); + $this->assertCount(5, $columns); + + $this->schema->dropColumns('address', ['street_3']); + $columns = $this->schema->getColumns($table); + $this->assertCount(4, $columns); + $this->assertFalse($this->schema->hasColumn($table, 'street_3')); + + } } From ed152fd76e235f0ae9cdf29cdb708b08badd170e Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sat, 19 Oct 2024 17:26:53 +0200 Subject: [PATCH 6/6] Update WordPressBuilderTest --- tests/WordPress/Orm/Schemas/WordPressBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php index 306b214c..20fb9bdd 100644 --- a/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php +++ b/tests/WordPress/Orm/Schemas/WordPressBuilderTest.php @@ -120,11 +120,11 @@ public function testDropColumn(): void $table = $this->database->getTablePrefix() . 'address'; $columns = $this->schema->getColumns($table); - $this->assertCount(5, $columns); + $this->assertCount(6, $columns); $this->schema->dropColumns('address', ['street_3']); $columns = $this->schema->getColumns($table); - $this->assertCount(4, $columns); + $this->assertCount(5, $columns); $this->assertFalse($this->schema->hasColumn($table, 'street_3')); }