Skip to content

Commit c8682e1

Browse files
dwightwatsontaylorotwell
authored andcommitted
Add alias for calling with single state (#24937)
1 parent eddbd6e commit c8682e1

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/Illuminate/Database/Eloquent/FactoryBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ public function times($amount)
117117
return $this;
118118
}
119119

120+
/**
121+
* Set the state to be applied to the model.
122+
*
123+
* @param string $state
124+
* @return $this
125+
*/
126+
public function state($state)
127+
{
128+
return $this->states([$state]);
129+
}
130+
120131
/**
121132
* Set the states to be applied to the model.
122133
*

tests/Integration/Database/EloquentFactoryBuilderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function getEnvironmentSetUp($app)
5353

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

5959
$user->servers->push($server);
@@ -91,7 +91,7 @@ protected function getEnvironmentSetUp($app)
9191

9292
$factory->afterCreatingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) {
9393
$server = factory(FactoryBuildableServer::class)
94-
->states('callable')
94+
->state('callable')
9595
->create(['user_id' => $user->id]);
9696
});
9797

@@ -186,11 +186,11 @@ public function creating_collection_of_models()
186186
/**
187187
* @test
188188
*/
189-
public function creating_models_with_callable_states()
189+
public function creating_models_with_callable_state()
190190
{
191191
$server = factory(FactoryBuildableServer::class)->create();
192192

193-
$callableServer = factory(FactoryBuildableServer::class)->states('callable')->create();
193+
$callableServer = factory(FactoryBuildableServer::class)->state('callable')->create();
194194

195195
$this->assertEquals('active', $server->status);
196196
$this->assertEquals(['Storage', 'Data'], $server->tags);
@@ -200,11 +200,11 @@ public function creating_models_with_callable_states()
200200
/**
201201
* @test
202202
*/
203-
public function creating_models_with_inline_states()
203+
public function creating_models_with_inline_state()
204204
{
205205
$server = factory(FactoryBuildableServer::class)->create();
206206

207-
$inlineServer = factory(FactoryBuildableServer::class)->states('inline')->create();
207+
$inlineServer = factory(FactoryBuildableServer::class)->state('inline')->create();
208208

209209
$this->assertEquals('active', $server->status);
210210
$this->assertEquals('inline', $inlineServer->status);
@@ -249,9 +249,9 @@ public function creating_models_with_after_callback()
249249
}
250250

251251
/** @test **/
252-
public function creating_models_with_after_callback_states()
252+
public function creating_models_with_after_callback_state()
253253
{
254-
$user = factory(FactoryBuildableUser::class)->states('with_callable_server')->create();
254+
$user = factory(FactoryBuildableUser::class)->state('with_callable_server')->create();
255255

256256
$this->assertNotNull($user->profile);
257257
$this->assertNotNull($user->servers->where('status', 'callable')->first());
@@ -276,9 +276,9 @@ public function making_models_with_after_callback()
276276
}
277277

278278
/** @test **/
279-
public function making_models_with_after_callback_states()
279+
public function making_models_with_after_callback_state()
280280
{
281-
$user = factory(FactoryBuildableUser::class)->states('with_callable_server')->make();
281+
$user = factory(FactoryBuildableUser::class)->state('with_callable_server')->make();
282282

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

0 commit comments

Comments
 (0)