Ad

Why Are There Multiple Assertions When Running An Http Test?

- 1 answer

Given the test below, why do I receive the result for the expected 1 test but with 2 assertions that both pass?

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ConvertALeadTest extends TestCase
{
    /** @test */
    public function a_user_can_view_a_convert_page()
    {
        $response = $this->get('/');

        $response->assertRedirect('login');
    }
}
Ad

Answer

Because the assertRedirect function has two assertions. One to check if the request returned a redirect code, and one to see if the ending location is correct.

public function assertRedirect($uri = null)
{
    PHPUnit::assertTrue(
        $this->isRedirect(), 'Response status code ['.$this->getStatusCode().'] is not a redirect status code.'
    );

    if (! is_null($uri)) {
        $this->assertLocation($uri);
    }

    return $this;
}
Ad
source: stackoverflow.com
Ad