Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 内腔包测试_Laravel_Unit Testing_Lumen - Fatal编程技术网

Laravel 内腔包测试

Laravel 内腔包测试,laravel,unit-testing,lumen,Laravel,Unit Testing,Lumen,我开发了流明包,但我不知道如何测试 在我的包中,我使用了全局方法config()和abort(),但是这种方法存在于bootstrap/app.php中,我的包中没有这个文件 我想用dummies类重新定义这个方法,但是当我测试一个方法时,我必须在测试类中只编写一个测试方法,在配置中进行更改,以便可以重新调用antoherconfigdummy类 这不实用,我想还有更好的 如果你愿意,我可以分享代码 ---编辑 例如: 类检查授权测试 public function testCanSeeOthe

我开发了流明包,但我不知道如何测试

在我的包中,我使用了全局方法
config()
abort()
,但是这种方法存在于
bootstrap/app.php中,我的包中没有这个文件

我想用dummies类重新定义这个方法,但是当我测试一个方法时,我必须在测试类中只编写一个测试方法,在配置中进行更改,以便可以重新调用antoher
config
dummy类

这不实用,我想还有更好的

如果你愿意,我可以分享代码

---编辑

例如:

类检查授权测试

public function testCanSeeOtherUserRoles()
{
    $this->assertTrue(CheckAuthorization::canSeeOtherUserRoles($user, $user));
}
类检查授权

static public function canSeeOtherUserRoles(Model $user_parent, Model $user_child)
{
    return self::roleIsParentOfDirectChild($user_parent, $user_child);
}

static public function canShowGroup(array $parent_group, string $child_group)
{
    $groupsHelper = new GroupsHelper();

    foreach ($parent_group as $group) {
        if (in_array($child_group, config('roles.roles'))) {
            return true;
        }
    }

    abort(403);
}
结果:

有1个错误:

1) ::testCanSeeOtherUserRoles
ReflectionException: Class config does not exist

为什么需要使用这些函数进行测试?这似乎违反直觉。当然,除非您正在测试此软件包是否安装在
Lumen
中,而不是…
Yi
或其他什么地方。在这种情况下,您只需要添加
Lumen
作为依赖项。谢谢,我已经更新了我的问题您应该为测试定义虚拟数据,而不是试图将其与生产数据集成。