它有一个受 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 的完整列表。
你可以在 GitHub 上了解更多关于此软件包的信息,获取完整的安装说明,并在 timacdonald/callable-fake 上查看源代码。 总结
以上是内存溢出为你收集整理的【 callable-fake】虚构你的可调用函数以加速测试全部内容,希望文章能够帮你解决【 callable-fake】虚构你的可调用函数以加速测试所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)