/**
  * Register a native Flow package
  *
  * @param PackageInterface $package The Package to be registered
  * @param boolean $sortAndSave allows for not saving packagestates when used in loops etc.
  * @return PackageInterface
  * @throws Exception\InvalidPackageStateException
  */
 public function registerPackage(PackageInterface $package, $sortAndSave = true)
 {
     $packageKey = $package->getPackageKey();
     $caseSensitivePackageKey = $this->getCaseSensitivePackageKey($packageKey);
     if ($this->isPackageAvailable($caseSensitivePackageKey)) {
         throw new Exception\InvalidPackageStateException('Package "' . $packageKey . '" is already registered as "' . $caseSensitivePackageKey . '".', 1338996122);
     }
     $this->packages[$packageKey] = $package;
     $this->packageStatesConfiguration['packages'][$packageKey]['packagePath'] = str_replace($this->packagesBasePath, '', $package->getPackagePath());
     $this->packageStatesConfiguration['packages'][$packageKey]['classesPath'] = str_replace($package->getPackagePath(), '', $package->getClassesPath());
     if ($sortAndSave === true) {
         $this->sortAndSavePackageStates();
     }
     return $package;
 }
 /**
  * Extracts the namespace from a package
  *
  * @param \TYPO3\Flow\Package\PackageInterface $package
  * @return void
  */
 protected function buildPackageNamespace(\TYPO3\Flow\Package\PackageInterface $package)
 {
     $packageNamespace = $package->getNamespace();
     // Ignore legacy extensions with unkown vendor name
     if ($packageNamespace[0] !== '*') {
         $this->packageNamespaces[$packageNamespace] = array('namespaceLength' => strlen($packageNamespace), 'classesPath' => $package->getClassesPath(), 'packagePath' => $package->getPackagePath(), 'substituteNamespaceInPath' => $package instanceof PackageInterface);
     }
 }
 /**
  * Creates a dummy class file inside $package's path
  * and requires it for propagation
  *
  * @param PackageInterface $package
  * @return object The dummy object of the class which was created
  */
 protected function createDummyObjectForPackage(PackageInterface $package)
 {
     $dummyClassName = 'Someclass' . md5(uniqid(mt_rand(), TRUE));
     $fullyQualifiedClassName = '\\' . $package->getNamespace() . '\\' . $dummyClassName;
     $dummyClassFilePath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getPackagePath(), PackageInterface::DIRECTORY_CLASSES, $dummyClassName . '.php'));
     file_put_contents($dummyClassFilePath, '<?php namespace ' . $package->getNamespace() . '; class ' . $dummyClassName . ' {}');
     require $dummyClassFilePath;
     return new $fullyQualifiedClassName();
 }
 /**
  * Return value is:
  * - 0 if unit tests ran through successfully,
  * - 1 or 2 if the tests failed or an error occured,
  * - 255 if a fatal error occured
  * - 137 ON TIMEOUT
  * - FALSE if the unit / functional test directory does not exist
  *
  *
  * @param \TYPO3\Flow\Package\PackageInterface $package
  * @param integer $timeout the timeout
  * @param string $testType either 'Unit' or 'Functional'
  * @param string $testPath path inside Tests/$testType
  * @param string $additionalArguments additional arguments to be passed to PHPUnit
  * @return null
  */
 protected function runPhpUnitForPackage(\TYPO3\Flow\Package\PackageInterface $package, $timeout, $testType, $testPath = '', $additionalArguments = '')
 {
     $output = array();
     $returnValue = NULL;
     if (!is_dir($package->getPackagePath() . 'Tests/' . $testType)) {
         return FALSE;
     }
     exec(sprintf('timeout %s %s -c %sBuild/BuildEssentials/PhpUnit/%sTests.xml %s %sTests/%s/%s 2>/dev/null', $timeout, $this->phpunitBinary, FLOW_PATH_ROOT, $testType, $additionalArguments, $package->getPackagePath(), $testType, $testPath), $output, $returnValue);
     return $returnValue;
 }