jeudi 10 mars 2016

Laravel PHPUnit follow redirect outside application routes

I'm testing my Laravel application and I need to check if it redirects to another page on our domain but that's not part of the Laravel app (legacy page). How do I get it to follow a redirect outside the app routes ?

Whenever I try to use assertRedirectedTo it complains about a 404 or Failed asserting that Illuminate\Http\Response Object (...) is an instance of class "Illuminate\Http\RedirectResponse" even though the page exits, I'm assuming it's because it's not within the application routes, because when I test the redirect with a random page in the app routes it works.

Code

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class UserTest extends TestCase
{

    use DatabaseTransactions ;
    protected $baseUrl = 'http://my_app.com:8892';

    public function testSuccessfulSignupRedirect(){

        $this->visit('/signup?redirect=https%3A%2F%2Fstore.domain.com')
            ->type('username', 'name')
            ->type('test@mail.com', 'mail')
            ->type('password', 'password')
            ->type('password', 'password_confirm')
            ->type('Philip', 'first_name')
            ->type('Fry', 'last_name')
            ->select('Freelancer', 'profile')
            ->check('licensecheck')->press('Create new account')
            ->assertRedirectedTo('http://ift.tt/1pbc3uW') ;
    }
}

Error

A request to [http://ift.tt/1jXKT14] failed. Received status code [404].

/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:178
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:72
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:120
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:72
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:96
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:788
/private/var/identity/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:775
/private/var/identity/tests/UserTest.php:52

Caused by
exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /private/var/identity/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:161
Stack trace:



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire