From 0e9c2119c7803c138298d0f8e754828952f94068 Mon Sep 17 00:00:00 2001 From: Fery Wardiyanto Date: Sun, 15 Oct 2023 03:02:49 +0700 Subject: [PATCH] test(model): dan sepertinya dari 2 opsi saya diharuskan untuk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit milih opsi ke 3, F! revert 5e77247, fix #65 (hopefuly) 🤞 Signed-off-by: Fery Wardiyanto --- database/.gitattributes | 3 --- database/migrations/.gitattributes | 1 + src/Models/Address.php | 5 +++++ src/Models/Concerns/Factories/WithIdentity.php | 3 +-- src/Models/Factories/.gitattributes | 1 + .../factories => src/Models/Factories}/AddressFactory.php | 2 +- .../Models/Factories}/BusinessFactory.php | 2 +- .../Models/Factories}/FileUploadFactory.php | 2 +- .../Models/Factories}/PersonnelFactory.php | 2 +- .../factories => src/Models/Factories}/ProfileFactory.php | 2 +- .../factories => src/Models/Factories}/UserFactory.php | 2 +- src/Models/Model.php | 8 ++++++++ tests/Fixtures/User.php | 6 ++++++ tests/TestCase.php | 3 +-- 14 files changed, 29 insertions(+), 13 deletions(-) delete mode 100644 database/.gitattributes create mode 100644 database/migrations/.gitattributes create mode 100644 src/Models/Factories/.gitattributes rename {database/factories => src/Models/Factories}/AddressFactory.php (97%) rename {database/factories => src/Models/Factories}/BusinessFactory.php (94%) rename {database/factories => src/Models/Factories}/FileUploadFactory.php (96%) rename {database/factories => src/Models/Factories}/PersonnelFactory.php (96%) rename {database/factories => src/Models/Factories}/ProfileFactory.php (96%) rename {database/factories => src/Models/Factories}/UserFactory.php (96%) diff --git a/database/.gitattributes b/database/.gitattributes deleted file mode 100644 index 85b6b06..0000000 --- a/database/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -# Exclude unused files -*_testbench_*.php export-ignore -UserFactory.php export-ignore diff --git a/database/migrations/.gitattributes b/database/migrations/.gitattributes new file mode 100644 index 0000000..050593c --- /dev/null +++ b/database/migrations/.gitattributes @@ -0,0 +1 @@ +*_testbench_*.php export-ignore diff --git a/src/Models/Address.php b/src/Models/Address.php index 49dea91..5ab7703 100644 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -31,6 +31,11 @@ class Address extends NusaAddress protected $casts = []; + protected static function newFactory() + { + return Factories\AddressFactory::new(); + } + public function getCasts() { return \array_merge(parent::getCasts(), [ diff --git a/src/Models/Concerns/Factories/WithIdentity.php b/src/Models/Concerns/Factories/WithIdentity.php index 2ee1798..759b91c 100644 --- a/src/Models/Concerns/Factories/WithIdentity.php +++ b/src/Models/Concerns/Factories/WithIdentity.php @@ -3,7 +3,6 @@ namespace Creasi\Base\Models\Concerns\Factories; use Creasi\Base\Models\Personnel; -use Database\Factories\PersonnelFactory; /** * @mixin \Illuminate\Database\Eloquent\Factories\Factory @@ -13,7 +12,7 @@ trait WithIdentity public function withIdentity(\Closure $cb = null): static { if ($cb === null) { - $cb = fn (PersonnelFactory $identity) => $identity->withProfile(); + $cb = fn ($identity) => $identity->withProfile(); } return $this->has($cb(Personnel::factory()), 'identity'); diff --git a/src/Models/Factories/.gitattributes b/src/Models/Factories/.gitattributes new file mode 100644 index 0000000..ddf0e90 --- /dev/null +++ b/src/Models/Factories/.gitattributes @@ -0,0 +1 @@ +UserFactory.php export-ignore diff --git a/database/factories/AddressFactory.php b/src/Models/Factories/AddressFactory.php similarity index 97% rename from database/factories/AddressFactory.php rename to src/Models/Factories/AddressFactory.php index a71f151..be60c26 100644 --- a/database/factories/AddressFactory.php +++ b/src/Models/Factories/AddressFactory.php @@ -1,6 +1,6 @@ \bcrypt($value)); diff --git a/tests/TestCase.php b/tests/TestCase.php index 9cd1c01..2181dcc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,7 +6,6 @@ use Creasi\Base\ServiceProvider; use Creasi\Nusa\ServiceProvider as NusaServiceProvider; use Creasi\Tests\Fixtures\User; -use Database\Factories\PersonnelFactory; use Illuminate\Contracts\Config\Repository; use Illuminate\Foundation\Testing\RefreshDatabase; use Laravel\Sanctum\SanctumServiceProvider; @@ -34,7 +33,7 @@ final protected function user(array|Closure $attrs = []): User { if (! $this->currentUser?->exists) { $this->currentUser = User::factory() - ->withIdentity(fn (PersonnelFactory $p) => $p->withProfile()->withCompany(true)) + ->withIdentity(fn ($p) => $p->withProfile()->withCompany(true)) ->createOne($attrs); }