Skip to content

Commit

Permalink
Add test for user
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Sep 11, 2024
1 parent 3c11767 commit f0c8af8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

use Aerni\Factory\Factories\Concerns\CreatesEntry;
use Aerni\Factory\Factories\Concerns\CreatesTerm;
use Aerni\Factory\Factories\Concerns\CreatesUser;
use Aerni\Factory\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\CrossJoinSequence;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use ReflectionClass;
use Statamic\Contracts\Auth\User;
use Statamic\Contracts\Entries\Entry;
use Statamic\Contracts\Taxonomies\Term;
use Statamic\Facades\Collection as CollectionFacade;
use Statamic\Facades\Entry as EntryFacade;
use Statamic\Facades\Site;
use Statamic\Facades\Taxonomy as TaxonomyFacade;
use Statamic\Facades\Term as TermFacade;
use Statamic\Facades\User as UserFacade;
use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk;

class FactoryTest extends TestCase
Expand Down Expand Up @@ -137,6 +140,13 @@ public function test_term_can_be_created(): void
$this->assertNotNull(TermFacade::find($term->id()));
}

public function test_user_can_be_created(): void
{
$user = FactoryTestUserFactory::new()->create();
$this->assertInstanceOf(User::class, $user);
$this->assertNotNull(UserFacade::find($user->id()));
}

public function test_make_creates_unpersisted_model_instance()
{
$entry = FactoryTestEntryFactory::new()->makeOne();
Expand Down Expand Up @@ -436,3 +446,17 @@ public function definition(): array
];
}
}

class FactoryTestUserFactory extends Factory
{
use CreatesUser;

public function definition(): array
{
return [
'email' => $this->faker->unique()->safeEmail,
'password' => $this->faker->password,
'roles' => ['editor'],
];
}
}

0 comments on commit f0c8af8

Please sign in to comment.