【 callable-fake】虚构你的可调用函数以加速测试_后端开发

【 callable-fake】虚构你的可调用函数以加速测试_后端开发,第1张

php如何将数组下标去掉_后端开发

php将数组下标去掉的方法是:可以使用array_values()函数来实现,具体代码如【array_values($arr)】。


该函数可以返回只包含数组中的所有的值的数组。


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]));
}

使用此软件包,您可以使用类似以下内容的内容:

php怎么禁止访问.php文件_后端开发

php禁止访问的方法:首先在打开需要紧张访问的php文件;然后在该文件的头部添加代码为“$fromurl="//www.xxx.net/";if( $_SERVER['HTTP_REFERER'] == "" ){...}”即可。


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】虚构你的可调用函数以加速测试的详细内容,更多请关注ki4网其它相关文章!

php怎么去除字符_后端开发

php去除字符的方法:首先创建一个用于实现去除字符功能的php文件;然后在文件中输入php代码为“echo str_replace("world","Shanghai","Hello world!");”;最后通过访问浏览器查看结果即可。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/558837.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2020-05-19
下一篇 2020-05-20

发表评论

登录后才能评论

评论列表(0条)

保存