3
votes

I get this error when i run phpunit

Error: Call to undefined method Tests\Feature\ViewConcertListingTest::see()

This is my code:

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

}

Any help? Thanks!

3

3 Answers

8
votes

If others have come across this error and the question's code looks familiar, this is from the Test-Driven Laravel course from Adam Wathan (highly recommended!).

If you're following along in earlier lessons of the course but are using Laravel 5.5, you'll need to update a couple of things:

  1. Instead of $this->get('...');, use $response = $this->get('...');.
  2. Instead of $this->see(), use $response->assertSee().

Laravel has updated the HTTP testing layer and helper methods from 5.3 (the Laravel version being used in the screencasts) to 5.5. Your feature spec for 5.5 should be updated to the following:

<?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');
        // ...
    }
}
2
votes

You will need to use Laravel Dusk for this scenario:

So your assertions will be as follows:

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

You will have to include the namespaces:

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

Are you referring to testing methods available in Laravel 5.3? Those were removed in 5.4 and are available as a separate package; https://github.com/laravel/browser-kit-testing

To install them, use composer:

composer require laravel/browser-kit-testing --dev