Issue #3204764 by longwave, mondrake: PHPUnit assertions do not return a value

merge-requests/469/head
catch 2021-03-22 10:00:18 +00:00
parent 768340bea5
commit 7e1043ea1d
17 changed files with 33 additions and 105 deletions

View File

@ -87,9 +87,6 @@ trait AssertMailTrait {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
$mails = $this->getMails();
@ -110,7 +107,7 @@ trait AssertMailTrait {
if (!$message) {
$message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $string]);
}
return $this->assertTrue($string_found, $message, $group);
$this->assertTrue($string_found, $message, $group);
}
/**
@ -130,9 +127,6 @@ trait AssertMailTrait {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
$mails = $this->getMails();
@ -141,7 +135,7 @@ trait AssertMailTrait {
if (!$message) {
$message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $regex]);
}
return $this->assertTrue((bool) $regex_found, $message, $group);
$this->assertTrue((bool) $regex_found, $message, $group);
}
/**

View File

@ -1139,12 +1139,9 @@ body {color:red}
* (optional) Message to display if failed. Defaults to an empty string.
* @param string $group
* (optional) The group this message belongs to. Defaults to 'Other'.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
public function assertNormalized($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertStringContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
$this->assertStringContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
}
/**
@ -1164,12 +1161,9 @@ body {color:red}
* (optional) Message to display if failed. Defaults to an empty string.
* @param string $group
* (optional) The group this message belongs to. Defaults to 'Other'.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
public function assertNoNormalized($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertStringNotContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
$this->assertStringNotContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
}
}

View File

@ -96,14 +96,11 @@ class UrlAlterFunctionalTest extends BrowserTestBase {
* A string with the original path that is run through generateFrommPath().
* @param $final
* A string with the expected result after generateFrommPath().
*
* @return
* TRUE if $original was correctly altered to $final, FALSE otherwise.
*/
protected function assertUrlOutboundAlter($original, $final) {
// Test outbound altering.
$result = $this->container->get('path_processor_manager')->processOutbound($original);
return $this->assertSame($final, $result, new FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
$this->assertSame($final, $result, new FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
}
/**
@ -113,14 +110,11 @@ class UrlAlterFunctionalTest extends BrowserTestBase {
* The original path before it has been altered by inbound URL processing.
* @param $final
* A string with the expected result.
*
* @return
* TRUE if $original was correctly altered to $final, FALSE otherwise.
*/
protected function assertUrlInboundAlter($original, $final) {
// Test inbound altering.
$result = $this->container->get('path_alias.manager')->getPathByAlias($original);
return $this->assertSame($final, $result, new FormattableMarkup('Altered inbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
$this->assertSame($final, $result, new FormattableMarkup('Altered inbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
}
}

View File

@ -79,14 +79,11 @@ class ConfirmFormTest extends BrowserTestBase {
* The assert message.
* @param string $group
* The assertion group.
*
* @return bool
* Result of the assertion.
*/
public function assertCancelLinkUrl(Url $url, $message = '', $group = 'Other') {
$links = $this->xpath('//a[@href=:url]', [':url' => $url->toString()]);
$message = ($message ? $message : new FormattableMarkup('Cancel link with URL %url found.', ['%url' => $url->toString()]));
return $this->assertTrue(isset($links[0]), $message, $group);
$this->assertTrue(isset($links[0]), $message, $group);
}
}

View File

@ -47,9 +47,9 @@ abstract class ModuleTestBase extends BrowserTestBase {
$tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%');
if ($count) {
return $this->assertNotEmpty($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table]));
$this->assertNotEmpty($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table]));
}
return $this->assertEmpty($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table]));
$this->assertEmpty($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table]));
}
/**
@ -67,7 +67,7 @@ abstract class ModuleTestBase extends BrowserTestBase {
$tables_exist = FALSE;
}
}
return $this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module]));
$this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module]));
}
/**
@ -85,7 +85,7 @@ abstract class ModuleTestBase extends BrowserTestBase {
$tables_exist = TRUE;
}
}
return $this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module]));
$this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module]));
}
/**
@ -93,11 +93,6 @@ abstract class ModuleTestBase extends BrowserTestBase {
*
* @param string $module
* The name of the module.
*
* @return bool|null
* TRUE if configuration has been installed, FALSE otherwise. Returns NULL
* if the module configuration directory does not exist or does not contain
* any configuration files.
*/
public function assertModuleConfig($module) {
$module_config_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
@ -131,7 +126,7 @@ abstract class ModuleTestBase extends BrowserTestBase {
}
// Verify that all configuration has been installed (which means that $names
// is empty).
return $this->assertEmpty($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module]));
$this->assertEmpty($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module]));
}
/**
@ -139,13 +134,10 @@ abstract class ModuleTestBase extends BrowserTestBase {
*
* @param string $module
* The name of the module.
*
* @return bool
* TRUE if no configuration was found, FALSE otherwise.
*/
public function assertNoModuleConfig($module) {
$names = \Drupal::configFactory()->listAll($module . '.');
return $this->assertEmpty($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module]));
$this->assertEmpty($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module]));
}
/**

View File

@ -248,13 +248,9 @@ class SessionHttpsTest extends BrowserTestBase {
* The insecure session ID to search for.
* @param $assertion_text
* The text to display when we perform the assertion.
*
* @return
* The result of assertTrue() that there's a session in the system that
* has the given insecure and secure session IDs.
*/
protected function assertSessionIds($sid, $assertion_text) {
return $this->assertNotEmpty(\Drupal::database()->select('sessions', 's')->fields('s', ['timestamp'])->condition('sid', Crypt::hashBase64($sid))->execute()->fetchField(), $assertion_text);
$this->assertNotEmpty(\Drupal::database()->select('sessions', 's')->fields('s', ['timestamp'])->condition('sid', Crypt::hashBase64($sid))->execute()->fetchField(), $assertion_text);
}
/**

View File

@ -166,12 +166,9 @@ class ErrorHandlerTest extends BrowserTestBase {
/**
* Asserts that no messages are printed onto the page.
*
* @return bool
* TRUE, if there are no messages.
*/
protected function assertNoMessages() {
return $this->assertEmpty($this->xpath('//div[contains(@class, "messages")]'), 'Ensures that also no messages div exists, which proves that no messages were generated by the error handler, not even an empty one.');
$this->assertEmpty($this->xpath('//div[contains(@class, "messages")]'), 'Ensures that also no messages div exists, which proves that no messages were generated by the error handler, not even an empty one.');
}
}

View File

@ -125,12 +125,9 @@ class FieldWebTest extends ViewTestBase {
* The message to display along with the assertion.
* @param string $group
* The type of assertion - examples are "Browser", "PHP".
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertStringContainsString($needle, $haystack, $message);
$this->assertStringContainsString($needle, $haystack, $message);
}
/**
@ -144,12 +141,9 @@ class FieldWebTest extends ViewTestBase {
* The message to display along with the assertion.
* @param string $group
* The type of assertion - examples are "Browser", "PHP".
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertStringNotContainsString($needle, $haystack, $message);
$this->assertStringNotContainsString($needle, $haystack, $message);
}
/**

View File

@ -363,9 +363,6 @@ class ExposedFormTest extends ViewTestBase {
*
* @param int[] $ids
* The ids to check.
*
* @return bool
* TRUE if ids match, FALSE otherwise.
*/
protected function assertIds(array $ids) {
$elements = $this->cssSelect('div.view-test-exposed-form-sort-items-per-page div.views-row span.field-content');
@ -374,7 +371,7 @@ class ExposedFormTest extends ViewTestBase {
$actual_ids[] = (int) $element->getText();
}
return $this->assertSame($ids, $actual_ids);
$this->assertSame($ids, $actual_ids);
}
/**

View File

@ -243,9 +243,6 @@ class RowEntityRenderersTest extends ViewsKernelTestBase {
* (optional) A message to display with the assertion.
* @param string $group
* (optional) The group this message is in.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertTranslations($display, $renderer_id, array $expected, $message = '', $group = 'Other') {
$view = Views::getView('test_entity_row_renderers');
@ -270,7 +267,7 @@ class RowEntityRenderersTest extends ViewsKernelTestBase {
}
}
return $this->assertTrue($result, $message, $group);
$this->assertTrue($result, $message, $group);
}
}

View File

@ -109,12 +109,9 @@ class FieldKernelTest extends ViewsKernelTestBase {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertStringContainsString($needle, $haystack, $message);
$this->assertStringContainsString($needle, $haystack, $message);
}
/**
@ -134,12 +131,9 @@ class FieldKernelTest extends ViewsKernelTestBase {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertStringNotContainsString($needle, $haystack, $message);
$this->assertStringNotContainsString($needle, $haystack, $message);
}
/**

View File

@ -837,9 +837,6 @@ trait AssertContentTrait {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertNoTitle($title, $message = '', $group = 'Other') {
$actual = (string) current($this->xpath('//title'));
@ -849,7 +846,7 @@ trait AssertContentTrait {
'@unexpected' => var_export($title, TRUE),
]);
}
return $this->assertNotEquals($title, $actual, $message, $group);
$this->assertNotEquals($title, $actual, $message, $group);
}
/**
@ -871,9 +868,6 @@ trait AssertContentTrait {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertThemeOutput($callback, array $variables = [], $expected = '', $message = '', $group = 'Other') {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
@ -889,7 +883,7 @@ trait AssertContentTrait {
$message = '%callback rendered correctly.';
}
$message = new FormattableMarkup($message, ['%callback' => 'theme_' . $callback . '()']);
return $this->assertSame($expected, $output, $message, $group);
$this->assertSame($expected, $output, $message, $group);
}
/**
@ -1245,13 +1239,10 @@ trait AssertContentTrait {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Browser'; most tests do not override
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertOption($id, $option, $message = '', $group = 'Browser') {
$options = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
return $this->assertTrue(isset($options[0]), $message ? $message : new FormattableMarkup('Option @option for field @id exists.', ['@option' => $option, '@id' => $id]), $group);
$this->assertTrue(isset($options[0]), $message ? $message : new FormattableMarkup('Option @option for field @id exists.', ['@option' => $option, '@id' => $id]), $group);
}
/**
@ -1263,13 +1254,10 @@ trait AssertContentTrait {
* The text for the option tag to assert.
* @param string $message
* (optional) A message to display with the assertion.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertOptionByText($id, $text, $message = '') {
$options = $this->xpath('//select[@id=:id]//option[normalize-space(text())=:text]', [':id' => $id, ':text' => $text]);
return $this->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
$this->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
}
/**
@ -1289,13 +1277,10 @@ trait AssertContentTrait {
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Browser'; most tests do not override
* this default.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertOptionWithDrupalSelector($drupal_selector, $option, $message = '', $group = 'Browser') {
$options = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]', [':data_drupal_selector' => $drupal_selector, ':option' => $option]);
return $this->assertTrue(isset($options[0]), $message ? $message : new FormattableMarkup('Option @option for field @data_drupal_selector exists.', ['@option' => $option, '@data_drupal_selector' => $drupal_selector]), $group);
$this->assertTrue(isset($options[0]), $message ? $message : new FormattableMarkup('Option @option for field @data_drupal_selector exists.', ['@option' => $option, '@data_drupal_selector' => $drupal_selector]), $group);
}
/**

View File

@ -98,7 +98,7 @@ class ConnectionUnitTest extends KernelTestBase {
*/
protected function assertConnection($id) {
$list = $this->monitor->query($this->getQuery()['processlist'])->fetchAllKeyed(0, 0);
return $this->assertTrue(isset($list[$id]), new FormattableMarkup('Connection ID @id found.', ['@id' => $id]));
$this->assertTrue(isset($list[$id]), new FormattableMarkup('Connection ID @id found.', ['@id' => $id]));
}
/**
@ -109,7 +109,7 @@ class ConnectionUnitTest extends KernelTestBase {
*/
protected function assertNoConnection($id) {
$list = $this->monitor->query($this->getQuery()['processlist'])->fetchAllKeyed(0, 0);
return $this->assertFalse(isset($list[$id]), new FormattableMarkup('Connection ID @id not found.', ['@id' => $id]));
$this->assertFalse(isset($list[$id]), new FormattableMarkup('Connection ID @id not found.', ['@id' => $id]));
}
/**

View File

@ -326,7 +326,7 @@ class TransactionTest extends DatabaseTestBase {
$message = new FormattableMarkup('Row %name is present.', ['%name' => $name]);
}
$present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE [name] = :name', [':name' => $name])->fetchField();
return $this->assertTrue($present, $message);
$this->assertTrue($present, $message);
}
/**
@ -342,7 +342,7 @@ class TransactionTest extends DatabaseTestBase {
$message = new FormattableMarkup('Row %name is absent.', ['%name' => $name]);
}
$present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE [name] = :name', [':name' => $name])->fetchField();
return $this->assertFalse($present, $message);
$this->assertFalse($present, $message);
}
/**

View File

@ -597,7 +597,7 @@ class EntityQueryAggregateTest extends EntityKernelTestBase {
$found = FALSE;
break;
}
return $this->assertTrue($found, strtr('!expected expected, !found found', ['!expected' => print_r($expected, TRUE), '!found' => print_r($this->queryResult, TRUE)]));
$this->assertTrue($found, strtr('!expected expected, !found found', ['!expected' => print_r($expected, TRUE), '!found' => print_r($this->queryResult, TRUE)]));
}
/**

View File

@ -98,7 +98,7 @@ class FieldTranslationSqlStorageTest extends EntityLanguageTestBase {
}
}
return $this->assertTrue($status, $message);
$this->assertTrue($status, $message);
}
}

View File

@ -66,9 +66,6 @@ abstract class DiscoveryTestBase extends KernelTestBase {
* The definition to test.
* @param array $expected_definition
* The expected definition to test against.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertDefinitionIdentical(array $definition, array $expected_definition) {
$func = function (&$item) {
@ -78,7 +75,7 @@ abstract class DiscoveryTestBase extends KernelTestBase {
};
array_walk_recursive($definition, $func);
array_walk_recursive($expected_definition, $func);
return $this->assertSame($expected_definition, $definition);
$this->assertSame($expected_definition, $definition);
}
}