once() ->with('init', \Mockery::any()); (new RoleManager())->register(); } public function testCreateRolesSkipsExistingRoles(): void { Functions\when('get_role')->alias(static fn() => new \stdClass()); Functions\expect('add_role')->never(); (new RoleManager())->createRoles(); } public function testCreateRolesAddsInstructorRoleWithCorrectCaps(): void { Functions\when('get_role')->alias(static function (string $role): ?object { return $role === RoleManager::INSTRUCTOR ? null : new \stdClass(); }); Functions\expect('add_role') ->once() ->with( RoleManager::INSTRUCTOR, \Mockery::any(), \Mockery::on(static function (array $caps): bool { return ($caps['read'] ?? false) === true && ($caps[RoleManager::CAP_MANAGE_AVAILABILITY] ?? false) === true && ($caps[RoleManager::CAP_VIEW_LESSONS] ?? false) === true; }) ); (new RoleManager())->createRoles(); } public function testCreateRolesAddsStudentRoleWithCorrectCaps(): void { Functions\when('get_role')->alias(static function (string $role): ?object { return $role === RoleManager::STUDENT ? null : new \stdClass(); }); Functions\expect('add_role') ->once() ->with( RoleManager::STUDENT, \Mockery::any(), \Mockery::on(static function (array $caps): bool { return ($caps['read'] ?? false) === true && ($caps[RoleManager::CAP_BOOK_LESSON] ?? false) === true && ($caps[RoleManager::CAP_VIEW_LESSONS] ?? false) === true; }) ); (new RoleManager())->createRoles(); } }