Пример #1
0
 /**
  * @param  string $className
  * @return PHPUnit_Framework_TestSuite
  */
 public static function suite($className)
 {
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->setName($className);
     $class = new ReflectionClass($className);
     $classGroups = PHPUnit_Util_Test::getGroups($className);
     $staticProperties = $class->getStaticProperties();
     if (defined('XLITE_TEST_BROWSERS_LIST')) {
         $staticProperties['browsers'] = unserialize(XLITE_TEST_BROWSERS_LIST);
     }
     // Leave only one browser in deployment mode
     if (defined('DEPLOYMENT_TEST') && !empty($staticProperties['browsers'])) {
         $_browsers = array();
         foreach ($staticProperties['browsers'] as $key => $value) {
             $_browsers[$key] = $value;
             break;
         }
         $staticProperties['browsers'] = $_browsers;
     }
     // Create tests from Selenese/HTML files.
     if (isset($staticProperties['seleneseDirectory']) && is_dir($staticProperties['seleneseDirectory'])) {
         $files = array_merge(self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.htm'), self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.html'));
         // Create tests from Selenese/HTML files for multiple browsers.
         if (!empty($staticProperties['browsers'])) {
             foreach ($staticProperties['browsers'] as $browser) {
                 $browserSuite = new PHPUnit_Framework_TestSuite();
                 $browserSuite->setName($className . ': ' . $browser['name']);
                 foreach ($files as $file) {
                     $browserSuite->addTest(new $className($file, array(), '', $browser), $classGroups);
                 }
                 $suite->addTest($browserSuite);
             }
         } else {
             foreach ($files as $file) {
                 $suite->addTest(new $className($file), $classGroups);
             }
         }
     }
     // Create tests from test methods for multiple browsers.
     if (!empty($staticProperties['browsers'])) {
         foreach ($staticProperties['browsers'] as $browser) {
             if (defined('NO_RESTORE')) {
                 $browserSuite = new PHPUnit_Framework_TestSuite();
             } else {
                 $browserSuite = new XLite_Tests_TestSuite();
             }
             $browserSuite->setName($className . ': ' . $browser['name']);
             foreach ($class->getMethods() as $method) {
                 if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
                     $name = $method->getName();
                     $data = PHPUnit_Util_Test::getProvidedData($className, $name);
                     $groups = PHPUnit_Util_Test::getGroups($className, $name);
                     // Test method with @dataProvider.
                     if (is_array($data) || $data instanceof Iterator) {
                         $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name);
                         foreach ($data as $_dataName => $_data) {
                             $dataSuite->addTest(new $className($name, $_data, $_dataName, $browser), $groups);
                         }
                         $browserSuite->addTest($dataSuite);
                     } else {
                         if ($data === FALSE) {
                             $browserSuite->addTest(new PHPUnit_Framework_Warning(sprintf('The data provider specified for %s::%s is invalid.', $className, $name)));
                         } else {
                             $browserSuite->addTest(new $className($name, array(), '', $browser), $groups);
                         }
                     }
                 }
             }
             $suite->addTest($browserSuite);
         }
     } else {
         foreach ($class->getMethods() as $method) {
             if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
                 $name = $method->getName();
                 $data = PHPUnit_Util_Test::getProvidedData($className, $name);
                 $groups = PHPUnit_Util_Test::getGroups($className, $name);
                 // Test method with @dataProvider.
                 if (is_array($data) || $data instanceof Iterator) {
                     $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name);
                     foreach ($data as $_dataName => $_data) {
                         $dataSuite->addTest(new $className($name, $_data, $_dataName), $groups);
                     }
                     $suite->addTest($dataSuite);
                 } else {
                     if ($data === FALSE) {
                         $suite->addTest(new PHPUnit_Framework_Warning(sprintf('The data provider specified for %s::%s is invalid.', $className, $name)));
                     } else {
                         $suite->addTest(new $className($name), $groups);
                     }
                 }
             }
         }
     }
     return $suite;
 }
Пример #2
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;
 }