Since #1901670: Start using PHPUnit for unit tests the output of simpletest_script_get_test_list is expected to be something like:

array(
  'group' => array(
    'testclass1',
    'testclass2',
  ),
);

However if you use --module or --class then this function currently returns

array(
  'testclass1',
  'testclass2',
);

as it used too. This means that simpletest_script_execute_batch flattens the test_group array to an empty array and no tests are run.

So for example, without this patch the following command is a total fail...

$ php ./core/scripts/run-tests.sh --class "Drupal\book\Tests\BookTest"
Files: 
CommentFileSizeAuthor
#3 1936806.run-tests.2.patch4.88 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 52,487 pass(es).
[ View ]
#1 1936806.run-tests.1.patch1.17 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 52,426 pass(es).
[ View ]

Comments

alexpott’s picture

Status:Active» Needs review
StatusFileSize
new1.17 KB
PASSED: [[SimpleTest]]: [MySQL] 52,426 pass(es).
[ View ]

The patch attached is a comprise... basically instead of trying to determine the correct test group for --class and --module we just use 'class' and 'module' as the test group... this keeps us clear of the following code in simpletest_script_execute_batch()

  // Separate PHPUnit tests from simpletest.
  if (isset($test_groups['PHPUnit'])) {
    $phpunit_tests = $test_groups['PHPUnit'];
    unset($test_groups['PHPUnit']);
  }

whilst making this code work...

  // Flatten the simpletest tests into an array of classnames.
  $test_classes = array();
  foreach ($test_groups as $group) {
    $test_classes = array_merge($test_classes, array_values($group));
  }

The group key is only used by the PHPUnit additions to run_tests.sh so this change minimises the impact and just works.

alexpott’s picture

The patch attached reverts the change to pass test lists around keyed by group eg...

array(
  'group' => array(
    'testclass1',
    'testclass2',
  ),
);

And instead detects is the class is a PHPUnit test using is_subclass_of(). This means you can mix classes like this...

$ php ./core/scripts/run-tests.sh --class "Drupal\Tests\Core\Cache\NullBackendTest,Drupal\search\Tests\SearchBlockTest"

Where one test is PHPUnit and one test is a WebTestBase :)

alexpott’s picture

StatusFileSize
new4.88 KB
PASSED: [[SimpleTest]]: [MySQL] 52,487 pass(es).
[ View ]

Now for the patch

alexpott’s picture

+++ b/core/scripts/run-tests.shundefined
@@ -431,8 +418,8 @@ function simpletest_script_execute_batch($test_groups) {
@@ -459,7 +446,7 @@ function simpletest_script_run_phpunit($test_id, $phpunit_tests) {

@@ -459,7 +446,7 @@ function simpletest_script_run_phpunit($test_id, $phpunit_tests) {
         $summaries[$result['test_class']]['#exception']++;
         break;
       case 'debug':
-        $summary['#exception']++;
+        $summaries[$result['test_class']]['#debug']++;
         break;
     }

This patch also fixes this small bug with PHPUnit test summarisation.

msonnabaum’s picture

Totally fine with this. If testbot comes back ok, I think this is RTBC.

msonnabaum’s picture

Status:Needs review» Reviewed & tested by the community
catch’s picture

#3: 1936806.run-tests.2.patch queued for re-testing.

Dries’s picture

Status:Reviewed & tested by the community» Fixed

Committed to 8.x. Thanks.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary:View changes

Add example command