diff --git a/src/Illuminate/Database/Eloquent/FactoryBuilder.php b/src/Illuminate/Database/Eloquent/FactoryBuilder.php index 3005cb688d6b..150f2ef312ba 100644 --- a/src/Illuminate/Database/Eloquent/FactoryBuilder.php +++ b/src/Illuminate/Database/Eloquent/FactoryBuilder.php @@ -117,6 +117,17 @@ public function times($amount) return $this; } + /** + * Set the state to be applied to the model. + * + * @param string $state + * @return $this + */ + public function state($state) + { + return $this->states([$state]); + } + /** * Set the states to be applied to the model. * diff --git a/tests/Integration/Database/EloquentFactoryBuilderTest.php b/tests/Integration/Database/EloquentFactoryBuilderTest.php index 611f69324d6e..3646afcb217f 100644 --- a/tests/Integration/Database/EloquentFactoryBuilderTest.php +++ b/tests/Integration/Database/EloquentFactoryBuilderTest.php @@ -53,7 +53,7 @@ protected function getEnvironmentSetUp($app) $factory->afterMakingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) { $server = factory(FactoryBuildableServer::class) - ->states('callable') + ->state('callable') ->make(['user_id' => $user->id]); $user->servers->push($server); @@ -91,7 +91,7 @@ protected function getEnvironmentSetUp($app) $factory->afterCreatingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) { $server = factory(FactoryBuildableServer::class) - ->states('callable') + ->state('callable') ->create(['user_id' => $user->id]); }); @@ -186,11 +186,11 @@ public function creating_collection_of_models() /** * @test */ - public function creating_models_with_callable_states() + public function creating_models_with_callable_state() { $server = factory(FactoryBuildableServer::class)->create(); - $callableServer = factory(FactoryBuildableServer::class)->states('callable')->create(); + $callableServer = factory(FactoryBuildableServer::class)->state('callable')->create(); $this->assertEquals('active', $server->status); $this->assertEquals(['Storage', 'Data'], $server->tags); @@ -200,11 +200,11 @@ public function creating_models_with_callable_states() /** * @test */ - public function creating_models_with_inline_states() + public function creating_models_with_inline_state() { $server = factory(FactoryBuildableServer::class)->create(); - $inlineServer = factory(FactoryBuildableServer::class)->states('inline')->create(); + $inlineServer = factory(FactoryBuildableServer::class)->state('inline')->create(); $this->assertEquals('active', $server->status); $this->assertEquals('inline', $inlineServer->status); @@ -249,9 +249,9 @@ public function creating_models_with_after_callback() } /** @test **/ - public function creating_models_with_after_callback_states() + public function creating_models_with_after_callback_state() { - $user = factory(FactoryBuildableUser::class)->states('with_callable_server')->create(); + $user = factory(FactoryBuildableUser::class)->state('with_callable_server')->create(); $this->assertNotNull($user->profile); $this->assertNotNull($user->servers->where('status', 'callable')->first()); @@ -276,9 +276,9 @@ public function making_models_with_after_callback() } /** @test **/ - public function making_models_with_after_callback_states() + public function making_models_with_after_callback_state() { - $user = factory(FactoryBuildableUser::class)->states('with_callable_server')->make(); + $user = factory(FactoryBuildableUser::class)->state('with_callable_server')->make(); $this->assertNotNull($user->profile); $this->assertNotNull($user->servers->where('status', 'callable')->first());