Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Add alias for calling with single state #24937

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Eloquent/FactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
20 changes: 10 additions & 10 deletions tests/Integration/Database/EloquentFactoryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
});

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down