diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 263cb29228..71b22f1b6c 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -925,30 +925,14 @@ public function testVarDump() { $body = $this->drupalGet('test-page-var-dump'); $this->assertSession()->statusCodeEquals(200); + // It is too strict to assert all properties of the Role and it's easy to + // break if one of these properties gets removed or gets a new default + // value. It should be sufficient to test just a couple of properties. $this->assertStringContainsString('', $body); $this->assertStringContainsString(' #id: "test_role"', $body); $this->assertStringContainsString(' #label: null', $body); - $this->assertStringContainsString(' #weight: null', $body); $this->assertStringContainsString(' #permissions: []', $body); - $this->assertStringContainsString(' #is_admin: null', $body); - $this->assertStringContainsString(' #originalId: "test_role"', $body); - $this->assertStringContainsString(' #status: true', $body); $this->assertStringContainsString(' #uuid: "', $body); - $this->assertStringContainsString(' -isUninstalling: false', $body); - $this->assertStringContainsString(' #langcode: "en"', $body); - $this->assertStringContainsString(' #third_party_settings: []', $body); - $this->assertStringContainsString(' #_core: []', $body); - $this->assertStringContainsString(' #trustedData: false', $body); - $this->assertStringContainsString(' #entityTypeId: "user_role"', $body); - $this->assertStringContainsString(' #enforceIsNew: true', $body); - $this->assertStringContainsString(' #typedData: null', $body); - $this->assertStringContainsString(' #cacheContexts: []', $body); - $this->assertStringContainsString(' #cacheTags: []', $body); - $this->assertStringContainsString(' #cacheMaxAge: -1', $body); - $this->assertStringContainsString(' #_serviceIds: []', $body); - $this->assertStringContainsString(' #_entityStorages: []', $body); - $this->assertStringContainsString(' #dependencies: []', $body); - $this->assertStringContainsString(' #isSyncing: false', $body); $this->assertStringContainsString('}', $body); } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index c8228546f3..e820555aa8 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -20,9 +20,9 @@ use Drupal\Tests\ConfigTestTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\Tests\TestRequirementsTrait; -use Drupal\TestTools\DrupalVarDumperHandler; use Drupal\Tests\Traits\PHPUnit8Warnings; use Drupal\TestTools\Comparator\MarkupInterfaceComparator; +use Drupal\TestTools\TestVarDumper; use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Reference; @@ -223,7 +223,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa */ public static function setUpBeforeClass() { parent::setUpBeforeClass(); - VarDumper::setHandler(DrupalVarDumperHandler::class . '::cliHandler'); + VarDumper::setHandler(TestVarDumper::class . '::cliHandler'); // Change the current dir to DRUPAL_ROOT. chdir(static::getDrupalRoot()); diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 35e1985569..b9cd459956 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -351,31 +351,13 @@ public function testVarDump() { $this->expectOutputRegex('|Drupal\\\\user\\\\Entity\\\\Role|'); // Assert that `#foo: bar\n` like pattern presents. $this->expectOutputRegex('|#.+:.+\\\n|'); + // It is too strict to assert all properties of the Role and it's easy to + // break if one of these properties gets removed or gets a new default + // value. It should be sufficient to test just a couple of properties. $this->expectOutputRegex('|id.+test_role|'); $this->expectOutputRegex('|label.+null|'); - $this->expectOutputRegex('|weight.+null|'); $this->expectOutputRegex('|permissions.+\[\]|'); - $this->expectOutputRegex('|is_admin.+null|'); - $this->expectOutputRegex('|originalId.+test_role|'); - $this->expectOutputRegex('|status.+true|'); $this->expectOutputRegex("|uuid.+$uuid|"); - // Assert that `-foo: bar\n` like pattern presents. - $this->expectOutputRegex('|\-.+:.+\\\n|'); - $this->expectOutputRegex('|isUninstalling.+false|'); - $this->expectOutputRegex('|langcode.+en|'); - $this->expectOutputRegex('|third_party_settings.+\[\]|'); - $this->expectOutputRegex('|_core.+\[\]|'); - $this->expectOutputRegex('|trustedData.+false|'); - $this->expectOutputRegex('|entityTypeId.+user_role|'); - $this->expectOutputRegex('|enforceIsNew.+true|'); - $this->expectOutputRegex('|typedData.+null|'); - $this->expectOutputRegex('|cacheContexts.+\[\]|'); - $this->expectOutputRegex('|cacheTags.+\[\]|'); - $this->expectOutputRegex('|cacheMaxAge.+\-1|'); - $this->expectOutputRegex('|_serviceIds.+\[\]|'); - $this->expectOutputRegex('|_entityStorages.+\[\]|'); - $this->expectOutputRegex('|dependencies.+\[\]|'); - $this->expectOutputRegex('|isSyncing.+false|'); dump($role); } diff --git a/core/tests/Drupal/TestTools/DrupalVarDumperHandler.php b/core/tests/Drupal/TestTools/TestVarDumper.php similarity index 97% rename from core/tests/Drupal/TestTools/DrupalVarDumperHandler.php rename to core/tests/Drupal/TestTools/TestVarDumper.php index d38029daa6..e18338d212 100644 --- a/core/tests/Drupal/TestTools/DrupalVarDumperHandler.php +++ b/core/tests/Drupal/TestTools/TestVarDumper.php @@ -12,7 +12,7 @@ * This allows the dump() function to produce output on the terminal without * causing PHPUnit to complain. */ -class DrupalVarDumperHandler { +class TestVarDumper { /** * A CLI handler for \Symfony\Component\VarDumper\VarDumper. diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 93d922ca70..fa27b4aa13 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -19,7 +19,7 @@ use Drupal\Tests\Traits\PHPUnit8Warnings; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\TestTools\Comparator\MarkupInterfaceComparator; -use Drupal\TestTools\DrupalVarDumperHandler; +use Drupal\TestTools\TestVarDumper; use GuzzleHttp\Cookie\CookieJar; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; @@ -219,7 +219,7 @@ abstract class BrowserTestBase extends TestCase { */ public static function setUpBeforeClass() { parent::setUpBeforeClass(); - VarDumper::setHandler(DrupalVarDumperHandler::class . '::htmlHandler'); + VarDumper::setHandler(TestVarDumper::class . '::htmlHandler'); } /**