调用未定义的方法

调用未定义的方法

我运行phpunit时收到此错误

错误:调用未定义的方法Tests \ Feature \ ViewConcertListingTest :: see()

这是我的代码:

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');
}


}

有什么帮助吗?
谢谢!

最佳答案

在这种情况下,您将需要使用Laravel Dusk:

因此,您的断言如下:

$this->browse(function ($browser) use ($user) {
                $browser->visit('/concerts/' . $concert->id)
                ->assertSee('The Red Chord');
                ->assertSee('with Animosity and Lethargy');
                ->assertSee('December 13, 2016');
                ->assertSee('8:00pm');
                ->assertSee('32.50');
                ->assertSee('The Mosh Pit');
                ->assertSee('123 Example Lane');
                ->assertSee('Laraville, ON 17916');
                ->assertSee('For tickets, call (555) 555-5555');
            });


您将必须包括名称空间:

use Tests\DuskTestCase;
use Laravel\Dusk\Chrome;

10-06 01:00