You are here

protected function PHPUnit_TextUI_Command::handleSelfUpdate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/TextUI/Command.php \PHPUnit_TextUI_Command::handleSelfUpdate()

@since Method available since Release 4.0.0

1 call to PHPUnit_TextUI_Command::handleSelfUpdate()
PHPUnit_TextUI_Command::handleArguments in vendor/phpunit/phpunit/src/TextUI/Command.php
Handles the command-line arguments.

File

vendor/phpunit/phpunit/src/TextUI/Command.php, line 773

Class

PHPUnit_TextUI_Command
A TestRunner for the Command Line Interface (CLI) PHP SAPI Module.

Code

protected function handleSelfUpdate() {
  $this
    ->printVersionString();
  $localFilename = realpath($_SERVER['argv'][0]);
  if (!is_writable($localFilename)) {
    print 'No write permission to update ' . $localFilename . "\n";
    exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
  }
  if (!extension_loaded('openssl')) {
    print "The OpenSSL extension is not loaded.\n";
    exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
  }
  if (PHP_VERSION_ID < 50600) {
    $remoteFilename = sprintf('https://phar.phpunit.de/phpunit-old.phar');
  }
  else {
    $remoteFilename = sprintf('https://phar.phpunit.de/phpunit.phar');
  }
  $tempFilename = tempnam(sys_get_temp_dir(), 'phpunit') . '.phar';

  // Workaround for https://bugs.php.net/bug.php?id=65538
  $caFile = dirname($tempFilename) . '/ca.pem';
  copy(__PHPUNIT_PHAR_ROOT__ . '/phar/ca.pem', $caFile);
  print 'Updating the PHPUnit PHAR ... ';
  $options = array(
    'ssl' => array(
      'allow_self_signed' => false,
      'cafile' => $caFile,
      'verify_peer' => true,
    ),
  );
  if (PHP_VERSION_ID < 50600) {
    $options['ssl']['CN_match'] = 'phar.phpunit.de';
    $options['ssl']['SNI_server_name'] = 'phar.phpunit.de';
  }
  file_put_contents($tempFilename, file_get_contents($remoteFilename, false, stream_context_create($options)));
  chmod($tempFilename, 0777 & ~umask());
  try {
    $phar = new Phar($tempFilename);
    unset($phar);
    rename($tempFilename, $localFilename);
    unlink($caFile);
  } catch (Throwable $_e) {
    $e = $_e;
  } catch (Exception $_e) {
    $e = $_e;
  }
  if (isset($e)) {
    unlink($caFile);
    unlink($tempFilename);
    print " done\n\n" . $e
      ->getMessage() . "\n";
    exit(2);
  }
  print " done\n";
  exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
}