131 - Asserting Against Sort Order

This commit is contained in:
Adam Wathan
2017-08-16 14:30:07 -04:00
parent 8893f5b03a
commit ac6c420170
5 changed files with 56 additions and 29 deletions

View File

@@ -14,6 +14,7 @@ class PublishedConcertOrdersController extends Controller
return view('backstage.published-concert-orders.index', [
'concert' => $concert,
'orders' => $concert->orders()->latest()->take(10)->get(),
]);
}
}

View File

@@ -60,6 +60,11 @@
<h2 class="m-xs-b-2 text-lg">Recent Orders</h2>
<div class="card">
<div class="card-section">
@if($orders->isEmpty())
<div class="text-center">
No orders yet.
</div>
@else
<table class="table">
<thead>
<tr>
@@ -71,17 +76,18 @@
</tr>
</thead>
<tbody>
@foreach(range(1, 10) as $i)
@foreach($orders as $order)
<tr>
<td>{{ collect(['john', 'jane', 'dave', 'donna'])->random() }}@example.com</td>
<td>{{ rand(1, 4) }}</td>
<td>${{ number_format(rand(5000, 15000) / 100, 2) }}</td>
<td><span class="text-dark-soft">****</span> 4242</td>
<td class="text-dark-soft">July 18, 2017 @ 12:37pm</td>
<td>{{ $order->email }}</td>
<td>{{ $order->ticketQuantity() }}</td>
<td>${{ number_format($order->amount / 100, 2) }}</td>
<td><span class="text-dark-soft">****</span> {{ $order->card_last_four}}</td>
<td class="text-dark-soft">{{ $order->created_at->format('M j, Y @ g:ia') }}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
</div>
</div>

View File

@@ -17,28 +17,6 @@ class ViewConcertListTest extends TestCase
{
use DatabaseMigrations;
protected function setUp()
{
parent::setUp();
Collection::macro('assertContains', function ($value) {
Assert::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
});
Collection::macro('assertNotContains', function ($value) {
Assert::assertFalse($this->contains($value), "Failed asserting that the collection does not contain the specified value.");
});
Collection::macro('assertEquals', function ($items) {
Assert::assertEquals(count($this), count($items));
$this->zip($items)->each(function ($pair) {
list($a, $b) = $pair;
Assert::assertTrue($a->is($b));
});
});
}
/** @test */
function guests_cannot_view_a_promoters_concert_list()
{

View File

@@ -22,13 +22,37 @@ class ViewPublishedConcertOrdersTest extends TestCase
$user = factory(User::class)->create();
$concert = ConcertFactory::createPublished(['user_id' => $user->id]);
$order = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('11 days ago')]);
$oldOrder = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('11 days ago')]);
$recentOrder1 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('10 days ago')]);
$recentOrder2 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('9 days ago')]);
$recentOrder3 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('8 days ago')]);
$recentOrder4 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('7 days ago')]);
$recentOrder5 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('6 days ago')]);
$recentOrder6 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('5 days ago')]);
$recentOrder7 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('4 days ago')]);
$recentOrder8 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('3 days ago')]);
$recentOrder9 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('2 days ago')]);
$recentOrder10 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('1 days ago')]);
$response = $this->actingAs($user)->get("/backstage/published-concerts/{$concert->id}/orders");
$response->assertStatus(200);
$response->assertViewIs('backstage.published-concert-orders.index');
$this->assertTrue($response->data('concert')->is($concert));
$response->data('orders')->assertNotContains($oldOrder);
$response->data('orders')->assertEquals([
$recentOrder10,
$recentOrder9,
$recentOrder8,
$recentOrder7,
$recentOrder6,
$recentOrder5,
$recentOrder4,
$recentOrder3,
$recentOrder2,
$recentOrder1,
]);
}
/** @test */

View File

@@ -7,6 +7,7 @@ use App\Exceptions\Handler;
use PHPUnit\Framework\Assert;
use Illuminate\Foundation\Testing\TestResponse;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
{
@@ -30,6 +31,23 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
TestResponse::macro('assertViewIs', function ($name) {
Assert::assertEquals($name, $this->original->name());
});
EloquentCollection::macro('assertContains', function ($value) {
Assert::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
});
EloquentCollection::macro('assertNotContains', function ($value) {
Assert::assertFalse($this->contains($value), "Failed asserting that the collection does not contain the specified value.");
});
EloquentCollection::macro('assertEquals', function ($items) {
Assert::assertEquals(count($this), count($items));
$this->zip($items)->each(function ($pair) {
list($a, $b) = $pair;
Assert::assertTrue($a->is($b));
});
});
}
protected function disableExceptionHandling()