PackageManagerKernelTestBase::assertResults does not give helpful error message if asserting results are empty fails

Created on 27 January 2023, over 1 year ago

Problem/Motivation

because PackageManagerKernelTestBase::assertResults()

// If we did not get an exception, ensure we didn't expect any results.
      $this->assertEmpty($expected_results);

If a test fails because the results are not empty you will just see

Failed asserting that an array is not empty.

which is not very helpful

Steps to reproduce

To force a failed test like what might happen in debugging an issue

  1. add return statement to the top of \Drupal\package_manager\Validator\LockFileValidator::validateStagePreOperation so we never add an error
  2. Run \Drupal\Tests\package_manager\Kernel\LockFileValidatorTest::testLockFileChanged which expects an error
  3. get the error "Failed asserting that an array is not empty."

Proposed resolution

replace

$this->assertEmpty($expected_results);

with

$this->assertValidationResultsEqual([], $expected_results);

which will show the error we were expecting

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024