Search code examples
laravellaravel-5laravel-5.3laravel-5.4laravel-dusk

acceptance test method visit undefined


I have created a new laravel 5.4 project with authentication.

I have then created a feature test for the login process which is as follows

public function test_login()
  {
    $user = factory(\App\User::class)->make();
    $user->save();
    $this->visit('/login')
    ->type($user->email,'email')
    ->type($user->password,'password')
     ->press('login');;
     $this->seePageIs('/dashboard');
    }

but when i run the test I get

Error: Call to undefined method Tests\Feature\UserTest::visit()

not sure if I need to install another component. this is what my composer.json looks like

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/dusk": "^1.0",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"

    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true
    }
}

Solution

  • There is no visit method built-in by default in Laravel 5.4 You need to run get in order to run action but please be aware it is not working the same (probably no redirections are followed).

    If you want to use old behaviour you can use for now Laravel browser kit;

    composer require laravel/browser-kit-testing
    

    You can read more about it in migration guide: https://laravel.com/docs/5.4/upgrade#upgrade-5.4.0

    As another alternative you can use Laravel Dusk to run full browser tests