mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
3.6 - Refactoring and Redundant Test Coverage
This commit is contained in:
@@ -16,7 +16,7 @@ class Order extends Model
|
||||
public function cancel()
|
||||
{
|
||||
foreach ($this->tickets as $ticket) {
|
||||
$ticket->update(['order_id' => null]);
|
||||
$ticket->release();
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
|
||||
@@ -12,4 +12,9 @@ class Ticket extends Model
|
||||
{
|
||||
return $query->whereNull('order_id');
|
||||
}
|
||||
|
||||
public function release()
|
||||
{
|
||||
$this->update(['order_id' => null]);
|
||||
}
|
||||
}
|
||||
|
||||
25
tests/unit/TicketTest.php
Normal file
25
tests/unit/TicketTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Concert;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class TicketTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
/** @test */
|
||||
function a_ticket_can_be_released()
|
||||
{
|
||||
$concert = factory(Concert::class)->create();
|
||||
$concert->addTickets(1);
|
||||
$order = $concert->orderTickets('jane@example.com', 1);
|
||||
$ticket = $order->tickets()->first();
|
||||
$this->assertEquals($order->id, $ticket->order_id);
|
||||
|
||||
$ticket->release();
|
||||
|
||||
$this->assertNull($ticket->fresh()->order_id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user