lundi 7 mars 2016

Route Parameters Returning Null in Laravel 5.2 PHPUnit Testing While using route(), call() & action() Methods

I'm using PHPUnit 4.0 & Laravel 5.2 with Apache. I'm having an issue where I can't get route parameters to pass through using the route() method when testing. They all dump as NULL. I have tried the route(), action(), and call() methods to get the same results for every test. I'm getting 404's with no code coverage while using only the routes. When I don't use either of those three methods and execute the code I get correct response codes with coverage. I have to use one of those three methods though, seeing how I want to verify the views returned. I've turned middleware off using:

use Illuminate\Foundation\Testing\WithoutMiddleware;

class loginControllerTest extends TestCase{

use WithoutMiddleware;
$this->withoutMiddleware();

My tests for the routes without route parameters seem to be working, so I know my configurations are fine. I know this through code coverage and through the response codes. I know my URL is correct, because I have tried hacking the call() method to dump the URL called. The route is correct because I would get undefined route errors if the route is incorrect. I can view the routes fine through the browser and through curl. PHPUnit just seems to be loosing the parameters and doesn't appear to hit the URL at all when route parameters are necessary...I know there was a similar known bug for Lumen that it looks like Taylor Otwell fixed; however, I can't get it working in Laravel 5.2. I am wondering if he forgot to update Laravel 5.2 with the same fix.

http://ift.tt/24MX8b2

my routes.php looks like:

<?php

Route::group(array('prefix' => '/site', 'namespace' => 'Site'), function() {

    Route::group(array('prefix' => '{parameter1}'), function () {

        Route::get('login', [
            'as'     => 'site.login',
            'uses'   => 'LoginController@login'
                    ]
                );
            }
        );
    }
);

the section of my test calling the route looks like:

$this->route('get', 'site.login', [
    'parameter1'    => 'parameter1'
], [
        'username'   => 'username'
        '_token'     => csrf_token(),
        'Login'      => ""
   ]
);

$this->assertResponseStatus(404);

LoginController.php looks like

<?php namespace App\Http\Controllers\Site;

class LoginController extends BaseController
{
    public function login($parameter1)
    {
        var_dump($parameter1);

    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire