Skip to content

PHPUnit testing named routes not working #4295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed

PHPUnit testing named routes not working #4295

wants to merge 18 commits into from

Conversation

alex-petrea
Copy link

@alex-petrea alex-petrea commented Jun 21, 2017

So I'm running the following test which does a post request to the login controller.
public function test_login_post()
{
$response = $this->post('/login', [
'email' => $this->user->email,
'password' => $this->user->password,
'_token' => csrf_token()
]);
dd($response);
}

Once the login is successful then the user should get redirected to the /app/invoices

If I set the /app/invoices route like this and run the test
Route::get('/app/invoices', 'InvoicesController@index')->name('account.invoices');
I get an error in the response that route('account.invoices') was not found.

If I name the route this way:
Route::get('/', [
'as' => 'account.invoices',
'uses' => 'InvoicesController@index'
]);
I get no errors.

I don't know if this is a bug or I'm doing something wrong

DrowningElysium and others added 18 commits May 10, 2017 15:03
I don't like the fact we have to add 
```
<script>
        window.Laravel = {!! json_encode([
            'csrfToken' => csrf_token(),
        ]) !!};
</script>
```
To have it working, when the docs suggest adding only the meta tag. This will get the token from the meta tag.
Add missing IPv4/IPv6 validation messages
Note that I left your dang `const` as it is, even though it's stupid. `let` for life. 💃💃💃💃
Sass compilers can sometimes be weird if import urls like this aren't quoted. They'll spit out junk like

```
Error: Encountered invalid @import syntax.
```

Anyways, pretty common practice to use quotes for all imports. I mean, seriously, how much more do you want me to write for a dang PR that adds a pair of quotes? I've got work to do, gah.
@edenreich
Copy link

edenreich commented Jun 21, 2017

@alex-petrea hey, I've tried to replicate this, but I need some more info. I get 200 for each request with phpunit.

I have noticed that in your question you specify different paths. the first one you are testing goes to /app/invoices and the second one is only / is that exacly what you were testing or did you test:

Route::get('/app/invoices', [
'as' => 'account.invoices',
'uses' => 'InvoicesController@index'
]);

and you get error not found?

@alex-petrea
Copy link
Author

alex-petrea commented Jun 21, 2017

@edenreich I mistyped it. I was testing

Route::get('/app/invoices', [
'as' => 'account.invoices',
'uses' => 'InvoicesController@index'
]);

nevermind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.