Did you call parent::setUp in your setUp method in your test class?
Jun 28, 2018
4
Level 1
Test lumen package
I develop external package to be used in lumen.
In my package, I use global method config() and abort() who comes Lumen package .
I include Lumen like a dependency of my project but this classes are not initialize because I haven't bootstrap/app.php in my package.
So, PHPunit returns :
ReflectionException: Class config does not exist
I create dummy class to define this method but when I want variated the value of the config class, I need to create another config file, and another test class to inject this new config class inside.
It's not practical and I guess there's better.
Example :
public function testCanSeeOtherUserRoles()
{
$user = new \UserDummy(true, [
"superadmin" => [
'admin'
]
]);
$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);
}
Please or to participate in this conversation.