您的位置 首页 php

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

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

【相关推荐:laravel视频】

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

对集合 Implode 方法的回调支持

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

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

使用 Storage Fake 断言一个空目录

Mark Beech 贡献了使用 Storage::fake () 实例断言空目录的能力:

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

如果目录中没有文件,只有其他子目录,则断言将失败,因为它包含其他文件夹 / 文件。这里有一个来自 pull request discussion 的例子:

Storage::fake('temp');
Storage::disk('temp')->put('/foo/bar.txt', 'string');
Storage::disk('temp')->assertDirectoryEmpty('/'); // 失败

JSON 断言 “assertJsonPath ()” 现在接受闭包

Fabien Villepinte 贡献了将闭包传递给 assertJsonPath 的,没有任何向后兼容的中断的能力:

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

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

部分队列伪造

Taylor Otwell 为测试中的队列贡献了部分伪造:

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

创建 “through” 模型的新方法

Hafez Divandari 贡献了不需要覆盖整个 hasOneThrough 或者 hasManyThrough 方法而创建一个新的 “through” 模型的能力:

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

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

Markus Hebenstreit 贡献了 wrap() 字符串辅助函数。 这里有一个来自 pull request description 的示例用法:

Str:wrap('value')->wrap('"');
Str::of('value')->wrap('"');
str('value')->wrap('"');
// 输出: "value"
Str:wrap('is', 'This ', ' me!');
Str::of('is')->wrap('This ', ' me!');
str('is')->wrap('This ', ' me!');
// 输出: This is me!

用于测试的 Freeze Time 辅助函数

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

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

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

$this->travelTo(Carbon::now());

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

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

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

发行说明

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

9.5.0 版本

新增

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

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

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

  • 使 assertPath () 接受闭包。(#41409)

  • 在集合上增加了对 operatorForWhere 的可调用支持。 (#41414, #41424)

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

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

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

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

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

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

修复

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

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

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

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

  • 修复了 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版本的新增、修复和改变!

文章地址:https://www.zhihuclub.com/23755.shtml

关于作者: 智云科技

热门文章

网站地图