3.6 - Refactoring and Redundant Test Coverage

This commit is contained in:
Adam Wathan
2016-11-15 13:22:44 -05:00
parent 2e92881fb6
commit 9fe42a1aaa
3 changed files with 31 additions and 1 deletions

View File

@@ -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();

View File

@@ -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
View 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);
}
}