I am trying to do login test by phpunit in laravel. I have 5.5 so visit method is not supported. Here is what I am doing
public function testLoginPost(){
Session::start();
$response = $this->call('POST', 'login', [
'email' => '[email protected]',
'password' => '123456',
'_token' => csrf_token()
]);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('auth.login', $response->original->name());}
```
c:\wamp64\www\fundtheneedy\tests\Unit>phpunit Fundtheneedy
PHPUnit 6.5.8 by Sebastian Bergmann and contributors.
.F 2 / 2 (100%)
Time: 321 ms, Memory: 14.00MB
There was 1 failure:
1) Tests\Unit\Fundtheneedy::testLoginPost
Failed asserting that 302 matches expected 200.
C:\wamp64\www\fundtheneedy\tests\Unit\Fundtheneedy.php:30
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
```
If you purely look at the response code it will always be 302 which is the response code for a URL Redirect as it will redirect regardless whether or not it fails.
You can instead look at whether or not there are errors in the session which is a bit of a workaround mentioned in this post here.
Or use the inverse