comparison core/modules/simpletest/src/TestBase.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
3 namespace Drupal\simpletest; 3 namespace Drupal\simpletest;
4 4
5 use Drupal\Component\Assertion\Handle; 5 use Drupal\Component\Assertion\Handle;
6 use Drupal\Component\Render\MarkupInterface; 6 use Drupal\Component\Render\MarkupInterface;
7 use Drupal\Component\Utility\Crypt; 7 use Drupal\Component\Utility\Crypt;
8 use Drupal\Component\Utility\SafeMarkup; 8 use Drupal\Component\Render\FormattableMarkup;
9 use Drupal\Core\Database\Database; 9 use Drupal\Core\Database\Database;
10 use Drupal\Core\Site\Settings; 10 use Drupal\Core\Site\Settings;
11 use Drupal\Core\StreamWrapper\PublicStream; 11 use Drupal\Core\StreamWrapper\PublicStream;
12 use Drupal\Core\Test\TestDatabase; 12 use Drupal\Core\Test\TestDatabase;
13 use Drupal\Core\Test\TestSetupTrait; 13 use Drupal\Core\Test\TestSetupTrait;
14 use Drupal\Core\Utility\Error; 14 use Drupal\Core\Utility\Error;
15 use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait; 15 use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait;
16 use Drupal\Tests\ConfigTestTrait; 16 use Drupal\Tests\ConfigTestTrait;
17 use Drupal\Tests\RandomGeneratorTrait; 17 use Drupal\Tests\RandomGeneratorTrait;
18 use Drupal\Tests\SessionTestTrait;
19 use Drupal\Tests\Traits\Core\GeneratePermutationsTrait; 18 use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
20 19
21 /** 20 /**
22 * Base class for Drupal tests. 21 * Base class for Drupal tests.
23 * 22 *
25 */ 24 */
26 abstract class TestBase { 25 abstract class TestBase {
27 26
28 use BaseAssertHelperTrait; 27 use BaseAssertHelperTrait;
29 use TestSetupTrait; 28 use TestSetupTrait;
30 use SessionTestTrait;
31 use RandomGeneratorTrait; 29 use RandomGeneratorTrait;
32 use GeneratePermutationsTrait; 30 use GeneratePermutationsTrait;
33 // For backwards compatibility switch the visbility of the methods to public. 31 // For backwards compatibility switch the visibility of the methods to public.
34 use ConfigTestTrait { 32 use ConfigTestTrait {
35 configImporter as public; 33 configImporter as public;
36 copyConfig as public; 34 copyConfig as public;
37 } 35 }
38 36
51 protected $timeLimit = 500; 49 protected $timeLimit = 500;
52 50
53 /** 51 /**
54 * Current results of this test case. 52 * Current results of this test case.
55 * 53 *
56 * @var Array 54 * @var array
57 */ 55 */
58 public $results = [ 56 public $results = [
59 '#pass' => 0, 57 '#pass' => 0,
60 '#fail' => 0, 58 '#fail' => 0,
61 '#exception' => 0, 59 '#exception' => 0,
63 ]; 61 ];
64 62
65 /** 63 /**
66 * Assertions thrown in that test case. 64 * Assertions thrown in that test case.
67 * 65 *
68 * @var Array 66 * @var array
69 */ 67 */
70 protected $assertions = []; 68 protected $assertions = [];
71 69
72 /** 70 /**
73 * This class is skipped when looking for the source of an assertion. 71 * This class is skipped when looking for the source of an assertion.
244 * @param $test_id 242 * @param $test_id
245 * Tests with the same id are reported together. 243 * Tests with the same id are reported together.
246 */ 244 */
247 public function __construct($test_id = NULL) { 245 public function __construct($test_id = NULL) {
248 $this->testId = $test_id; 246 $this->testId = $test_id;
247 }
248
249 /**
250 * Fail the test if it belongs to a PHPUnit-based framework.
251 *
252 * This would probably be caused by automated test conversions such as those
253 * in https://www.drupal.org/project/drupal/issues/2770921.
254 */
255 public function checkTestHierarchyMismatch() {
256 // We can use getPhpunitTestSuite() because it uses a regex on the class'
257 // namespace to deduce the PHPUnit test suite.
258 if (TestDiscovery::getPhpunitTestSuite(get_class($this)) !== FALSE) {
259 $this->fail(get_class($this) . ' incorrectly subclasses ' . __CLASS__ . ', it should probably extend \Drupal\Tests\BrowserTestBase instead.');
260 }
249 } 261 }
250 262
251 /** 263 /**
252 * Performs setup tasks before each individual test method is run. 264 * Performs setup tasks before each individual test method is run.
253 */ 265 */
289 * @param $status 301 * @param $status
290 * Can be 'pass', 'fail', 'exception', 'debug'. 302 * Can be 'pass', 'fail', 'exception', 'debug'.
291 * TRUE is a synonym for 'pass', FALSE for 'fail'. 303 * TRUE is a synonym for 'pass', FALSE for 'fail'.
292 * @param string|\Drupal\Component\Render\MarkupInterface $message 304 * @param string|\Drupal\Component\Render\MarkupInterface $message
293 * (optional) A message to display with the assertion. Do not translate 305 * (optional) A message to display with the assertion. Do not translate
294 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 306 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
295 * variables in the message text, not t(). If left blank, a default message 307 * variables in the message text, not t(). If left blank, a default message
296 * will be displayed. 308 * will be displayed.
297 * @param $group 309 * @param $group
298 * (optional) The group this message is in, which is displayed in a column 310 * (optional) The group this message is in, which is displayed in a column
299 * in test output. Use 'Debug' to indicate this is debugging output. Do not 311 * in test output. Use 'Debug' to indicate this is debugging output. Do not
447 * 459 *
448 * @param $value 460 * @param $value
449 * The value on which the assertion is to be done. 461 * The value on which the assertion is to be done.
450 * @param $message 462 * @param $message
451 * (optional) A message to display with the assertion. Do not translate 463 * (optional) A message to display with the assertion. Do not translate
452 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 464 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
453 * variables in the message text, not t(). If left blank, a default message 465 * variables in the message text, not t(). If left blank, a default message
454 * will be displayed. 466 * will be displayed.
455 * @param $group 467 * @param $group
456 * (optional) The group this message is in, which is displayed in a column 468 * (optional) The group this message is in, which is displayed in a column
457 * in test output. Use 'Debug' to indicate this is debugging output. Do not 469 * in test output. Use 'Debug' to indicate this is debugging output. Do not
460 * 472 *
461 * @return 473 * @return
462 * TRUE if the assertion succeeded, FALSE otherwise. 474 * TRUE if the assertion succeeded, FALSE otherwise.
463 */ 475 */
464 protected function assertTrue($value, $message = '', $group = 'Other') { 476 protected function assertTrue($value, $message = '', $group = 'Other') {
465 return $this->assert((bool) $value, $message ? $message : SafeMarkup::format('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group); 477 return $this->assert((bool) $value, $message ? $message : new FormattableMarkup('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group);
466 } 478 }
467 479
468 /** 480 /**
469 * Check to see if a value is false. 481 * Check to see if a value is false.
470 * 482 *
472 * 484 *
473 * @param $value 485 * @param $value
474 * The value on which the assertion is to be done. 486 * The value on which the assertion is to be done.
475 * @param $message 487 * @param $message
476 * (optional) A message to display with the assertion. Do not translate 488 * (optional) A message to display with the assertion. Do not translate
477 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 489 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
478 * variables in the message text, not t(). If left blank, a default message 490 * variables in the message text, not t(). If left blank, a default message
479 * will be displayed. 491 * will be displayed.
480 * @param $group 492 * @param $group
481 * (optional) The group this message is in, which is displayed in a column 493 * (optional) The group this message is in, which is displayed in a column
482 * in test output. Use 'Debug' to indicate this is debugging output. Do not 494 * in test output. Use 'Debug' to indicate this is debugging output. Do not
485 * 497 *
486 * @return 498 * @return
487 * TRUE if the assertion succeeded, FALSE otherwise. 499 * TRUE if the assertion succeeded, FALSE otherwise.
488 */ 500 */
489 protected function assertFalse($value, $message = '', $group = 'Other') { 501 protected function assertFalse($value, $message = '', $group = 'Other') {
490 return $this->assert(!$value, $message ? $message : SafeMarkup::format('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group); 502 return $this->assert(!$value, $message ? $message : new FormattableMarkup('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group);
491 } 503 }
492 504
493 /** 505 /**
494 * Check to see if a value is NULL. 506 * Check to see if a value is NULL.
495 * 507 *
496 * @param $value 508 * @param $value
497 * The value on which the assertion is to be done. 509 * The value on which the assertion is to be done.
498 * @param $message 510 * @param $message
499 * (optional) A message to display with the assertion. Do not translate 511 * (optional) A message to display with the assertion. Do not translate
500 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 512 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
501 * variables in the message text, not t(). If left blank, a default message 513 * variables in the message text, not t(). If left blank, a default message
502 * will be displayed. 514 * will be displayed.
503 * @param $group 515 * @param $group
504 * (optional) The group this message is in, which is displayed in a column 516 * (optional) The group this message is in, which is displayed in a column
505 * in test output. Use 'Debug' to indicate this is debugging output. Do not 517 * in test output. Use 'Debug' to indicate this is debugging output. Do not
508 * 520 *
509 * @return 521 * @return
510 * TRUE if the assertion succeeded, FALSE otherwise. 522 * TRUE if the assertion succeeded, FALSE otherwise.
511 */ 523 */
512 protected function assertNull($value, $message = '', $group = 'Other') { 524 protected function assertNull($value, $message = '', $group = 'Other') {
513 return $this->assert(!isset($value), $message ? $message : SafeMarkup::format('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group); 525 return $this->assert(!isset($value), $message ? $message : new FormattableMarkup('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group);
514 } 526 }
515 527
516 /** 528 /**
517 * Check to see if a value is not NULL. 529 * Check to see if a value is not NULL.
518 * 530 *
519 * @param $value 531 * @param $value
520 * The value on which the assertion is to be done. 532 * The value on which the assertion is to be done.
521 * @param $message 533 * @param $message
522 * (optional) A message to display with the assertion. Do not translate 534 * (optional) A message to display with the assertion. Do not translate
523 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 535 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
524 * variables in the message text, not t(). If left blank, a default message 536 * variables in the message text, not t(). If left blank, a default message
525 * will be displayed. 537 * will be displayed.
526 * @param $group 538 * @param $group
527 * (optional) The group this message is in, which is displayed in a column 539 * (optional) The group this message is in, which is displayed in a column
528 * in test output. Use 'Debug' to indicate this is debugging output. Do not 540 * in test output. Use 'Debug' to indicate this is debugging output. Do not
531 * 543 *
532 * @return 544 * @return
533 * TRUE if the assertion succeeded, FALSE otherwise. 545 * TRUE if the assertion succeeded, FALSE otherwise.
534 */ 546 */
535 protected function assertNotNull($value, $message = '', $group = 'Other') { 547 protected function assertNotNull($value, $message = '', $group = 'Other') {
536 return $this->assert(isset($value), $message ? $message : SafeMarkup::format('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group); 548 return $this->assert(isset($value), $message ? $message : new FormattableMarkup('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group);
537 } 549 }
538 550
539 /** 551 /**
540 * Check to see if two values are equal. 552 * Check to see if two values are equal.
541 * 553 *
543 * The first value to check. 555 * The first value to check.
544 * @param $second 556 * @param $second
545 * The second value to check. 557 * The second value to check.
546 * @param $message 558 * @param $message
547 * (optional) A message to display with the assertion. Do not translate 559 * (optional) A message to display with the assertion. Do not translate
548 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 560 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
549 * variables in the message text, not t(). If left blank, a default message 561 * variables in the message text, not t(). If left blank, a default message
550 * will be displayed. 562 * will be displayed.
551 * @param $group 563 * @param $group
552 * (optional) The group this message is in, which is displayed in a column 564 * (optional) The group this message is in, which is displayed in a column
553 * in test output. Use 'Debug' to indicate this is debugging output. Do not 565 * in test output. Use 'Debug' to indicate this is debugging output. Do not
563 // comparing with. 575 // comparing with.
564 $first = $this->castSafeStrings($first); 576 $first = $this->castSafeStrings($first);
565 $second = $this->castSafeStrings($second); 577 $second = $this->castSafeStrings($second);
566 $is_equal = $first == $second; 578 $is_equal = $first == $second;
567 if (!$is_equal || !$message) { 579 if (!$is_equal || !$message) {
568 $default_message = SafeMarkup::format('Value @first is equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]); 580 $default_message = new FormattableMarkup('Value @first is equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
569 $message = $message ? $message . PHP_EOL . $default_message : $default_message; 581 $message = $message ? $message . PHP_EOL . $default_message : $default_message;
570 } 582 }
571 return $this->assert($is_equal, $message, $group); 583 return $this->assert($is_equal, $message, $group);
572 } 584 }
573 585
578 * The first value to check. 590 * The first value to check.
579 * @param $second 591 * @param $second
580 * The second value to check. 592 * The second value to check.
581 * @param $message 593 * @param $message
582 * (optional) A message to display with the assertion. Do not translate 594 * (optional) A message to display with the assertion. Do not translate
583 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 595 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
584 * variables in the message text, not t(). If left blank, a default message 596 * variables in the message text, not t(). If left blank, a default message
585 * will be displayed. 597 * will be displayed.
586 * @param $group 598 * @param $group
587 * (optional) The group this message is in, which is displayed in a column 599 * (optional) The group this message is in, which is displayed in a column
588 * in test output. Use 'Debug' to indicate this is debugging output. Do not 600 * in test output. Use 'Debug' to indicate this is debugging output. Do not
598 // comparing with. 610 // comparing with.
599 $first = $this->castSafeStrings($first); 611 $first = $this->castSafeStrings($first);
600 $second = $this->castSafeStrings($second); 612 $second = $this->castSafeStrings($second);
601 $not_equal = $first != $second; 613 $not_equal = $first != $second;
602 if (!$not_equal || !$message) { 614 if (!$not_equal || !$message) {
603 $default_message = SafeMarkup::format('Value @first is not equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]); 615 $default_message = new FormattableMarkup('Value @first is not equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
604 $message = $message ? $message . PHP_EOL . $default_message : $default_message; 616 $message = $message ? $message . PHP_EOL . $default_message : $default_message;
605 } 617 }
606 return $this->assert($not_equal, $message, $group); 618 return $this->assert($not_equal, $message, $group);
607 } 619 }
608 620
613 * The first value to check. 625 * The first value to check.
614 * @param $second 626 * @param $second
615 * The second value to check. 627 * The second value to check.
616 * @param $message 628 * @param $message
617 * (optional) A message to display with the assertion. Do not translate 629 * (optional) A message to display with the assertion. Do not translate
618 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 630 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
619 * variables in the message text, not t(). If left blank, a default message 631 * variables in the message text, not t(). If left blank, a default message
620 * will be displayed. 632 * will be displayed.
621 * @param $group 633 * @param $group
622 * (optional) The group this message is in, which is displayed in a column 634 * (optional) The group this message is in, which is displayed in a column
623 * in test output. Use 'Debug' to indicate this is debugging output. Do not 635 * in test output. Use 'Debug' to indicate this is debugging output. Do not
628 * TRUE if the assertion succeeded, FALSE otherwise. 640 * TRUE if the assertion succeeded, FALSE otherwise.
629 */ 641 */
630 protected function assertIdentical($first, $second, $message = '', $group = 'Other') { 642 protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
631 $is_identical = $first === $second; 643 $is_identical = $first === $second;
632 if (!$is_identical || !$message) { 644 if (!$is_identical || !$message) {
633 $default_message = SafeMarkup::format('Value @first is identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]); 645 $default_message = new FormattableMarkup('Value @first is identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
634 $message = $message ? $message . PHP_EOL . $default_message : $default_message; 646 $message = $message ? $message . PHP_EOL . $default_message : $default_message;
635 } 647 }
636 return $this->assert($is_identical, $message, $group); 648 return $this->assert($is_identical, $message, $group);
637 } 649 }
638 650
643 * The first value to check. 655 * The first value to check.
644 * @param $second 656 * @param $second
645 * The second value to check. 657 * The second value to check.
646 * @param $message 658 * @param $message
647 * (optional) A message to display with the assertion. Do not translate 659 * (optional) A message to display with the assertion. Do not translate
648 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 660 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
649 * variables in the message text, not t(). If left blank, a default message 661 * variables in the message text, not t(). If left blank, a default message
650 * will be displayed. 662 * will be displayed.
651 * @param $group 663 * @param $group
652 * (optional) The group this message is in, which is displayed in a column 664 * (optional) The group this message is in, which is displayed in a column
653 * in test output. Use 'Debug' to indicate this is debugging output. Do not 665 * in test output. Use 'Debug' to indicate this is debugging output. Do not
658 * TRUE if the assertion succeeded, FALSE otherwise. 670 * TRUE if the assertion succeeded, FALSE otherwise.
659 */ 671 */
660 protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') { 672 protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') {
661 $not_identical = $first !== $second; 673 $not_identical = $first !== $second;
662 if (!$not_identical || !$message) { 674 if (!$not_identical || !$message) {
663 $default_message = SafeMarkup::format('Value @first is not identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]); 675 $default_message = new FormattableMarkup('Value @first is not identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
664 $message = $message ? $message . PHP_EOL . $default_message : $default_message; 676 $message = $message ? $message . PHP_EOL . $default_message : $default_message;
665 } 677 }
666 return $this->assert($not_identical, $message, $group); 678 return $this->assert($not_identical, $message, $group);
667 } 679 }
668 680
673 * The first object to check. 685 * The first object to check.
674 * @param object $object2 686 * @param object $object2
675 * The second object to check. 687 * The second object to check.
676 * @param $message 688 * @param $message
677 * (optional) A message to display with the assertion. Do not translate 689 * (optional) A message to display with the assertion. Do not translate
678 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 690 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
679 * variables in the message text, not t(). If left blank, a default message 691 * variables in the message text, not t(). If left blank, a default message
680 * will be displayed. 692 * will be displayed.
681 * @param $group 693 * @param $group
682 * (optional) The group this message is in, which is displayed in a column 694 * (optional) The group this message is in, which is displayed in a column
683 * in test output. Use 'Debug' to indicate this is debugging output. Do not 695 * in test output. Use 'Debug' to indicate this is debugging output. Do not
686 * 698 *
687 * @return 699 * @return
688 * TRUE if the assertion succeeded, FALSE otherwise. 700 * TRUE if the assertion succeeded, FALSE otherwise.
689 */ 701 */
690 protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') { 702 protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') {
691 $message = $message ?: SafeMarkup::format('@object1 is identical to @object2', [ 703 $message = $message ?: new FormattableMarkup('@object1 is identical to @object2', [
692 '@object1' => var_export($object1, TRUE), 704 '@object1' => var_export($object1, TRUE),
693 '@object2' => var_export($object2, TRUE), 705 '@object2' => var_export($object2, TRUE),
694 ]); 706 ]);
695 $identical = TRUE; 707 $identical = TRUE;
696 foreach ($object1 as $key => $value) { 708 foreach ($object1 as $key => $value) {
753 /** 765 /**
754 * Fire an assertion that is always positive. 766 * Fire an assertion that is always positive.
755 * 767 *
756 * @param $message 768 * @param $message
757 * (optional) A message to display with the assertion. Do not translate 769 * (optional) A message to display with the assertion. Do not translate
758 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 770 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
759 * variables in the message text, not t(). If left blank, a default message 771 * variables in the message text, not t(). If left blank, a default message
760 * will be displayed. 772 * will be displayed.
761 * @param $group 773 * @param $group
762 * (optional) The group this message is in, which is displayed in a column 774 * (optional) The group this message is in, which is displayed in a column
763 * in test output. Use 'Debug' to indicate this is debugging output. Do not 775 * in test output. Use 'Debug' to indicate this is debugging output. Do not
774 /** 786 /**
775 * Fire an assertion that is always negative. 787 * Fire an assertion that is always negative.
776 * 788 *
777 * @param $message 789 * @param $message
778 * (optional) A message to display with the assertion. Do not translate 790 * (optional) A message to display with the assertion. Do not translate
779 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 791 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
780 * variables in the message text, not t(). If left blank, a default message 792 * variables in the message text, not t(). If left blank, a default message
781 * will be displayed. 793 * will be displayed.
782 * @param $group 794 * @param $group
783 * (optional) The group this message is in, which is displayed in a column 795 * (optional) The group this message is in, which is displayed in a column
784 * in test output. Use 'Debug' to indicate this is debugging output. Do not 796 * in test output. Use 'Debug' to indicate this is debugging output. Do not
795 /** 807 /**
796 * Fire an error assertion. 808 * Fire an error assertion.
797 * 809 *
798 * @param $message 810 * @param $message
799 * (optional) A message to display with the assertion. Do not translate 811 * (optional) A message to display with the assertion. Do not translate
800 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed 812 * messages: use \Drupal\Component\Render\FormattableMarkup to embed
801 * variables in the message text, not t(). If left blank, a default message 813 * variables in the message text, not t(). If left blank, a default message
802 * will be displayed. 814 * will be displayed.
803 * @param $group 815 * @param $group
804 * (optional) The group this message is in, which is displayed in a column 816 * (optional) The group this message is in, which is displayed in a column
805 * in test output. Use 'Debug' to indicate this is debugging output. Do not 817 * in test output. Use 'Debug' to indicate this is debugging output. Do not
862 * array('testFoo', 'testBar'). By default, all methods of the class are 874 * array('testFoo', 'testBar'). By default, all methods of the class are
863 * taken into account, but it can be useful to only run a few selected test 875 * taken into account, but it can be useful to only run a few selected test
864 * methods during debugging. 876 * methods during debugging.
865 */ 877 */
866 public function run(array $methods = []) { 878 public function run(array $methods = []) {
879 $this->checkTestHierarchyMismatch();
867 $class = get_class($this); 880 $class = get_class($this);
868 881
869 if ($missing_requirements = $this->checkRequirements()) { 882 if ($missing_requirements = $this->checkRequirements()) {
870 $object_info = new \ReflectionObject($this); 883 $object_info = new \ReflectionObject($this);
871 $caller = [ 884 $caller = [
983 TestBase::deleteAssert($test_completion_check_id); 996 TestBase::deleteAssert($test_completion_check_id);
984 } 997 }
985 998
986 TestServiceProvider::$currentTest = NULL; 999 TestServiceProvider::$currentTest = NULL;
987 // Clear out the error messages and restore error handler. 1000 // Clear out the error messages and restore error handler.
988 drupal_get_messages(); 1001 \Drupal::messenger()->deleteAll();
989 restore_error_handler(); 1002 restore_error_handler();
990 } 1003 }
991 1004
992 /** 1005 /**
993 * Generates a database prefix for running tests. 1006 * Generates a database prefix for running tests.
1324 'line' => $exception->getLine(), 1337 'line' => $exception->getLine(),
1325 'file' => $exception->getFile(), 1338 'file' => $exception->getFile(),
1326 ]); 1339 ]);
1327 $decoded_exception = Error::decodeException($exception); 1340 $decoded_exception = Error::decodeException($exception);
1328 unset($decoded_exception['backtrace']); 1341 unset($decoded_exception['backtrace']);
1329 $message = SafeMarkup::format('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decoded_exception + [ 1342 $message = new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decoded_exception + [
1330 '@backtrace' => Error::formatBacktrace($verbose_backtrace), 1343 '@backtrace' => Error::formatBacktrace($verbose_backtrace),
1331 ]); 1344 ]);
1332 $this->error($message, 'Uncaught exception', Error::getLastCaller($backtrace)); 1345 $this->error($message, 'Uncaught exception', Error::getLastCaller($backtrace));
1333 } 1346 }
1334 1347