Commit 55092dc7 authored by catch's avatar catch

Issue #2059313 by StephaneQ, giammi: Cache simpletest_phpunit_get_available_tests().

parent 375a7081
...@@ -589,6 +589,7 @@ function simpletest_clean_environment() { ...@@ -589,6 +589,7 @@ function simpletest_clean_environment() {
// Detect test classes that have been added, renamed or deleted. // Detect test classes that have been added, renamed or deleted.
cache()->delete('simpletest'); cache()->delete('simpletest');
cache()->delete('simpletest_phpunit');
} }
/** /**
...@@ -718,25 +719,35 @@ function simpletest_library_info() { ...@@ -718,25 +719,35 @@ function simpletest_library_info() {
* If TRUE, returns a flat array of class names only. * If TRUE, returns a flat array of class names only.
*/ */
function simpletest_phpunit_get_available_tests() { function simpletest_phpunit_get_available_tests() {
// Load the PHPUnit configuration file, which tells us where to find the // Try to load the class names array from cache.
// tests. if ($cache = \Drupal::cache()->get('simpletest_phpunit')) {
$phpunit_config = simpletest_phpunit_configuration_filepath(); $test_classes = $cache->data;
$configuration = PHPUnit_Util_Configuration::getInstance($phpunit_config); }
// Find all the tests and get a list of unique class names. else {
$test_suite = $configuration->getTestSuiteConfiguration(NULL); // If there was no cached data available we have to find the tests.
$test_classes = array(); // Load the PHPUnit configuration file, which tells us where to find the
foreach ($test_suite AS $test) { // tests.
// PHPUnit returns a warning message if something is wrong with a test, $phpunit_config = simpletest_phpunit_configuration_filepath();
// throw an exception to avoid an error when trying to call getInfo() on $configuration = PHPUnit_Util_Configuration::getInstance($phpunit_config);
// this. // Find all the tests and get a list of unique class names.
if ($test instanceof PHPUnit_Framework_Warning) { $test_suite = $configuration->getTestSuiteConfiguration(NULL);
throw new RuntimeException($test->getMessage()); $test_classes = array();
} foreach ($test_suite as $test) {
// PHPUnit returns a warning message if something is wrong with a test,
// throw an exception to avoid an error when trying to call getInfo() on
// this.
if ($test instanceof PHPUnit_Framework_Warning) {
throw new RuntimeException($test->getMessage());
}
$name = get_class($test); $name = get_class($test);
if (!array_key_exists($name, $test_classes)) { if (!array_key_exists($name, $test_classes)) {
$test_classes[$name] = $test->getInfo(); $test_classes[$name] = $test->getInfo();
}
} }
// Since we have recalculated, we now need to store the new data into cache.
\Drupal::cache()->set('simpletest_phpunit', $test_classes);
} }
return $test_classes; return $test_classes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment