归纳Laravel 9.5版本的新增、修复和改变!

本篇文章给大家带来了关于laravel的相关知识,laravel团队发布了 9.5 版本,其中包括部分队列伪造,freezetime()辅助函数,存储assertdirectoryempty()断言等等,希望对大家有帮助。

归纳Laravel 9.5版本的新增、修复和改变!

【相关推荐:laravel

laravel 团队发布了 9.5 版本,其中包括部分队列伪造,freezeTime () 辅助函数,存储 assertDirectoryEmpty () 断言,assertJsonPath () 中的闭包等:

对集合 Implode 方法的回调支持

@Lito 贡献了在 Collect::implode() 上的回调支持, 以简化 ->map()->implode() 调用:

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

使用 Storage Fake 断言一个空目录

Mark Beech 贡献了使用 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 ()” 现在接受闭包

Fabien Villepinte 贡献了将闭包传递给 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>

虽然上面的示例使用字符串版本似乎更简单,但如果你需要围绕路径断言更复杂的逻辑,你现在可以使用闭包。

部分队列伪造

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 AppModelsExampleEntity)-&gt;setTable($resource);<br>}<br>

新的字符串换行的辅助函数

Markus Hebenstreit 贡献了 wrap() 字符串辅助函数。 这里有一个来自 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 辅助函数

@Italo 贡献了 freezeTime() 辅助函数 —— 一个将在测试中冻结当前时间的测试方法:

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

freezeTime() 方法是以下内容的语法糖:

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

允许在 Http::beforeSending () 中接受可调用对象

Dries Vints 有助于在 Http::beforeSending() 方法中接受可调用对象,而不仅仅是可调用的类。 现在,以下示例将起作用,而不是获取 “调用数组上的成员函数 __invoke ()”:

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

发行说明

你可以在下面查看新功能和更新的完整列表以及在 GitHub 上查 9.4.0 和 9.5.0 之间的差异 。 以下发行说明直接来自 changelog:

9.5.0 版本

新增

  • 增加了对 implode 集合方法的回调支持。(laravel)

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

  • 为 SesTransport 实施邮件 “元数据”。 (laravel)

  • 使 assertPath () 接受闭包。(laravel)

  • 在集合上增加了对 operatorForWhere 的可调用支持。 (laravellaravel)

  • 增加了部分队列伪造。(laravel)

  • 为 schedule:test 命令添加了 –name 选项。 (laravel)

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

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

  • 为测试增加了 “freezeTime” 辅助函数。(laravel)

  • 允许在 Illuminate/Http/Client/PendingRequest.php::runBeforeSendingCallbacks() 中使用 beforeSending 调用。(laravel)

修复

  • 修复了在过滤名称或域时来自 route:list 的弃用警告。 (laravel)

  • 修复了当 URL 返回空状态码时的 HTTP::pool 响应。 (laravel)

  • 修复了 Illuminate/Session/Middleware/AuthenticateSession.php 中的 recaller 名称解析。(laravel)

  • 修复了在 /Illuminate/Session/Middleware/AuthenticateSession.php 中被使用的 guard 实例 (laravel)

  • 修复了 route:list –except-vendor,用于隐藏 Route::view () & Route::redirect () (laravel)

改变

  • 在 IlluminateDatabaseEloquentFactoriesFactory 中为连接属性添加空类型。(laravel)

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

  • 重新设计了 php artisan schedule:list 命令。 (laravel)

  • 扩展了 eloquent 高阶代理属性。(laravel)

  • 允许传递已经命名的参数给动态的本地作用域。(laravel)

  • 如果标签通过但在 Illuminate/Encryption/Encrypter.php 中不受支持,则抛出异常。(laravel)

  • 当 composer vendor 文件夹不在项目的文件夹时 为案例更新 PackageManifest::$vendorPath 初始化。(laravel)

【相关推荐:laravel

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享