lundi 7 septembre 2020

The laravel internal middleware 'TrimStrings' is never called in tests

api.php

Route::middleware(['trim.strings', 'other'])->group(function () {
    Route::put('a', 'a@put');
})

Kernel.php

use App\Http\Middleware\TrimStrings;
protected $routeMiddleware = [
    'trim.strings' => TrimStrings::class,
    'other' => Other::class
]

Tests.php

$this->withMiddleware()
    ->putJson('/a', '{"a": [{"name" => "hi  "}]')
    ->assertStatus(200)
    ->assertJson([
        'data' => [
            'a' => [
               ['name' => "hi"],
            ]
        ]
    ]);

More Info:

  • Laravel 7

Behavior:

  • In the tests:
    • Only middlewares other is called
  • Normal call:
    • Middlewares other and trim.strings are used

Question: Why is the string trimmer never called inside tests ?

Aucun commentaire:

Enregistrer un commentaire