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

Commit

Permalink
test(model): dan sepertinya dari 2 opsi saya diharuskan untuk
Browse files Browse the repository at this point in the history
milih opsi ke 3, F!

revert 5e77247, fix #65 (hopefuly) 🤞

Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Oct 14, 2023
1 parent 5e77247 commit 0e9c211
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 13 deletions.
3 changes: 0 additions & 3 deletions database/.gitattributes

This file was deleted.

1 change: 1 addition & 0 deletions database/migrations/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*_testbench_*.php export-ignore
5 changes: 5 additions & 0 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [
Expand Down
3 changes: 1 addition & 2 deletions src/Models/Concerns/Factories/WithIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/Models/Factories/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UserFactory.php export-ignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace Creasi\Base\Models\Factories;

use Creasi\Base\Models\Address;
use Creasi\Base\Models\Enums\AddressType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace Creasi\Base\Models\Factories;

use Creasi\Base\Models\Business;
use Creasi\Base\Models\Concerns\Factories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace Creasi\Base\Models\Factories;

use Creasi\Base\Models\FileUpload;
use Illuminate\Database\Eloquent\Factories\Factory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace Creasi\Base\Models\Factories;

use Creasi\Base\Models\Concerns\Factories;
use Creasi\Base\Models\Enums\Gender;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace Creasi\Base\Models\Factories;

use Creasi\Base\Models\Enums;
use Creasi\Base\Models\Profile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace Creasi\Base\Models\Factories;

use Creasi\Base\Models\Concerns\Factories\WithIdentity;
use Illuminate\Database\Eloquent\Factories\Factory;
Expand Down
8 changes: 8 additions & 0 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ abstract class Model extends EloquentModel
{
use HasFactory;
use SoftDeletes;

protected static function newFactory()
{
$modelName = \class_basename(static::class);
$factory = __NAMESPACE__."\\Factories\\{$modelName}Factory";

return $factory::new();
}
}
6 changes: 6 additions & 0 deletions tests/Fixtures/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Creasi\Base\Contracts\HasIdentity;
use Creasi\Base\Models\Concerns\WithIdentity;
use Creasi\Base\Models\Factories\UserFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand All @@ -27,6 +28,11 @@ class User extends Authenticatable implements HasIdentity
use Notifiable;
use WithIdentity;

protected static function newFactory()
{
return UserFactory::new();
}

public function password(): Attribute
{
return Attribute::set(fn (string $value) => \bcrypt($value));
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 0e9c211

Please sign in to comment.