简体   繁体   中英

Laravel unit testing show complete error

I am trying to create a test for my laravel 5.2 project which will test a register page in a rest resource controller. When I test it manually with the exact input of my test everything works but when I test it with phpunit I get redirected to an error page making my page assert fail. The error however displays the error of the assert failing and not what is on the error page and thus doesn't show why the test failed. How can I see this?

Testcase:

class registerTest extends TestCase
{
use WithoutMiddleware;

public function testRegisterCompanyCorrectly()
{
    $this->actAsAdmin();
    $this->visit('/Companies/create')
        ->type('testCompany', 'CName')
        ->type('www.testCompany.com', 'CUrl')
        ->type('testManager@gmail.com', 'Mail')
        ->type('John Doe', 'Name')
        ->type('Keith Richards', 'Password')
        ->type('Keith Richards', 'CPassword')
        ->press('Registreren')
        ->seePageIs('/Companies/3')
        ;
}

private function actAsAdmin()
{
    $user = User::find(1);
    $this->actingAs($user);
}
}'

phpunit error:

There was 1 failure:

1) registerTest::testRegisterCompanyCorrectly
Did not land on expected page [http://localhost/Companies/3].

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/Companies/3'
+'http://localhost/Companies'

C:\Users\Stefan\Documents\producten\Applicatie\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:170
C:\Users\Stefan\Documents\producten\Applicatie\tests\registerTest.php:34
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129

FAILURES!
Tests: 5, Assertions: 14, Failures: 1.

One way to investigate the error would be to activate error reporting for Illuminate\\Foundation\\Validation\\ValidationException in your app/Exceptions/Handler.php .

protected $dontReport = [
    // ValidationException::class,
];

If you run the test again, there should be a stack trace in your log file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM