Laravel 5 how to test redirect
<p>I have a Laravel 5 app in which one controller action finishes by redirecting to a page outside the Laravel app but on the same domain. Interacting manually with the page works fine, but automating the test with PHPunit doesn't. It keeps trying to load the route and fails with 'headers already sent'.</p>

<p><strong>Route</strong></p>

<pre><code>Route::post('/trials', [
    'middleware' =&gt; ['web'],
    'uses' =&gt; 'TrialsController@create'
]);
</code></pre>

<p><strong>Controller</strong></p>

<pre><code>public function create(Request $request)
{
  ...
  setcookie( 'etc', $value, time() + 60, '/', "domain.com", true, true) ;
  return Saml2::login('https://store.domain.com');
}
</code></pre>

<p><strong>Test</strong></p>

<pre><code>public function testSuccessfulSignup(){

    $this-&gt;visit('/signup')
        -&gt;type('test@mail.com', 'mail')
        -&gt;type('Philip', 'first_name')
        -&gt;type('Fry', 'last_name')
        -&gt;press('Signup !') ;
        // -&gt;seePageIs('https://store.domain.com'); doesn't work
        // -&gt;assertRedirectedTo('https://store.domain.com'); doesn't work
}
</code></pre>

<p><strong>Error</strong></p>

<pre><code>1) TrialsTest::testSuccessfulSignup
A request to [http://domain.com/trials] failed. Received status code [500].

/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:196
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:80
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:114
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:554
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:541
/private/var/identity/tests/TrialsTest.php:154

Caused by
exception 'ErrorException' with message 'Cannot modify header information - headers already sent by (output started at phar:///usr/local/bin/phpunit/phpunit/Util/Printer.php:134)' in /private/var/identity/app/Http/Controllers/TrialsController.php:84
</code></pre>

<h1>Update</h1>

<p>It seems to be related to the web middleware, more specifically the CSRF middleware, interfering with my redirect headers. Specifying <code>use WithoutMiddleware;</code> also disables the Session, how can I keep the session but disable CSRF in testing context ?</p>

<h1>Update 2</h1>

<p>Regarding close vote: You can see in the test code I have an assertion that it should follow the redirect, what I expect this code to do is follow the redirection beyond the controller action (successfully and not fail) then proceed to do more verifications.</p>