/**
  * @param HeadlessInterface|\PHPUnit_Framework_Test $test
  */
 protected function bootHeadless($test)
 {
     if (CIVICRM_UF !== 'UnitTests') {
         throw new \RuntimeException('HeadlessInterface requires CIVICRM_UF=UnitTests');
     }
     // Hrm, this seems wrong. Shouldn't we be resetting the entire session?
     $session = \CRM_Core_Session::singleton();
     $session->set('userID', NULL);
     $test->setUpHeadless();
     $config = \CRM_Core_Config::singleton(TRUE, TRUE);
     // ugh, performance
     \CRM_Utils_System::flushCache();
     \Civi::reset();
     \CRM_Core_Session::singleton()->set('userID', NULL);
     if (property_exists($config->userPermissionClass, 'permissions')) {
         $config->userPermissionClass->permissions = NULL;
     }
 }