This article brings you relevant knowledge about laravel. The Laravel team released version 9.5, which includes partial queue forgery, freezeTime() auxiliary function, storage assertDirectoryEmpty() assertion, etc., I hope everyone has to help.
[Related recommendations: laravel video】
Laravel team released version 9.5, which includes partial queue forgery, freezeTime () Helper functions, storage assertDirectoryEmpty () assertions, closures in assertJsonPath (), etc.:
@Lito contributed on Collect::implode() Callback support to simplify ->map()->implode() calls:
// 之前<br/>{{ $user->cities->map(fn ($city) => $city->name.' ('.$city->state->name.')')->implode(', ') }}<br/>// 使用回调 <br/>{{ $user->cities->implode(fn ($city) => $city->name.' ('.$city->state->name.')', ', ') }}<br/>
Mark Beech contributed using Storage::fake () Example of the ability to assert an empty directory:
// 9.5 版本之前<br/>$this->assertEmpty(Storage::disk('temp')->allFiles('/foo'));<br/>// +9.5<br/>Storage::disk('temp')->assertDirectoryEmpty('/foo');<br/>
If there are no files in the directory and only other subdirectories, the assertion will fail because it contains other folders / files. Here's an example from the pull request discussion:
Storage::fake('temp');<br/>Storage::disk('temp')->put('/foo/bar.txt', 'string');<br/>Storage::disk('temp')->assertDirectoryEmpty('/'); // 失败<br/>
Fabien Villepinte contributed passing closures to assertJsonPath without any backwards Compatible interrupt capabilities:
$response = TestResponse::fromBaseResponse(new Response([<br/> 'data' => ['foo' => 'bar'],<br/>]));<br/>$response->assertJsonPath('data.foo', 'bar');<br/>$response->assertJsonPath('data.foo', fn ($value) => $value === 'bar');<br/>
While the example above seems simpler using the string version, if you need more complex logic around path assertions, you can now use closures.
Taylor Otwell contributed partial faking to the queue under test:
Queue::fake([JobsToFake::class, /* ... */]);<br/>
Hafez Divandari Contributed the ability to create a new "through" model without overriding the entire hasOneThrough or hasManyThrough method:
// Define a `newThroughInstance` method<br/>protected function newThroughInstance($resource)<br/>{<br/> return (new \App\Models\ExampleEntity)->setTable($resource);<br/>}<br/>
Markus Hebenstreit contributed wrap() String helper functions. Here's an example usage from the pull request description:
Str:wrap('value')->wrap('"');<br/>Str::of('value')->wrap('"');<br/>str('value')->wrap('"');<br/>// 输出: "value"<br/>Str:wrap('is', 'This ', ' me!');<br/>Str::of('is')->wrap('This ', ' me!');<br/>str('is')->wrap('This ', ' me!');<br/>// 输出: This is me!<br/>
@Italo contributed the freezeTime() helper function - one that will freeze the current time in the test Time test method:
public function test_something()<br/>{<br/> $this->freezeTime();<br/> // 或将时间设置为日期的当前秒<br/> // 没有亚秒级精度。<br/> $this->freezeSecond();<br/>}<br/>
freezeTime() method is syntactic sugar for the following:
$this->travelTo(Carbon::now());<br/>
Dries Vints help to accept callable objects in the Http::beforeSending() method, not just callable classes. The following example will now work instead of getting "call member function __invoke() on an array":
Http::baseUrl('https://api.example.org')<br/> ->beforeSending([ $this, 'prepareRequest' ])<br/> ->asJson()<br/> ->withoutVerifying();<br/>
You can check out the full list of new features and updates below And check out the differences between 9.4.0 and 9.5.0 on GitHub. The following release notes are taken directly from the changelog:
9.5.0 Version
New
Added Added callback support for implode collection methods. (#41405)
Added Illuminate/Filesystem/FilesystemAdapter::assertDirectoryEmpty(). (#41398)
Implements email "metadata" for SesTransport. (#41422)
Make assertPath () accept a closure. (#41409)
Added callable support for operatorForWhere on collections. (#41414, #41424)
Added some queue forgery. (#41425)
Added –name option to schedule:test command. (#41439)
defines Illuminate/Database/Eloquent/Concerns/HasRelationships::newRelatedThroughInstance(). (#41444)
Added Illuminate/Support/Stringable::wrap() (#41455)
Added "freezeTime" auxiliary function for testing. (#41460)
Allows the use of beforeSending calls in Illuminate/Http/Client/PendingRequest.php::runBeforeSendingCallbacks(). (#41489)
Fix
Fixed when filtering names or domains from Deprecation warning for route:list . (#41421)
Fixed HTTP::pool response when URL returns empty status code. (#41412)
Fixed recaller name resolution in Illuminate/Session/Middleware/AuthenticateSession.php. (#41429)
Fixed guard instance being used in /Illuminate/Session/Middleware/AuthenticateSession.php (#41447 )
#41465)
Change
#41418)
#41441)
#41445)
#41449)
#41478)
#41479)
#41463)
laravel video tutorial]
The above is the detailed content of Summarize the new additions, fixes and changes in Laravel 9.5 version!. For more information, please follow other related articles on the PHP Chinese website!