mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
1.4 - Unit Testing Presentation Logic
This commit is contained in:
@@ -8,4 +8,9 @@ class Concert extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
protected $dates = ['date'];
|
||||
|
||||
public function getFormattedDateAttribute()
|
||||
{
|
||||
return $this->date->format('F j, Y');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model Factories
|
||||
@@ -22,3 +24,18 @@ $factory->define(App\User::class, function (Faker\Generator $faker) {
|
||||
'remember_token' => str_random(10),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Concert::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'title' => 'Example Band',
|
||||
'subtitle' => 'with The Fake Openers',
|
||||
'date' => Carbon::parse('+2 weeks'),
|
||||
'ticket_price' => 2000,
|
||||
'venue' => 'The Example Theatre',
|
||||
'venue_address' => '123 Example Lane',
|
||||
'city' => 'Fakeville',
|
||||
'state' => 'ON',
|
||||
'zip' => '90210',
|
||||
'additional_information' => 'Some sample additional information.',
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1>{{ $concert->title }}</h1>
|
||||
<h2>{{ $concert->subtitle }}</h2>
|
||||
<p>{{ $concert->date->format('F j, Y') }}</p>
|
||||
<p>{{ $concert->formatted_date }}</p>
|
||||
<p>Doors at {{ $concert->date->format('g:ia') }}</p>
|
||||
<p>{{ number_format($concert->ticket_price / 100, 2) }}</p>
|
||||
<p>{{ $concert->venue }}</p>
|
||||
|
||||
27
tests/unit/ConcertTest.php
Normal file
27
tests/unit/ConcertTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use App\Concert;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ConcertTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
/** @test */
|
||||
function can_get_formatted_date()
|
||||
{
|
||||
// Create a concert with a known date
|
||||
$concert = factory(Concert::class)->create([
|
||||
'date' => Carbon::parse('2016-12-01 8:00pm'),
|
||||
]);
|
||||
|
||||
// Retrieve the formatted date
|
||||
$date = $concert->formatted_date;
|
||||
|
||||
// Verify the date is formatted as expected
|
||||
$this->assertEquals('December 1, 2016', $date);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user