歸納Laravel 9.5版本的新增、修復(fù)和改變!

本篇文章給大家?guī)砹岁P(guān)于laravel的相關(guān)知識,laravel團(tuán)隊發(fā)布了 9.5 版本,其中包括部分隊列偽造,freezetime()輔助函數(shù),存儲assertdirectoryempty()斷言等等,希望對大家有幫助。

歸納Laravel 9.5版本的新增、修復(fù)和改變!

【相關(guān)推薦:laravel

laravel?團(tuán)隊發(fā)布了?9.5?版本,其中包括部分隊列偽造,freezeTime?()?輔助函數(shù),存儲?assertDirectoryEmpty?()?斷言,assertJsonPath?()?中的閉包等:

對集合?Implode?方法的回調(diào)支持

@Lito?貢獻(xiàn)了在?Collect::implode()?上的回調(diào)支持,?以簡化?->map()->implode()?調(diào)用:

// 之前<br>{{ $user-&gt;cities-&gt;map(fn ($city) =&gt; $city-&gt;name.' ('.$city-&gt;state-&gt;name.')')-&gt;implode(', ') }}<br>// 使用回調(diào) <br>{{ $user-&gt;cities-&gt;implode(fn ($city) =&gt; $city-&gt;name.' ('.$city-&gt;state-&gt;name.')', ', ') }}<br>

使用?Storage?Fake?斷言一個空目錄

Mark?Beech?貢獻(xiàn)了使用?Storage::fake?()?實例斷言空目錄的能力:

// 9.5 版本之前<br>$this-&gt;assertEmpty(Storage::disk('temp')-&gt;allFiles('/foo'));<br>// +9.5<br>Storage::disk('temp')-&gt;assertDirectoryEmpty('/foo');<br>

如果目錄中沒有文件,只有其他子目錄,則斷言將失敗,因為它包含其他文件夾?/?文件。這里有一個來自?pull?request?discussion?的例子:

Storage::fake('temp');<br>Storage::disk('temp')-&gt;put('/foo/bar.txt', 'string');<br>Storage::disk('temp')-&gt;assertDirectoryEmpty('/'); // 失敗<br>

JSON?斷言?“assertJsonPath?()”?現(xiàn)在接受閉包

Fabien?Villepinte?貢獻(xiàn)了將閉包傳遞給?assertJsonPath?的,沒有任何向后兼容的中斷的能力:

$response = TestResponse::fromBaseResponse(new Response([<br>    'data' =&gt; ['foo' =&gt; 'bar'],<br>]));<br>$response-&gt;assertJsonPath('data.foo', 'bar');<br>$response-&gt;assertJsonPath('data.foo', fn ($value) =&gt; $value === 'bar');<br>

雖然上面的示例使用字符串版本似乎更簡單,但如果你需要圍繞路徑斷言更復(fù)雜的邏輯,你現(xiàn)在可以使用閉包。

部分隊列偽造

Taylor?Otwell?為測試中的隊列貢獻(xiàn)了部分偽造:

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

創(chuàng)建?“through”?模型的新方法

Hafez?Divandari?貢獻(xiàn)了不需要覆蓋整個?hasOneThrough?或者?hasManyThrough?方法而創(chuàng)建一個新的?“through”?模型的能力:

// Define a `newThroughInstance` method<br>protected function newThroughInstance($resource)<br>{<br>    return (new AppModelsExampleEntity)-&gt;setTable($resource);<br>}<br>

新的字符串換行的輔助函數(shù)

Markus?Hebenstreit?貢獻(xiàn)了?wrap()?字符串輔助函數(shù)。?這里有一個來自?pull?request?description?的示例用法:

Str:wrap('value')-&gt;wrap('"');<br>Str::of('value')-&gt;wrap('"');<br>str('value')-&gt;wrap('"');<br>// 輸出: "value"<br>Str:wrap('is', 'This ', ' me!');<br>Str::of('is')-&gt;wrap('This ', ' me!');<br>str('is')-&gt;wrap('This ', ' me!');<br>// 輸出: This is me!<br>

用于測試的?Freeze?Time?輔助函數(shù)

@Italo?貢獻(xiàn)了?freezeTime()?輔助函數(shù)?——?一個將在測試中凍結(jié)當(dāng)前時間的測試方法:

public function test_something()<br>{<br>    $this-&gt;freezeTime();<br>    // 或?qū)r間設(shè)置為日期的當(dāng)前秒<br>    // 沒有亞秒級精度。<br>    $this-&gt;freezeSecond();<br>}<br>

freezeTime()?方法是以下內(nèi)容的語法糖:

$this-&gt;travelTo(Carbon::now());<br>

允許在?Http::beforeSending?()?中接受可調(diào)用對象

Dries?Vints?有助于在?Http::beforeSending()?方法中接受可調(diào)用對象,而不僅僅是可調(diào)用的類。?現(xiàn)在,以下示例將起作用,而不是獲取?“調(diào)用數(shù)組上的成員函數(shù)?__invoke?()”:

Http::baseUrl('https://api.example.org')<br>    -&gt;beforeSending([ $this, 'prepareRequest' ])<br>    -&gt;asJson()<br>    -&gt;withoutVerifying();<br>

發(fā)行說明

你可以在下面查看新功能和更新的完整列表以及在?GitHub?上查?9.4.0?和?9.5.0?之間的差異?。?以下發(fā)行說明直接來自?changelog:

9.5.0?版本

新增

  • 增加了對?implode?集合方法的回調(diào)支持。(laravel)

  • 增加了?Illuminate/Filesystem/FilesystemAdapter::assertDirectoryEmpty()。?(laravel)

  • 為?SesTransport?實施郵件?“元數(shù)據(jù)”。?(laravel)

  • 使?assertPath?()?接受閉包。(laravel)

  • 在集合上增加了對?operatorForWhere?的可調(diào)用支持。?(laravel,?laravel)

  • 增加了部分隊列偽造。(laravel)

  • 為?schedule:test?命令添加了?–name?選項。?(laravel)

  • 定義了?Illuminate/Database/Eloquent/Concerns/HasRelationships::newRelatedThroughInstance()。(laravel)

  • 增加了?Illuminate/Support/Stringable::wrap()?(laravel)

  • 為測試增加了?“freezeTime”?輔助函數(shù)。(laravel)

  • 允許在?Illuminate/Http/Client/PendingRequest.php::runBeforeSendingCallbacks()?中使用?beforeSending?調(diào)用。(laravel)

修復(fù)

  • 修復(fù)了在過濾名稱或域時來自?route:list?的棄用警告。?(laravel)

  • 修復(fù)了當(dāng)?URL?返回空狀態(tài)碼時的?HTTP::pool?響應(yīng)。?(laravel)

  • 修復(fù)了?Illuminate/Session/Middleware/AuthenticateSession.php?中的?recaller?名稱解析。(laravel)

  • 修復(fù)了在?/Illuminate/Session/Middleware/AuthenticateSession.php?中被使用的?guard?實例?(laravel)

  • 修復(fù)了?route:list?–except-vendor,用于隱藏?Route::view?()?&?Route::redirect?()?(laravel)

改變

  • 在?IlluminateDatabaseEloquentFactoriesFactory?中為連接屬性添加空類型。(laravel)

  • 更新了?GeneratorCommand?中的保留名稱?(laravel)

  • 重新設(shè)計了?php?artisan?schedule:list?命令。?(laravel)

  • 擴(kuò)展了?eloquent?高階代理屬性。(laravel)

  • 允許傳遞已經(jīng)命名的參數(shù)給動態(tài)的本地作用域。(laravel)

  • 如果標(biāo)簽通過但在?Illuminate/Encryption/Encrypter.php?中不受支持,則拋出異常。(laravel)

  • 當(dāng)?composer?vendor?文件夾不在項目的文件夾時?為案例更新?PackageManifest::$vendorPath?初始化。(laravel)

【相關(guān)推薦:laravel

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點贊9 分享