con*_*nfm 3 phpunit laravel laravel-5.5
我运行phpunit时出现此错误
错误:调用未定义的方法测试\ Feature\ViewConcertListingTest :: see()
这是我的代码:
class ViewConcertListingTest扩展TestCase {使用DatabaseMigrations;
/** @test */
public function user_can_view_a_concert_listing()
{
// Arrange
// Create a concert
$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 tickets, call (555) 555-5555'
]);
// Act
// View the concert listing
$this->get('/concerts/' . $concert->id);
// Assert
// See the concert details
$this->see('The Red Chord');
$this->see('with Animosity and Lethargy');
$this->see('December 13, 2016');
$this->see('8:00pm');
$this->see('32.50');
$this->see('The Mosh Pit');
$this->see('123 Example Lane');
$this->see('Laraville, ON 17916');
$this->see('For tickets, call (555) 555-5555');
}
Run Code Online (Sandbox Code Playgroud)
}
有帮助吗?谢谢!
如果其他人遇到了这个错误并且问题的代码看起来很熟悉,那么这来自Adam Wathan的测试驱动的Laravel课程(强烈推荐!).
如果您在本课程的早期课程中学习但使用的是Laravel 5.5,则需要更新以下内容:
$this->get('...');,使用$response = $this->get('...');.$this->see(),使用$response->assertSee().Laravel已经将5.3测试层和帮助器方法从5.3(在屏幕录像中使用的Laravel版本)更新到5.5.您的5.5功能规范应更新为以下内容:
<?php
class ViewConcertListingTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function user_can_view_a_concert_listing()
{
// Arrange
// Create a concert
$concert = Concert::create([
'title' => 'The Red Chord',
// ...
]);
// Act
// View the concert listing
$response = $this->get('/concerts/' . $concert->id);
// Assert
// See the concert details
$response->assertSee('The Red Chord');
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2746 次 |
| 最近记录: |