我正在尝试编写带有一些断言的测试。这是一个简单的 GET 请求示例,我希望它会失败,因为页面上缺少文本。但是,它给了我绿色。当我检查响应内容时,我清楚地看到它抛出错误。我正在使用 laravel 8。
<?php
namespace Tests\Feature;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Concert;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ViewConcertListingTest extends TestCase
{
use DatabaseMigrations;
/** @test */
function user_can_view_a_concert_listing() {
$concert = Concert::create([
'title' => 'The Red Chord',
'subtitle' => 'with Animosity and Lethargy',
'date' => Carbon::parse('December 13, 2016 8:00pm'),
'ticket_price' => 3250,
'venue' => 'The Mosh Pit',
'venue_address' => '123 Example Lane',
'city' => 'Laraville',
'state' => 'ON',
'zip' => '17916',
'additional_information' => 'For ticket, cal (555) 555-5555.',
]);
$view = $this->get('/concerts/'.$concert->id);
$view->assertSee('The Red Chord');
$view->assertSee('with Animosity and Lethargy');
$view->assertSee('December 13, 2016');
$view->assertSee('8:00pm');
$view->assertSee('32.50');
$view->assertSee('The Mosh Pit');
$view->assertSee('123 Example Lane');
$view->assertSee('Laraville, ON 17916');
$view->assertSee('For tickets, call (555) 555-5555.');
}
}