Framework: [BUG] [5.6.1] assertSessionHasErrors no longer works only with keys of errores

Created on 8 Feb 2018  路  14Comments  路  Source: laravel/framework

  • Laravel Version: 5.6.1
  • PHP Version: 7.2.2
  • Database Driver & Version: 5.7.2

Description:

After the latest update (5.6.1) all the tests for form validation are failing. The message is:

Failed asserting that an array contains 'fieldName'.

From checking the headers it seems like the erroBag does have that key (and the validation works if I specify key value pairs (['message' => 'message is required']

Steps To Reproduce:

  1. New laravel project with 5.6.1 version
  2. Add a route
Route::post('post', function (Request $request) {
    $request->validate([
        'title' => 'required',
    ]);
});
  1. Add a test
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $this->post('/post',[
            'title' => ''
        ])->assertSessionHasErrors('title');
    }
}
  1. Watch it fail.

Most helpful comment

The issue that caused the problem in the original post has been resolved. If you're seeing a similar issue, please open a new issue and fill out the issue template completely. Posting similar problems on an old closed issue will not likely be considered.

https://github.com/laravel/framework/issues/28268#issue-435009763

I just open a ticket

All 14 comments

Reverted entire feature.

@taylorotwell I'm not sure that the TestResponse changes are the cause of this problem. I just tested this on a clean install of 5.6.2 and I'm still seeing the issue.

@taylorotwell

It seems like the feature was reverted incorrectly - it is now

foreach ($keys as $key => $value) {
            if (is_int($value)) {
                PHPUnit::assertTrue($errors->has($value), "Session missing error: $value");
            } else {
                PHPUnit::assertContains($value, $errors->get($key, $format));
            }
        }

It should be (And was before)

foreach ($keys as $key => $value) {
            if (is_int($key)) {
                PHPUnit::assertTrue($errors->has($value), "Session missing error: $value");
            } else {
                PHPUnit::assertContains($value, $errors->get($key, $format));
            }
        }

@LCD344 You should probably reopen this as it's still an issue.

I confirm that still an issue, i tried it in a new laravel installation (Laravel 5.7.17) and i got the same issue.

Got the same issue in Laravel 5.7.17

Got the same issue in Laravel 5.8.11

Excuse me.
The error message was the same but the cause was different.

I am with "laravel/framework": "5.8.*",

and the issue remains the same

Session is missing expected key [username].
Failed asserting that false is true.

Why is this issue closed? When should be open?

The issue that caused the problem in the original post has been resolved. If you're seeing a similar issue, please open a new issue and fill out the issue template completely. Posting similar problems on an old closed issue will not likely be considered.

The issue that caused the problem in the original post has been resolved. If you're seeing a similar issue, please open a new issue and fill out the issue template completely. Posting similar problems on an old closed issue will not likely be considered.

https://github.com/laravel/framework/issues/28268#issue-435009763

I just open a ticket

Have you found any solution for this issue?

I did! for me the solution was first clear all the caches, I found this solution after dump all the test and I saw an Page Expired

php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan test
Was this page helpful?
0 / 5 - 0 ratings