Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Olsen committed Mar 19, 2018
1 parent 0526452 commit 41dbc74
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Integration/Database/EloquentFactoryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ protected function getEnvironmentSetUp($app)
$user->setRelation('profile', $profile);
});

$factory->afterMakingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) {
$server = factory(FactoryBuildableServer::class)
->states('callable')
->make(['user_id' => $user->id]);

$user->servers->push($server);
});

$factory->define(FactoryBuildableTeam::class, function (Generator $faker) {
return [
'name' => $faker->name,
Expand Down Expand Up @@ -81,6 +89,12 @@ protected function getEnvironmentSetUp($app)
];
});

$factory->afterCreatingState(FactoryBuildableUser::class, 'with_callable_server', function(FactoryBuildableUser $user, Generator $faker){
$server = factory(FactoryBuildableServer::class)
->states('callable')
->create(['user_id' => $user->id]);
});

$factory->state(FactoryBuildableServer::class, 'inline', ['status' => 'inline']);

$app->singleton(Factory::class, function ($app) use ($factory) {
Expand Down Expand Up @@ -234,6 +248,15 @@ public function creating_models_with_after_callback()
$this->assertTrue($team->users->contains($team->owner));
}

/** @test **/
public function creating_models_with_after_callback_states()
{
$user = factory(FactoryBuildableUser::class)->states('with_callable_server')->create();

$this->assertNotNull($user->profile);
$this->assertNotNull($user->servers->where('status', 'callable')->first());
}

/** @test */
public function making_models_with_a_custom_connection()
{
Expand All @@ -251,6 +274,15 @@ public function making_models_with_after_callback()

$this->assertNotNull($user->profile);
}

/** @test **/
public function making_models_with_after_callback_states()
{
$user = factory(FactoryBuildableUser::class)->states('with_callable_server')->make();

$this->assertNotNull($user->profile);
$this->assertNotNull($user->servers->where('status', 'callable')->first());
}
}

class FactoryBuildableUser extends Model
Expand Down

0 comments on commit 41dbc74

Please sign in to comment.