什么是callable-fake?怎么使用?-创新互联
什么是callable-fake?怎么使用?相信很多人对php中的callable-fake不了解,小编给大家总结了以下内容。如下资料是关于callable-fake的内容。
Callable fake 是 Tim Macdonald 的一个 PHP 测试实用程序,它 “允许您伪造、捕获和断言对可调用 / 闭包的调用”。在某些情况下,此包可以帮助在测试中允许开发人员传递一个 callable。
它有一个受 Laravel 虚构启发的 API,如下所示:
// Before, you might collect callables to assert later... public function testEachLoopsOverAllDependencies(): void { // arrange $received = []; $expected = factory(Dependency::class)->times(2)->create(); $repo = $this->app[DependencyRepository::class]; // act $repo->each(function (Dependency $dependency) use (&$received): void { $received[] = $dependency; }); // assert $this->assertCount(2, $received); $this->assertTrue($expected[0]->is($received[0])); $this->assertTrue($expected[1]->is($received[1])); }
使用此软件包,您可以使用类似以下内容的内容:
public function testEachLoopsOverAllDependencies(): void { // arrange $callable = new CallableFake(); $expected = factory(Dependency::class)->times(2)->create(); $repo = $this->app[DependencyRepository::class]; // act $repo->each($callable); // assert $callable->assertTimesInvoked(2); $callable->assertCalled(function (Depedency $dependency) use ($expected): bool { return $dependency->is($expected[0]); }); $callable->assertCalled(function (Dependency $dependency) use ($expected): bool { return $dependency->is($expected[1]); }); }
该包提供了诸如 assertCalled、assertNotCalled、assertInvoked 等断言。有关详细信息和示例,请务必查看项目自述文件中的可用 assertions 的完整列表。
以上就是callable-fake的详细介绍,代码详细清楚,如果在日常工作遇到这个问题,希望你能通过这篇文章解决问题。如果想了解更多相关内容,欢迎关注创新互联成都网站设计公司行业资讯频道!
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站题目:什么是callable-fake?怎么使用?-创新互联
网站路径:http://ybzwz.com/article/ppoep.html