首頁  >  文章  >  php框架  >  歸納Laravel 9.5版本的新增、修復與改變!

歸納Laravel 9.5版本的新增、修復與改變!

WBOY
WBOY轉載
2022-03-21 09:57:162522瀏覽

這篇文章為大家帶來了關於laravel的相關知識,Laravel團隊發布了9.5 版本,其中包括部分隊列偽造,freezeTime()輔助函數,存儲assertDirectoryEmpty()斷言等等,希望對大家有幫助。

歸納Laravel 9.5版本的新增、修復與改變!

【相關推薦:laravel影片

Laravel 團隊發布了 9.5 版本,其中包括部分隊列偽造,freezeTime ()輔助函數,儲存 assertDirectoryEmpty () 斷言,assertJsonPath () 中的閉包等:

對集合 Implode 方法的回呼支持

#@Lito 貢獻了在 Collect::implode()回呼支持, 以簡化 ->map()->implode() 調用:

// 之前<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/>

使用 Storage Fake 斷言一個空目錄

Mark Beech 貢獻了使用 Storage::fake (

Mark Beech 貢獻了使用 Storage::fake (

Mark Beech 貢獻了使用 Storage::fake (

Mark Beech 貢獻了使用 Storage::fake (

Mark Beech 貢獻了使用 Storage)實例斷言空目錄的能力:

// 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/>

如果目錄中沒有文件,只有其他子目錄,則斷言將失敗,因為它包含其他資料夾 / 檔案。這裡有一個來自 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/>

JSON 斷言 「assertJsonPath ()」 現在接受閉包

Fabien Villepinte 使用了將閉包傳給 asserasserJsonPath相容的中斷的能力:

$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/>

雖然上面的範例使用字串版本似乎更簡單,但如果你需要圍繞路徑斷言更複雜的邏輯,你現在可以使用閉包。

部分隊列偽造

Taylor Otwell 為測試中的隊列貢獻了部分偽造:

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

創建 「through」 模型的新方法

Hafez Divandari貢獻了不需要涵蓋整個 hasOneThrough 或 hasManyThrough 方法而創建一個新的 「through」 模型的能力:

// Define a `newThroughInstance` method<br/>protected function newThroughInstance($resource)<br/>{<br/>    return (new \App\Models\ExampleEntity)->setTable($resource);<br/>}<br/>

新的字串換行的輔助函數

Markus Hebenstreit字串輔助函數。這裡有一個來自 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/>

#用於測試的 Freeze Time 輔助函數

@Italo 貢獻了 freezeTime() 輔助函數 - 一個將在測試中凍結目前時間的測試方法:

public function test_something()<br/>{<br/>    $this->freezeTime();<br/>    // 或将时间设置为日期的当前秒<br/>    // 没有亚秒级精度。<br/>    $this->freezeSecond();<br/>}<br/>

freezeTime() 方法是以下內容的語法糖:

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

允許在 Http::beforeSending () 中接受可呼叫物件Dries Vints 有助於在 Http::beforeSending() 方法中接受可呼叫對象,而不僅僅是可呼叫的類別。現在,以下範例將會起作用,而不是取得 「呼叫數組上的成員函數 __invoke ()」:

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

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

修復

  • 修復了在篩選名稱或網域時來自route:list 的棄用警告。 (#41421)

  • 修正了當 URL 傳回空狀態碼時的 HTTP::pool 回應。 (#41412)

  • 修正了 Illuminate/Session/Middleware/AuthenticateSession.php 中的 recaller 名稱解析。 (#41429)

  • 修正了在 /Illuminate/Session/Middleware/AuthenticateSession.php 中被使用的 guard )

  • 修正了 route:list –except-vendor,用於隱藏 Route::view () & Route::redirect () (
  • #41465

    )

改變

    在 \Illuminate\Database\Eloquent\Factories\Factory 中為連線屬性新增空白類型。 (
  • #41418

    )

  • 更新了 GeneratorCommand 中的保留名稱 (
  • #41441

    )

  • #重新設計了 php artisan schedule:list 命令。 (
  • #41445

    )

  • 擴充了 eloquent 高階代理屬性。 (
  • #41449

    )

  • 允許傳遞已命名的參數給動態的本地作用域。 (
  • #41478

    )

  • 如果標籤通過但在 Illuminate/Encryption/Encrypter.php 中不受支持,則拋出例外。 (
  • #41479

    )

  • 當 composer vendor 資料夾不在專案的資料夾時 為案例更新 PackageManifest::$vendorPath 初始化。 (
  • #41463

    )

  • 【相關推薦:
laravel影片教學

以上是歸納Laravel 9.5版本的新增、修復與改變!的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:learnku.com。如有侵權,請聯絡admin@php.cn刪除