public function beforeScenario($event)
 {
     parent::beforeScenario($event);
     // @todo provide our own mail system to ameliorate ensuing ugliness.
     if ($event instanceof ScenarioEvent) {
         if ($event->getScenario()->hasTag('mail')) {
             if (module_exists('devel')) {
                 variable_set('mail_system', array('default-system' => 'DevelMailLog'));
             } else {
                 throw new \Exception('You must ensure that the devel module is enabled');
             }
             $fs = new \Filesystem();
             if ($mail_path = $event->getScenario()->getTitle()) {
                 $fs->remove('/tmp/' . $mail_path);
                 $fs->mkdir($mail_path);
             }
             variable_set('devel_debug_mail_directory', $mail_path);
             // NB: DevelMailLog is going to replace our separator with __.
             variable_set('devel_debug_mail_file_format', '%to::%subject');
             $this->mail = new \DevelMailLog();
         }
     }
     if (!$this->drupalSession) {
         $_SERVER['SERVER_SOFTWARE'] = 'foo';
         $this->drupalSession = (object) array('name' => session_name(), 'id' => session_id());
         $_SESSION['foo'] = 'bar';
         drupal_session_commit();
     }
     session_name($this->drupalSession->name);
     session_id($this->drupalSession->id);
     $_COOKIE[session_name()] = session_id();
     drupal_session_start();
     $base_url = getenv('DRUPAL_BASE_URL');
     if (!empty($base_url)) {
         $this->setMinkParameter('base_url', $base_url);
     }
     $userName = getenv('DRUPAL_BASIC_AUTH_USERNAME');
     $pass = getenv('DRUPAL_BASIC_AUTH_PASS');
     foreach (array('selenium2', 'goutte') as $session) {
         $session = $this->getMink()->getSession($session);
         $session->visit($this->locatePath('/index.php?foo=bar'));
         if (!empty($userName) && !empty($pass)) {
             $this->getMink()->getSession()->setBasicAuth($userName, $pass);
         }
     }
 }