3.7 - Cleaning Up Our Tests

This commit is contained in:
Adam Wathan
2016-11-15 16:10:45 -05:00
parent 9fe42a1aaa
commit 8abc8b19c9
5 changed files with 34 additions and 33 deletions

View File

@@ -32,8 +32,7 @@ class PurchaseTicketsTest extends TestCase
/** @test */
function customer_can_purchase_tickets_to_a_published_concert()
{
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250]);
$concert->addTickets(3);
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250])->addTickets(3);
$this->orderTickets($concert, [
'email' => 'john@example.com',
@@ -43,16 +42,14 @@ class PurchaseTicketsTest extends TestCase
$this->assertResponseStatus(201);
$this->assertEquals(9750, $this->paymentGateway->totalCharges());
$order = $concert->orders()->where('email', 'john@example.com')->first();
$this->assertNotNull($order);
$this->assertEquals(3, $order->tickets()->count());
$this->assertTrue($concert->hasOrderFor('john@example.com'));
$this->assertEquals(3, $concert->ordersFor('john@example.com')->first()->ticketQuantity());
}
/** @test */
function cannot_purchase_tickets_to_an_unpublished_concert()
{
$concert = factory(Concert::class)->states('unpublished')->create();
$concert->addTickets(3);
$concert = factory(Concert::class)->states('unpublished')->create()->addTickets(3);
$this->orderTickets($concert, [
'email' => 'john@example.com',
@@ -61,15 +58,14 @@ class PurchaseTicketsTest extends TestCase
]);
$this->assertResponseStatus(404);
$this->assertEquals(0, $concert->orders()->count());
$this->assertFalse($concert->hasOrderFor('john@example.com'));
$this->assertEquals(0, $this->paymentGateway->totalCharges());
}
/** @test */
function an_order_is_not_created_if_payment_fails()
{
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250]);
$concert->addTickets(3);
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250])->addTickets(3);
$this->orderTickets($concert, [
'email' => 'john@example.com',
@@ -78,17 +74,13 @@ class PurchaseTicketsTest extends TestCase
]);
$this->assertResponseStatus(422);
$order = $concert->orders()->where('email', 'john@example.com')->first();
$this->assertNull($order);
$this->assertFalse($concert->hasOrderFor('john@example.com'));
}
/** @test */
function cannot_purchase_more_tickets_than_remain()
{
$this->disableExceptionHandling();
$concert = factory(Concert::class)->states('published')->create();
$concert->addTickets(50);
$concert = factory(Concert::class)->states('published')->create()->addTickets(50);
$this->orderTickets($concert, [
'email' => 'john@example.com',
@@ -97,8 +89,7 @@ class PurchaseTicketsTest extends TestCase
]);
$this->assertResponseStatus(422);
$order = $concert->orders()->where('email', 'john@example.com')->first();
$this->assertNull($order);
$this->assertFalse($concert->hasOrderFor('john@example.com'));
$this->assertEquals(0, $this->paymentGateway->totalCharges());
$this->assertEquals(50, $concert->ticketsRemaining());
}