Answer
When you do setUp you have to call parent::setUp(); first...
class CheckerTest extends TestCase
{
    private \User\Permission\Checker $model;
    protected function setUp(): void
    {
        parent::setUp();
        $this->model = app(\User\Permission\Checker::class);
    }
    public function testCheckerReturnsTrueWhenPermissionExists(): void
    {
        $permissions = new \User\Permission\Collection();
        $permissions->add(
            (new \User\Permission\Entity(1))
            ->setValue(
                \User\Permission::USER_VIEW->value
            )
        );
        $user = (new \User\Entity('1'))->setPermissions($permissions);
        $result = $this->model->check(
            \User\Permission::USER_VIEW,
            $user
        );
        $this->assertTrue($result);
    }
}
See how the parent setUp it is still setting up stuff.
0 comments:
Post a Comment
Thanks