PHP培训技术产品
选课中心 APP下载
当前位置:首页 > 技能类 > PHP培训 > 技术产品 > 【技术产品】【 callable-fake】虚构你的可调用函数以加速测试

【技术产品】【 callable-fake】虚构你的可调用函数以加速测试

更新时间:2020-05-19 17:19:29 来源: 阅读量:

【摘要】 对于初入门的php学习者肯定会有很多问题,今天考比过小编为大家整理了关于【技术产品】【 callable-fake】虚构你的可调用函数以加速测试的信息,希望可以帮助到大家。下面就让我们一起来看下【技术产品】【 callable-fake】虚构你的可调用函数以加速测试的具体内容吧!

【技术产品】【 callable-fake】虚构你的可调用函数以加速测试"Callable fake 是 Tim Macdonald 的一个 PHP 测试实用程序,它 “允许您伪造、捕获和断言对可调用 / 闭包的调用”。在某些情况下,此包可以帮助在测试中允许开发人员传递一个 callable。",
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 的完整列表。

你可以在 GitHub 上了解更多关于此软件包的信息,获取完整的安装说明,并在 timacdonald/callable-fake 上查看源代码。

以上就是【 callable-fake】虚构你的可调用函数以加速测试的详细内容,更多请关注考比过其它相关文章!

以上就是考比过小编为大家整理的【技术产品】【 callable-fake】虚构你的可调用函数以加速测试内容,希望可以帮助到你,如果你还有更多关于php的问题,请持续关注考比过php频道,小编会持续为大家分享关于php方面的知识!

分享到: 编辑:dada

技术产品关键词
  • 热门关键词
  • 热门问答