Beispiel #1
0
 /**
  * Performs the primary task and adds an execute publisher to the config.xml.
  * 
  * @return void
  */
 public function execute()
 {
     $out = phpucConsoleOutput::get();
     $out->writeLine('Performing ezcGraph task.');
     $installDir = $this->args->getArgument('cc-install-dir');
     $projectName = $this->args->getOption('project-name');
     $out->startList();
     $out->writeListItem('Modifying config file: config.xml');
     $configFile = new phpucConfigFile($installDir . '/config.xml');
     $configProject = $configFile->getProject($projectName);
     $publisher = $configProject->createExecutePublisher();
     $binary = sprintf('%s/phpuc', PHPUC_BIN_DIR);
     if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) {
         $binary .= '.bat';
     } else {
         if (!file_exists($binary)) {
             $binary .= '.php';
         }
     }
     // Build default command string
     $command = sprintf('%s graph logs/${project.name}', $binary);
     // Check for an artifacts directory
     if ($this->artifacts) {
         $command .= ' artifacts/${project.name}';
     }
     $publisher->command = $command;
     $configFile->store();
     $out->writeLine();
 }
 /**
  * Sets the required binary contents.
  *
  * @return void
  */
 protected function setUp()
 {
     parent::setUp();
     if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) {
         $this->validBin = "@echo off\n\recho version 1.2.0";
     }
 }
 /**
  * Validates the existing PHPUnit version.
  *
  * @return void
  */
 protected function doValidate()
 {
     $binary = basename($this->executable);
     if (($execdir = dirname($this->executable)) !== '.') {
         chdir($execdir);
         if (phpucFileUtil::getOS() === phpucFileUtil::OS_UNIX) {
             $binary = "./{$binary}";
         }
     }
     // Check Xdebug installation
     if (extension_loaded('xdebug') === false) {
         phpucConsoleOutput::get()->writeLine('NOTICE: The xdebug extension is not installed. For coverage');
         phpucConsoleOutput::get()->writeLine('you must install xdebug with the following command:');
         phpucConsoleOutput::get()->writeLine('  pecl install pecl/xdebug');
         $this->properties['coverage'] = false;
     }
 }
Beispiel #4
0
 /**
  * Does the primary validation that the command line tool exists. If the
  * tool exists this method passes the request to the internal template 
  * method {@link doValidate()}.
  *
  * @return void
  * 
  * @throws phpucValidateException If the validation fails.
  */
 public final function validate()
 {
     // Get possible or configured pear path
     if ($this->pearBinaryDir === null) {
         $paths = explode(PATH_SEPARATOR, getenv('PATH'));
     } else {
         $paths = array($this->pearBinaryDir);
     }
     $paths = array_unique($paths);
     $windows = phpucFileUtil::getOS() == phpucFileUtil::OS_WINDOWS;
     foreach ($paths as $path) {
         $fileName = sprintf('%s/%s%s', $path, $this->cliTool, $windows === true ? '.bat' : '');
         if (file_exists($fileName) === false) {
             continue;
         }
         if (is_executable($fileName) === false && $windows === false) {
             continue;
         }
         $this->properties['executable'] = $fileName;
         break;
     }
     if ($this->executable === null) {
         throw new phpucValidateException("Missing cli tool '{$this->cliTool}', check the PATH variable.");
     } else {
         if ($this->pearBinaryDir === null) {
             $dir = dirname($this->executable);
             if (strpos(getenv('PATH'), $dir) !== false) {
                 $this->properties['executable'] = basename($this->executable);
             }
         }
     }
     $this->doValidate();
 }
 /**
  * Validates the existing code sniffer version.
  *
  * @return void
  */
 protected function doValidate()
 {
     $cwd = $this->getWorkingDirectory();
     $binary = basename($this->executable);
     if (($execdir = dirname($this->executable)) !== '.') {
         chdir($execdir);
         if (phpucFileUtil::getOS() === phpucFileUtil::OS_UNIX) {
             $binary = "./{$binary}";
         }
     }
     $regexp = '/version\\s+([0-9\\.]+(RC[0-9])?)/';
     $retval = exec(escapeshellcmd("{$binary} --version"));
     chdir($cwd);
     if (preg_match($regexp, $retval, $match) === 0) {
         phpucConsoleOutput::get()->writeLine('WARNING: Cannot identify PHP_CodeSniffer version.');
         // Assume valid version
         $version = self::CODE_SNIFFER_VERSION;
     } else {
         $version = $match[1];
     }
     if (version_compare($version, self::CODE_SNIFFER_VERSION) < 0) {
         throw new phpucValidateException(sprintf('PHP_CodeSniffer version %s or higher required.' . ' Given version is "%s".', self::CODE_SNIFFER_VERSION, $version));
     }
 }
 /**
  * Creates a fake executable. 
  *
  * @param string $executable The executable name.
  * @param string $content    Dummy/test content for the executable.
  * 
  * @return void
  */
 protected function createExecutable($executable, $content)
 {
     if (!is_dir(PHPUC_TEST_DIR . '/bin')) {
         mkdir(PHPUC_TEST_DIR . '/bin');
     }
     if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) {
         $executable .= '.bat';
     }
     $fileName = PHPUC_TEST_DIR . '/bin/' . $executable;
     file_put_contents($fileName, $content);
     chmod($fileName, 0755);
 }
 /**
  * Sets the required binary contents.
  *
  * @return void
  */
 protected function setUp()
 {
     parent::setUp();
     $this->clearTestContents(PHPUC_TEST_DIR . '/projects');
     $this->clearTestContents(PHPUC_TEST_DIR . '/build');
     $this->clearTestContents(PHPUC_TEST_DIR . '/logs');
     if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) {
         $this->badBin = "@echo off\n\recho version-3.2.0";
         $this->validBin = "@echo off\n\recho version 3.2.0";
         $this->invalidBin = "@echo off\n\recho version 3.1.9";
     }
 }
 /**
  * Tests that the {@link phpucFileUtil::getOS()} method detects the correct
  * operation system.
  *
  * @return void
  */
 public function testGetOperationSystem()
 {
     $this->assertEquals($this->os, phpucFileUtil::getOS());
 }
 /**
  * Initializes the test environment.
  *
  * @return void
  */
 public static function init()
 {
     // Load phpUnderControl base class
     include_once PHPUC_SOURCE . '/PhpUnderControl.php';
     include_once PHPUC_SOURCE . '/Util/Autoloader.php';
     // Register autoload
     $autoloader = new phpucAutoloader();
     spl_autoload_register(array($autoloader, 'autoload'));
     // Load ezcBase class
     if (file_exists(PHPUC_EZC_BASE)) {
         include_once PHPUC_EZC_BASE;
         spl_autoload_register(array('ezcBase', 'autoload'));
     }
     include_once dirname(__FILE__) . '/ConsoleOutputBuffer.php';
     phpucConsoleOutput::set(new phpucConsoleOutputBuffer());
     if (!is_dir(PHPUC_TEST_DIR)) {
         mkdir(PHPUC_TEST_DIR);
     }
     self::$windows = phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS;
 }
 /**
  * Tries to find the ant home directory.
  *
  * @param string $installDir The CruiseControl installation directory.
  *
  * @return string
  */
 public function getAntHome($installDir)
 {
     if (count($ant = glob(sprintf('%s/apache-ant*', $installDir))) === 0) {
         if (file_exists($installDir . '/bin/ant')) {
             return $installDir;
         }
         $os = phpucFileUtil::getOS();
         if ($os !== phpucFileUtil::OS_WINDOWS) {
             $ant = shell_exec('which ant');
         }
         if (strstr(trim($ant), 'bin/ant')) {
             return substr($ant, 0, strlen($ant) - 7);
         }
         return false;
     } else {
         return array_pop($ant);
     }
 }