1.8 - Factory States

This commit is contained in:
Adam Wathan
2016-11-03 15:05:59 -04:00
parent 12e18f3728
commit a3d6a1efcd
2 changed files with 14 additions and 5 deletions

View File

@@ -39,3 +39,15 @@ $factory->define(App\Concert::class, function (Faker\Generator $faker) {
'additional_information' => 'Some sample additional information.',
];
});
$factory->state(App\Concert::class, 'published', function ($faker) {
return [
'published_at' => Carbon::parse('-1 week'),
];
});
$factory->state(App\Concert::class, 'unpublished', function ($faker) {
return [
'published_at' => null,
];
});

View File

@@ -13,7 +13,7 @@ class ViewConcertListingTest extends TestCase
/** @test */
function user_can_view_a_published_concert_listing()
{
$concert = Concert::create([
$concert = factory(Concert::class)->states('published')->create([
'title' => 'The Red Chord',
'subtitle' => 'with Animosity and Lethargy',
'date' => Carbon::parse('December 13, 2016 8:00pm'),
@@ -24,7 +24,6 @@ class ViewConcertListingTest extends TestCase
'state' => 'ON',
'zip' => '17916',
'additional_information' => 'For tickets, call (555) 555-5555.',
'published_at' => Carbon::parse('-1 week'),
]);
$this->visit('/concerts/'.$concert->id);
@@ -43,9 +42,7 @@ class ViewConcertListingTest extends TestCase
/** @test */
function user_cannot_view_unpublished_concert_listings()
{
$concert = factory(Concert::class)->create([
'published_at' => null,
]);
$concert = factory(Concert::class)->states('unpublished')->create();
$this->get('/concerts/'.$concert->id);