@meto1080 hmm - can you properly format the question please, it's very difficult to read! Thanks!
Mar 6, 2016
8
Level 5
Laravel testing cannot recognise route when call the same test function at the second time
Hi Guys,
I am newbee of Laravel testing. I just got an route not define error when I call the same test function at the second time.
Story:
- I put the login test into the TestCase.php file for reusability in all test files.
- When it is called by the first test case, everything is fine. I.E. loginSuccess, loginFailed functions below.
- But when the second test case pickup the same testing above, it give me error that routes not defined.
More details, please refer to below code and error message in the end.
Will appreciate if someone can point out where I am doing wrong.
/**
* Shared function for login fail test.
*/
public function loginFail() {
$this->visit(route('auth.getLogin'))
->see('Welcome to VMS')
->type('notexist@gmail.com', 'email')
->type('asdfasdfasdfa', 'password')
->press('Login')
->seePageIs(route('auth.getLogin'))
->see('These credentials do not match our records');
}
/**
* Shared function for login fail test.
*/
public function loginSuccess() {
$this->visit(route('auth.getLogin'))
->see('Welcome to VMS')
->type(Config::get('constants.VISDOM_ADMIN_EMAIL'), 'email')
->type(Config::get('constants.VISDOM_STANDARD_PASSWORD'), 'password')
->press('Login')
->dontSee('These credentials do not match our records');
}
/**
* A basic functional test example.
*
* @return void
*/
public function testAddUserInPage()
{
$this->loginSuccess();
$this->visit(route('users.add'))
->type($this->faker->firstName, 'first_name')
->type($this->faker->lastName, 'last_name')
->type($this->faker->email, 'email')
->type(Config::get('constants.VISDOM_STANDARD_PASSWORD'), 'password')
->type(Config::get('constants.VISDOM_STANDARD_PASSWORD'), 'password_confirmation')
->type('<div>als,dfjaslkdf</div>', 'email_signature')
->press('Add User')
->see('User created successfully');
$this->reset();
}
There were 2 errors:
1) UserAuthBddTest::testUserAuthSuccess
InvalidArgumentException: Route [auth.getLogin] not defined.
/home/vagrant/Code/vms-v4/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:306
/home/vagrant/Code/vms-v4/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:614
/home/vagrant/Code/vms-v4/tests/TestCase.php:43
/home/vagrant/Code/vms-v4/tests/users/UserAuthBddTest.php:24
2) UserAuthBddTest::testUserAuthFail
InvalidArgumentException: Route [auth.getLogin] not defined.
/home/vagrant/Code/vms-v4/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:306
/home/vagrant/Code/vms-v4/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:614
/home/vagrant/Code/vms-v4/tests/TestCase.php:30
/home/vagrant/Code/vms-v4/tests/users/UserAuthBddTest.php:34
FAILURES!
Tests: 4, Assertions: 11, Errors: 2.
Above errors are all returned from the second test case.....
See my second test case, nothing funny really.
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
<?php
/**
* @file
*
* BDD test for user authentication.
*/
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UserAuthBddTest extends TestCase
{
use DatabaseTransactions;
public function setUp() {
parent::setUp();
}
/**
* Test login fail.
*
* @return void
*/
public function testLoginFail()
{
$this->loginFail();
}
/**
* Test login fail.
*
* @return void
*/
public function testLoginSuccess()
{
$this->loginSuccess();
}
}
Please or to participate in this conversation.