Issue #3427177 by longwave, quietone, dineshkumarbollu, samit.310@gmail.com, mondrake, alexpott: Replace calls to ::expectError*() from Drupal\Tests\Core\Render\ElementTest

(cherry picked from commit b59e63e990)
merge-requests/7353/head
Alex Pott 2024-04-05 13:21:21 +01:00
parent 3194f768b3
commit 3d645c1b3c
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
3 changed files with 4 additions and 23 deletions

View File

@ -2566,18 +2566,6 @@ $ignoreErrors[] = [
'count' => 1, 'count' => 1,
'path' => __DIR__ . '/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php', 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php',
]; ];
$ignoreErrors[] = [
'message' => '#^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
'count' => 1,
'path' => __DIR__ . '/tests/Drupal/Tests/Core/Render/ElementTest.php',
];
$ignoreErrors[] = [
'message' => '#^Call to deprecated method expectErrorMessage\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
'count' => 1,
'path' => __DIR__ . '/tests/Drupal/Tests/Core/Render/ElementTest.php',
];
$ignoreErrors[] = [ $ignoreErrors[] = [
'message' => '#^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: 'message' => '#^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#', https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',

View File

@ -2,7 +2,6 @@
namespace Drupal\Core\Render; namespace Drupal\Core\Render;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Access\AccessResultInterface;
/** /**
@ -92,16 +91,10 @@ class Element {
// the insertion order. // the insertion order.
$child_weights[$key] = floor($weight * 1000) + $i / $count; $child_weights[$key] = floor($weight * 1000) + $i / $count;
} }
// Only trigger an error if the value is not null. // Only trigger an exception if the value is not null.
// @see https://www.drupal.org/node/1283892 // @see https://www.drupal.org/node/1283892
elseif (isset($value)) { elseif (isset($value)) {
trigger_error(new FormattableMarkup( throw new \InvalidArgumentException(sprintf('"%s" is an invalid render array key. Value should be an array but got a %s.', $key, gettype($value)));
'"@key" is an invalid render array key. Value should be an array but got a @type',
[
'@key' => $key,
'@type' => gettype($value),
]
), E_USER_ERROR);
} }
} }
$i++; $i++;

View File

@ -108,8 +108,8 @@ class ElementTest extends UnitTestCase {
$element = [ $element = [
'foo' => 'bar', 'foo' => 'bar',
]; ];
$this->expectError(); $this->expectException(\InvalidArgumentException::class);
$this->expectErrorMessage('"foo" is an invalid render array key. Value should be an array but got a string'); $this->expectExceptionMessage('"foo" is an invalid render array key. Value should be an array but got a string.');
Element::children($element); Element::children($element);
} }