Laravel v5.5.20 was tagged yesterday with some testing assertions, route updates, and Blueprint time precision. Multiple changes and fixes were also merged, see the full release notes for details.
Among the new features, some TestResponse methods were added for convenience around validation and asserting JSON responses:
The assertJsonMissingExact() method, related to the assertJsonMissing() method, fails when all of the JSON attributes exist in the response.
For example, the following assertion will fail because the created attribute matches the response, even though the assertion is clearly for a different record:
{ "data": [ { "name": "Example User", "created": "2017-11-07" } ]} // Fails because the `created` attribute matches$response->assertJsonMissing([ 'name' => 'Missing User', 'created' => '2017-11-07']);
The assertJsonMissingExact() can help with this scenario:
// Passes because not ALL attributes are a match$response->assertJsonMissingExact([ 'name' => 'Missing User', 'created' => '2017-11-07']);
The assertValidationErrors() method helps assert that given keys are in the errors key of a JSON response with validation errors:
$response->assertValidationErrors(['firstName', 'lastName']);
The assertJsonCount() method can help you assert how many items exist in a JSON array:
{ "data": [ {"name": "Example User", "email": "user@example.com"}, {"name": "Example User 2", "email": "user2@example.com"} ]} $response->assertJsonCount(2, 'data');
The fluent Route::middleware method now supports variadic arguments:
Route::middleware(Middleware::class, Middleware2::class) ->get('one', function () { return 'Hello World'; });
Here’s the full list of additions, changes, and fixes:
v5.5.20 (2017-11-07)
Added
- Added
TestResponse::assertJsonMissingExact()(#21881) - Added
assertValidationErrors()andassertJsonCount()toTestResponse(#21917) - Added
allOnQueue()andallOnConnection()for job chaining (#21765) - Support variadic arguments on fluent
Route::middleware()(#21930) - Added precision to
Blueprint::time()(#21936) - Added
Router::apiResources()method (#21956) - Support graceful handling of
SIGTERMin queue workers (#21964)
Changed
- Added “kin” as an uncountable word (#21843)
- Improved geo spatial support (#21919)
- Include job name in the
MaxAttemptsExcededException(#21941, #21943) - Support rendering multiple
@verbatimand@phpblocks (#21900) - Moved
InteractsWithRedistoIlluminate\Foundation\Testing(#21967) - Don’t bind macro when it is not a
Closure(#21980) - Check for
before()method on policies classes (#21989) - Detect lost pgbouncer connections (#21988)
Fixed
- Fixed
BroadcastControllernamespace issue (#21844) - Fixed eager loading
HasManyThroughrelations with custom intermediate and local key (#21902) - Use table aliases when calling self-referencing
HasManyThroughrelation (#21883) - Fixed Vue component file name in React present (#21945)
- Reverted changes to
BadMethodExceptionin #20196 (#21929)