Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Extract beberapa method di model factory ke trait #65

Merged
merged 1 commit into from
Oct 14, 2023

Conversation

feryardiant
Copy link
Contributor

Tujuan utama adanya model factory adalah untuk mempermudah kita untuk meng-generate data yang dibutuhkan untuk tiap model pada saat melakukan pengujian.

Namun dikarenakan factory class yang ada di package ini tidak disertakan dalam distribusi (saat package ini di install di app), perlu ada cara bagi developer untuk dapat tetap fitur yang perlu ada tanpa perlu menulis ulang.

Contoh untuk UserFactory, by default installasi laravel sudah memiliki class Database\Factories\UserFactory didalam folder database/factories maka developer cukup menggunakan trait WithIdentity untuk dapat meng-generate user beserta identity yang dibutuhkan

namespace Database\Factories;

use Creasi\Base\Models\Concerns\Factories\WithIdentity;
use Illuminate\Database\Eloquent\Factories\Factory;

class UserFactory extends Factory
{
    use WithIdentity;

    ...
}

// Sample
App\Models\User::factory()->withIdentity();

Agar bisa meng-generate User beserta Identity (Profile) yang dibutuhkan

Simply to make it easier to customize factory classes in app-level

Signed-off-by: Fery Wardiyanto <[email protected]>
@feryardiant feryardiant added the backlog Potential item under consideration for a product label Oct 14, 2023
@feryardiant feryardiant self-assigned this Oct 14, 2023
@feryardiant feryardiant requested a review from a team as a code owner October 14, 2023 18:22
@feryardiant feryardiant added the enhancement New feature or request label Oct 14, 2023
@feryardiant feryardiant merged commit cb60cc5 into main Oct 14, 2023
7 checks passed
@feryardiant feryardiant deleted the refactor-model-factory branch October 14, 2023 18:45
@feryardiant
Copy link
Contributor Author

Bodohnya saya langsung tak merge dan jelas akan error di app, 🤦🏻‍♂️

Screenshot 2023-10-15 at 01 58 03

Kenapa? karena method withIdentity manggil PersonnelFactory yang gak include. Saya cuma kepikiran 2 opsi :

  • Load Database\Factories dari package ini; atau
  • Publish file database/factories

Ada 1 lagi sih sebenernya, tp akan ngubah cukup banyak file dan saya males.

feryardiant added a commit that referenced this pull request Oct 14, 2023
feryardiant added a commit that referenced this pull request Oct 14, 2023
milih opsi ke 3, F!

revert 5e77247, fix #65 (hopefuly) 🤞

Signed-off-by: Fery Wardiyanto <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backlog Potential item under consideration for a product enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

1 participant