本篇文章给大家带来了关于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版本的新增、修复和改变!的详细内容。