Example #1
0
 function start($clientsCount)
 {
     $time = microtime(true);
     xlite_make_sql_backup();
     exec("rm /tmp/output*");
     $this->clientsCount = $clientsCount;
     while (true) {
         $this->run();
         while ($this->isRunning()) {
             sleep(5);
             $this->clean();
         }
         if ($this->isComplete()) {
             break;
         }
     }
     $this->resources->reset();
     $time = round(microtime(true) - $time, 2);
     print PHP_EOL . " Total time: " . $time . "sec";
     exec('cat /tmp/output-* > /tmp/phpunit.txt');
 }
Example #2
0
 /**
  * Make backup
  *
  * @return void
  * @see    ____func_see____
  * @since  1.0.11
  */
 protected function doMakeBackup($path)
 {
     ob_start();
     xlite_make_sql_backup($path);
     ob_end_clean();
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR . '/../.dev/tests/images');
     \Includes\Utils\FileManager::mkdirRecursive(LC_DIR . '/../.dev/tests/images');
     \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, LC_DIR . '/../.dev/tests/images/');
 }
Example #3
0
 /**
  * Creates the phpunit test suite
  *
  * @return XLite_Tests_TestSuite
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public static function suite()
 {
     $suite = new XLite_Tests_TestSuite(ROOT_TEST_SUITE_NAME);
     $deploy = null;
     $includes = false;
     $includeTests = array();
     $excludes = array();
     $ds = preg_quote(LC_DS, '/');
     if (defined('INCLUDE_ONLY_TESTS')) {
         $includes = array_map('trim', explode(',', INCLUDE_ONLY_TESTS));
         if (in_array('LOCAL_TESTS', $includes)) {
             $k = array_search('LOCAL_TESTS', $includes);
             unset($includes[$k]);
         }
         if (in_array('NOWEB', $includes)) {
             if (!defined('SELENIUM_DISABLED')) {
                 define('SELENIUM_DISABLED', true);
             }
             $k = array_search('NOWEB', $includes);
             unset($includes[$k]);
         }
         if (in_array('ONLYWEB', $includes)) {
             if (!defined('UNITS_DISABLED')) {
                 define('UNITS_DISABLED', true);
             }
             $k = array_search('ONLYWEB', $includes);
             unset($includes[$k]);
         }
         if (in_array('DEPLOY_DRUPAL', $includes)) {
             $deploy = 'Drupal';
         } elseif (in_array('DEPLOY_STANDALONE', $includes)) {
             $deploy = 'Standalone';
         }
         if (!is_null($deploy)) {
             if (!defined('UNITS_DISABLED')) {
                 define('UNITS_DISABLED', true);
             }
             $k = array_search('DEPLOY_' . strtoupper($deploy), $includes);
             if (!defined('DIR_TESTS')) {
                 define('DIR_TESTS', 'Deploy' . LC_DS . $deploy);
             }
             unset($includes[$k]);
         }
         if (in_array('W3C', $includes)) {
             if (!defined('W3C_VALIDATION')) {
                 define('W3C_VALIDATION', true);
             }
             $k = array_search('W3C', $includes);
             unset($includes[$k]);
         }
         foreach ($includes as $k => $v) {
             if ('-' == substr($v, 0, 1)) {
                 $excludes[] = substr($v, 1);
                 unset($includes[$k]);
             }
         }
         foreach ($includes as $k => $v) {
             $tmp = explode(':', $v, 2);
             $includes[$k] = $tmp[0];
             if (isset($tmp[1])) {
                 $includeTests[$tmp[0]] = $tmp[1];
             }
         }
     }
     if (isset($deploy) && !defined('DEPLOYMENT_TEST')) {
         define('DEPLOYMENT_TEST', true);
     }
     // Include abstract classes
     $classesDir = dirname(__FILE__);
     $pattern = '/^' . preg_quote($classesDir, '/') . '.*' . $ds . '(?:\\w*Abstract|A[A-Z][a-z]\\w*)\\.php$/Ss';
     $dirIterator = new RecursiveDirectoryIterator($classesDir . LC_DS);
     $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $filePath => $fileObject) {
         if (preg_match($pattern, $filePath, $matches)) {
             require_once $filePath;
         }
     }
     // Include fake classes
     if (!defined('DEPLOYMENT_TEST')) {
         $classesDir = dirname(__FILE__) . LC_DS . 'FakeClass' . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '.+\\.php$/Ss';
         $dirIterator = new RecursiveDirectoryIterator($classesDir . LC_DS);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($iterator as $filePath => $fileObject) {
             if (preg_match($pattern, $filePath, $matches)) {
                 require_once $filePath;
             }
         }
     }
     if (!isset($deploy) || !$deploy) {
         \Includes\Utils\FileManager::unlinkRecursive(__DIR__ . '/images');
         \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images');
         \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, __DIR__ . '/images/');
         xlite_make_sql_backup();
     }
     // Classes tests
     if (!defined('UNITS_DISABLED')) {
         $classesDir = dirname(__FILE__) . LC_DS . 'Classes' . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '(.*)\\.php$/';
         $dirIterator = new RecursiveDirectoryIterator($classesDir);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         $siterator = new XLite_Tests_SortedIterator($iterator);
         foreach ($siterator as $filePath) {
             if (preg_match($pattern, $filePath, $matches) && !empty($matches[1]) && !preg_match('/' . $ds . '(\\w+Abstract|A[A-Z][a-z]\\w+)\\.php$/Ss', $filePath) && !preg_match('/' . $ds . '(?:scripts|skins)' . $ds . '/Ss', $filePath)) {
                 $matched = str_replace(LC_DS, '/', $matches[1]);
                 if ((!$includes || static::isPatternInArray($matched, $includes)) && (!$excludes || !static::isPatternInArray($matched, $excludes))) {
                     $class = XLite_Tests_TestCase::CLASS_PREFIX . str_replace('/', '_', $matched);
                     require_once $filePath;
                     $suite->addTest(new XLite_Tests_TestSuite(new ReflectionClass($class)));
                     // Limit test range by a specific test if it was specified in call. Example: ./phpunit-report.sh Model/Zone:create
                     if (isset($includeTests[$matched])) {
                         eval($class . '::$testsRange = array($includeTests[$matched]);');
                     }
                 }
             }
         }
     }
     // Web tests
     if (!defined('SELENIUM_DISABLED')) {
         if (!defined('DIR_TESTS')) {
             define('DIR_TESTS', 'Web');
         }
         $classesDir = dirname(__FILE__) . LC_DS . constant('DIR_TESTS') . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '(.*)\\.php$/';
         $dirIterator = new RecursiveDirectoryIterator($classesDir);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         $siterator = new XLite_Tests_SortedIterator($iterator);
         foreach ($siterator as $filePath) {
             if (preg_match($pattern, $filePath, $matches) && !empty($matches[1]) && !preg_match('/' . $ds . '(\\w+Abstract|A[A-Z]\\w+)\\.php/Ss', $filePath) && !preg_match('/' . $ds . '(?:scripts|skins)' . $ds . '/Ss', $filePath)) {
                 $matched = str_replace(LC_DS, '/', $matches[1]);
                 if ((!$includes || static::isPatternInArray($matched, $includes)) && (!$excludes || !static::isPatternInArray($matched, $excludes))) {
                     $classPrefix = !isset($deploy) ? XLite_Tests_SeleniumTestCase::CLASS_PREFIX : 'XLite_Deploy_' . $deploy . '_';
                     $class = $classPrefix . str_replace('/', '_', $matched);
                     require_once $filePath;
                     $seleniumSuite = new PHPUnit_Framework_TestSuite();
                     $seleniumSuite->addTestSuite($class);
                     $suite->addTest($seleniumSuite);
                     // Limit test range by a specific test if it was specified in call. Example: ./phpunit-report.sh Model/Zone:create
                     if (isset($includeTests[$matched])) {
                         eval($class . '::$testsRange = array($includeTests[$matched]);');
                     }
                 }
             }
         }
     }
     error_reporting(E_ALL);
     return $suite;
 }