diff --git a/tests/Integration/Database/EloquentFactoryBuilderTest.php b/tests/Integration/Database/EloquentFactoryBuilderTest.php index d2dcbee3040e..23dc1bf2520d 100644 --- a/tests/Integration/Database/EloquentFactoryBuilderTest.php +++ b/tests/Integration/Database/EloquentFactoryBuilderTest.php @@ -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, @@ -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) { @@ -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() { @@ -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