Home > PHP Framework > Laravel > body text

Summarize the new additions, fixes and changes in Laravel 9.5 version!

WBOY
Release: 2022-04-06 15:46:43
forward
2574 people have browsed it

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.

Summarize the new additions, fixes and changes in Laravel 9.5 version!

[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.:

Callback support for the collection's Implode method

@Lito contributed on Collect::implode() Callback support to simplify ->map()->implode() calls:

// 之前<br/>{{ $user->cities->map(fn ($city) => $city->name.&#39; (&#39;.$city->state->name.&#39;)&#39;)->implode(&#39;, &#39;) }}<br/>// 使用回调 <br/>{{ $user->cities->implode(fn ($city) => $city->name.&#39; (&#39;.$city->state->name.&#39;)&#39;, &#39;, &#39;) }}<br/>
Copy after login

Using Storage Fake to assert an empty directory

Mark Beech contributed using Storage::fake () Example of the ability to assert an empty directory:

// 9.5 版本之前<br/>$this->assertEmpty(Storage::disk(&#39;temp&#39;)->allFiles(&#39;/foo&#39;));<br/>// +9.5<br/>Storage::disk(&#39;temp&#39;)->assertDirectoryEmpty(&#39;/foo&#39;);<br/>
Copy after login

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(&#39;temp&#39;);<br/>Storage::disk(&#39;temp&#39;)->put(&#39;/foo/bar.txt&#39;, &#39;string&#39;);<br/>Storage::disk(&#39;temp&#39;)->assertDirectoryEmpty(&#39;/&#39;); // 失败<br/>
Copy after login

JSON assertion "assertJsonPath ()" now accepts closures

Fabien Villepinte contributed passing closures to assertJsonPath without any backwards Compatible interrupt capabilities:

$response = TestResponse::fromBaseResponse(new Response([<br/>    &#39;data&#39; => [&#39;foo&#39; => &#39;bar&#39;],<br/>]));<br/>$response->assertJsonPath(&#39;data.foo&#39;, &#39;bar&#39;);<br/>$response->assertJsonPath(&#39;data.foo&#39;, fn ($value) => $value === &#39;bar&#39;);<br/>
Copy after login

While the example above seems simpler using the string version, if you need more complex logic around path assertions, you can now use closures.

Partial Queue Faking

Taylor Otwell contributed partial faking to the queue under test:

Queue::fake([JobsToFake::class, /* ... */]);<br/>
Copy after login

A new way to create a “through” model

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/>
Copy after login

New string wrap helper function

Markus Hebenstreit contributed wrap() String helper functions. Here's an example usage from the pull request description:

Str:wrap(&#39;value&#39;)->wrap(&#39;"&#39;);<br/>Str::of(&#39;value&#39;)->wrap(&#39;"&#39;);<br/>str(&#39;value&#39;)->wrap(&#39;"&#39;);<br/>// 输出: "value"<br/>Str:wrap(&#39;is&#39;, &#39;This &#39;, &#39; me!&#39;);<br/>Str::of(&#39;is&#39;)->wrap(&#39;This &#39;, &#39; me!&#39;);<br/>str(&#39;is&#39;)->wrap(&#39;This &#39;, &#39; me!&#39;);<br/>// 输出: This is me!<br/>
Copy after login

Freeze Time helper function for testing

@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/>
Copy after login

freezeTime() method is syntactic sugar for the following:

$this->travelTo(Carbon::now());<br/>
Copy after login

Allows callable objects to be accepted in Http::beforeSending ()

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(&#39;https://api.example.org&#39;)<br/>    ->beforeSending([ $this, &#39;prepareRequest&#39; ])<br/>    ->asJson()<br/>    ->withoutVerifying();<br/>
Copy after login

Release Notes

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 )

  • ##Fixed route:list –except-vendor for hiding Route::view () & Route::redirect () (

    #41465)

Change

  • Add an empty type for the connection property in \Illuminate\Database\Eloquent\Factories\Factory. (

    #41418)

  • Updated reserved names in GeneratorCommand (

    #41441)

  • Redesigned the php artisan schedule:list command. (

    #41445)

  • Extended eloquent high-order proxy properties. (

    #41449)

  • Allows passing named parameters to dynamic local scopes. (

    #41478)

  • Throws an exception if the tag passes but is not supported in Illuminate/Encryption/Encrypter.php. (

    #41479)

  • When the composer vendor folder is not in the project folder, Update PackageManifest::$vendorPath is initialized for the case. (

    #41463)

[Related recommendations:

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template