By krzysztof domański on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.8.x
Introduced in version:
8.8.0-beta1
Issue links:
Description:
The assertTrue() and assertFalse() compatibility override has been deprecated from Drupal 8.8.0 and will be removed in Drupal 9. The tested condition in assertTrue/False() should be a Boolean. Conditions that return values that are not Booleans such as 1 or 0 are not longer supported. This makes these assertions behave the same way as vanilla PHPUnit.
Replace usages of assertTrue() or assertFalse() on non-Boolean values with another assert method. Helpful methods are:
assertEmpty()assertNotEmpty()assertCount()assertGreaterThan()assertEquals()assertSame()assertRegexp()assertInstanceOf()
The method to use depends on the assertion you are trying to make and the most semantically correct should be chosen.
Examples
Before
$this->assertTrue($count);
After
$this->assertGreaterThan(0, $count);
Before
$this->assertTrue(preg_match('/^"[a-z0-9]{32}"$/', $feed->getEtag()));
After
$this->assertRegExp('/^"[a-z0-9]{32}"$/', $feed->getEtag());
Before
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
After
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
Before
$block_type = BlockContentType::load('other');
$this->assertTrue($block_type, 'The new block type has been created.');
After
$block_type = BlockContentType::load('other');
$this->assertInstanceOf(BlockContentType::class, $block_type, 'The new block type has been created.');
Before
$xpath = $this->xpath('//div[contains(@class, :class)]', [':class' => $type]);
$this->assertTrue(count($xpath), new FormattableMarkup('Analyse messages with @type found', ['@type' => $type]));
After
// Check that analyse messages with the expected type found.
$this->assertSession()->elementExists('css', 'div.' . $type);
Impacts:
Module developers