mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
|
|
use App\Ticket;
|
|
use App\Concert;
|
|
use App\Reservation;
|
|
use App\Billing\FakePaymentGateway;
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
class ReservationTest extends TestCase
|
|
{
|
|
use DatabaseMigrations;
|
|
|
|
/** @test */
|
|
function calculating_the_total_cost()
|
|
{
|
|
$tickets = collect([
|
|
(object) ['price' => 1200],
|
|
(object) ['price' => 1200],
|
|
(object) ['price' => 1200],
|
|
]);
|
|
|
|
$reservation = new Reservation($tickets, 'john@example.com');
|
|
|
|
$this->assertEquals(3600, $reservation->totalCost());
|
|
}
|
|
|
|
/** @test */
|
|
function retrieving_the_reservations_tickets()
|
|
{
|
|
$tickets = collect([
|
|
(object) ['price' => 1200],
|
|
(object) ['price' => 1200],
|
|
(object) ['price' => 1200],
|
|
]);
|
|
|
|
$reservation = new Reservation($tickets, 'john@example.com');
|
|
|
|
$this->assertEquals($tickets, $reservation->tickets());
|
|
}
|
|
|
|
/** @test */
|
|
function retrieving_the_customers_email()
|
|
{
|
|
$reservation = new Reservation(collect(), 'john@example.com');
|
|
|
|
$this->assertEquals('john@example.com', $reservation->email());
|
|
}
|
|
|
|
/** @test */
|
|
function reserved_tickets_are_released_when_a_reservation_is_cancelled()
|
|
{
|
|
$tickets = collect([
|
|
Mockery::spy(Ticket::class),
|
|
Mockery::spy(Ticket::class),
|
|
Mockery::spy(Ticket::class),
|
|
]);
|
|
|
|
$reservation = new Reservation($tickets, 'john@example.com');
|
|
|
|
$reservation->cancel();
|
|
|
|
foreach ($tickets as $ticket) {
|
|
$ticket->shouldHaveReceived('release');
|
|
}
|
|
}
|
|
|
|
/** @test */
|
|
function completing_a_reservation()
|
|
{
|
|
$concert = factory(Concert::class)->create(['ticket_price' => 1200]);
|
|
$tickets = factory(Ticket::class, 3)->create(['concert_id' => $concert->id]);
|
|
$reservation = new Reservation($tickets, 'john@example.com');
|
|
$paymentGateway = new FakePaymentGateway;
|
|
|
|
$order = $reservation->complete($paymentGateway, $paymentGateway->getValidTestToken());
|
|
|
|
$this->assertEquals('john@example.com', $order->email);
|
|
$this->assertEquals(3, $order->ticketQuantity());
|
|
$this->assertEquals(3600, $order->amount);
|
|
$this->assertEquals(3600, $paymentGateway->totalCharges());
|
|
}
|
|
}
|