jhodgson4
jhodgson4

Reputation: 1656

Why are there multiple assertions when running an http test?

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');
    }
}

Upvotes: 1

Views: 184

Answers (1)

Jerodev
Jerodev

Reputation: 33206

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;
}

Upvotes: 4

Related Questions