-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Enums\Gender; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class FamilyMember extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $casts = [ | ||
'sex' => Gender::class, | ||
]; | ||
|
||
public function dafac() | ||
{ | ||
return $this->belongsTo(Dafac::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Enums\Gender; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\FamilyMember> | ||
*/ | ||
class FamilyMemberFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'dafac_id' => DafacFactory::new(), | ||
'name' => fake()->name(), | ||
'relation_to_head' => fake()->word(), | ||
'age' => fake()->numberBetween(0, 100), | ||
'sex' => fake()->randomElement(Gender::cases()), | ||
'educational_attainment' => fake()->word(), | ||
'occupational_skills' => fake()->word(), | ||
'remarks' => fake()->word(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
database/migrations/2024_04_05_085134_create_family_members_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('family_members', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('dafac_id')->constrained(); | ||
$table->string('name'); | ||
$table->string('relation_to_head'); | ||
$table->unsignedInteger('age'); | ||
$table->string('sex'); | ||
$table->string('educational_attainment'); | ||
$table->string('occupational_skills'); | ||
$table->string('remarks'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('family_members'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Models; | ||
|
||
use App\Models\FamilyMember; | ||
use Database\Factories\FamilyMemberFactory; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Tests\TestCase; | ||
|
||
class FamilyMemberTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
/** | ||
* @dataProvider dafacAttributesProvider | ||
* @testdox $_dataName is not null | ||
*/ | ||
public function test_attribute_not_null($attribute) | ||
{ | ||
// arrange - create model | ||
$model = FamilyMemberFactory::new()->create(); | ||
// act - retrieve model | ||
$value = FamilyMember::find($model->getKey())->$attribute; | ||
// assert - attribute is not null | ||
$this->assertNotNull($value); | ||
} | ||
|
||
public static function dafacAttributesProvider() | ||
{ | ||
// * use $_dataName on @testdox to get key | ||
return [ | ||
'name of family member' => ['name'], | ||
'relation to family head' => ['relation_to_head'], | ||
'age' => ['age'], | ||
'sex' => ['sex'], | ||
'educational attainment' => ['educational_attainment'], | ||
'occupational skills' => ['occupational_skills'], | ||
'remarks' => ['remarks'], | ||
]; | ||
} | ||
} |