Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.5 Tests - Call to undefined method ::see()

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!

like image 459
confm Avatar asked Nov 05 '25 18:11

confm


2 Answers

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');
        // ...
    }
}
like image 171
dstrunk Avatar answered Nov 07 '25 07:11

dstrunk


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;
like image 21
Pubudu Jayawardana Avatar answered Nov 07 '25 08:11

Pubudu Jayawardana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!