Skip to content

Commit

Permalink
refactor: improve migration and model names
Browse files Browse the repository at this point in the history
  • Loading branch information
WatheqAlshowaiter committed Jul 14, 2024
1 parent 6338ecb commit f47588a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
public function up(): void
{
Schema::create('parent_test_models', function (Blueprint $table) {
Schema::create('fathers', function (Blueprint $table) {
$table->id(); // primary key -> ignored
$table->boolean('active')->default(false); // default => ignored
$table->string('name'); // required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
public function up(): void
{
Schema::create('another_parent_test_models', function (Blueprint $table) {
Schema::create('mothers', function (Blueprint $table) {
$table->ulid('id')->primary(); // primary key => ignored
$table->enum('types', ['one', 'two'])->default('one'); // default => ignored
$table->uuid('uuid'); // required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
{
public function up(): void
{
Schema::create('child_test_models', function (Blueprint $table) {
Schema::create('sons', function (Blueprint $table) {
$table->uuid('id')->primary(); // primary key => ignored
$table->foreignId('parent_id')->constrained(); // required
$table->foreignUlid('another_parent_id')->nullable()->constrained(); // nullable => ignored
$table->foreignUlid('mother_id')->nullable()->constrained(); // nullable => ignored
$table->foreignId('father_id')->nullable()->constrained(); // nullable => ignored
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/ChildTestModel.php → src/Models/Father.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use WatheqAlshowaiter\ModelRequiredFields\RequiredFields;

class ChildTestModel extends Model
class Father extends Model
{
use RequiredFields;
}
2 changes: 1 addition & 1 deletion src/Models/ParentTestModel.php → src/Models/Mother.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use WatheqAlshowaiter\ModelRequiredFields\RequiredFields;

class ParentTestModel extends Model
class Mother extends Model
{
use RequiredFields;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use WatheqAlshowaiter\ModelRequiredFields\RequiredFields;

class AnotherParentTestModel extends Model
class Son extends Model
{
use RequiredFields;
}
14 changes: 7 additions & 7 deletions tests/RequiredFieldsTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Illuminate\Foundation\Testing\RefreshDatabase;
use WatheqAlshowaiter\ModelRequiredFields\Models\AnotherParentTestModel;
use WatheqAlshowaiter\ModelRequiredFields\Models\ChildTestModel;
use WatheqAlshowaiter\ModelRequiredFields\Models\ParentTestModel;
use WatheqAlshowaiter\ModelRequiredFields\Models\Father;
use WatheqAlshowaiter\ModelRequiredFields\Models\Mother;
use WatheqAlshowaiter\ModelRequiredFields\Models\Son;
use WatheqAlshowaiter\ModelRequiredFields\Tests\TestCase;

class RequiredFieldsTest extends TestCase
Expand All @@ -15,26 +15,26 @@ public function test_get_required_fields_for_parent_model()
$this->assertEquals([
'name',
'email',
], ParentTestModel::getRequiredFields());
], Father::getRequiredFields());

$this->assertNotEquals([
'email',
'name',
], ParentTestModel::getRequiredFields());
], Father::getRequiredFields());
}

public function test_get_required_fields_for_another_parent_model()
{
$this->assertEquals([
'uuid',
'ulid',
], AnotherParentTestModel::getRequiredFields());
], Mother::getRequiredFields());
}

public function test_get_required_fields_for_child_model()
{
$this->assertEquals([
'parent_id',
], ChildTestModel::getRequiredFields());
], Son::getRequiredFields());
}
}

0 comments on commit f47588a

Please sign in to comment.