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

@@ -58,13 +58,12 @@ class ConcertTest extends TestCase
/** @test */
function can_order_concert_tickets()
{
$concert = factory(Concert::class)->create();
$concert->addTickets(3);
$concert = factory(Concert::class)->create()->addTickets(3);
$order = $concert->orderTickets('jane@example.com', 3);
$this->assertEquals('jane@example.com', $order->email);
$this->assertEquals(3, $order->tickets()->count());
$this->assertEquals(3, $order->ticketQuantity());
}
/** @test */
@@ -80,8 +79,7 @@ class ConcertTest extends TestCase
/** @test */
function tickets_remaining_does_not_include_tickets_associated_with_an_order()
{
$concert = factory(Concert::class)->create();
$concert->addTickets(50);
$concert = factory(Concert::class)->create()->addTickets(50);
$concert->orderTickets('jane@example.com', 30);
$this->assertEquals(20, $concert->ticketsRemaining());
@@ -90,14 +88,12 @@ class ConcertTest extends TestCase
/** @test */
function trying_to_purchase_more_tickets_than_remain_throws_an_exception()
{
$concert = factory(Concert::class)->create();
$concert->addTickets(10);
$concert = factory(Concert::class)->create()->addTickets(10);
try {
$concert->orderTickets('jane@example.com', 11);
} catch (NotEnoughTicketsException $e) {
$order = $concert->orders()->where('email', 'jane@example.com')->first();
$this->assertNull($order);
$this->assertFalse($concert->hasOrderFor('jane@example.com'));
$this->assertEquals(10, $concert->ticketsRemaining());
return;
}
@@ -108,15 +104,13 @@ class ConcertTest extends TestCase
/** @test */
function cannot_order_tickets_that_have_already_been_purchased()
{
$concert = factory(Concert::class)->create();
$concert->addTickets(10);
$concert = factory(Concert::class)->create()->addTickets(10);
$concert->orderTickets('jane@example.com', 8);
try {
$concert->orderTickets('john@example.com', 3);
} catch (NotEnoughTicketsException $e) {
$johnsOrder = $concert->orders()->where('email', 'john@example.com')->first();
$this->assertNull($johnsOrder);
$this->assertFalse($concert->hasOrderFor('john@example.com'));
$this->assertEquals(2, $concert->ticketsRemaining());
return;
}