Verified Commit c3a57ec4 authored by Dave Long's avatar Dave Long
Browse files

Issue #3358437 by Spokje, mondrake: Deprecate directly accessing...

Issue #3358437 by Spokje, mondrake: Deprecate directly accessing ::$randomGenerator property in base test classes
parent d21fd5d2
Loading
Loading
Loading
Loading
+3 −2
Changes for core/tests/Drupal/KernelTests/KernelTestBase.php: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
use Drupal\Tests\Traits\PhpUnitWarnings;
use Drupal\TestTools\Comparator\MarkupInterfaceComparator;
use Drupal\TestTools\Extension\SchemaInspector;
use Drupal\TestTools\Random;
use Drupal\TestTools\TestVarDumper;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
@@ -267,7 +266,9 @@ protected function setUp(): void {
   */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      return Random::getGenerator();
      @trigger_error('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445', E_USER_DEPRECATED);

      return $this->getRandomGenerator();
    }
  }

+14 −0
Changes for core/tests/Drupal/KernelTests/KernelTestBaseTest.php: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\KernelTests;

use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Utility\Random;
use Drupal\Core\Database\Database;
use GuzzleHttp\Exception\GuzzleException;
use Drupal\Tests\StreamCapturer;
@@ -365,4 +366,17 @@ public function testDatabaseDriverModuleEnabled() {
    $this->assertSame(1, \Drupal::service('extension.list.module')->get($module)->status);
  }

  /**
   * Tests the deprecation of accessing the randomGenerator property directly.
   *
   * @group legacy
   */
  public function testGetRandomGeneratorPropertyDeprecation() {
    $this->expectDeprecation('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445');
    // We purposely test accessing an undefined property here. We need to tell
    // PHPStan to ignore that.
    // @phpstan-ignore-next-line
    $this->assertInstanceOf(Random::class, $this->randomGenerator);
  }

}
+3 −2
Changes for core/tests/Drupal/Tests/BrowserTestBase.php: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
use Drupal\Tests\Traits\PhpUnitWarnings;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\TestTools\Comparator\MarkupInterfaceComparator;
use Drupal\TestTools\Random;
use Drupal\TestTools\TestVarDumper;
use GuzzleHttp\Cookie\CookieJar;
use PHPUnit\Framework\TestCase;
@@ -383,7 +382,9 @@ protected function setUp(): void {
   */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      return Random::getGenerator();
      @trigger_error('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445', E_USER_DEPRECATED);

      return $this->getRandomGenerator();
    }
  }

+14 −0
Changes for core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Tests\Core\Test;

use Drupal\Component\Utility\Random;
use Drupal\Tests\DrupalTestBrowser;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\BrowserTestBase;
@@ -92,4 +93,17 @@ public function testTearDownWithoutSetUp() {
    $ref_tearDown->invoke($btb);
  }

  /**
   * Tests the deprecation of accessing the randomGenerator property directly.
   *
   * @group legacy
   */
  public function testGetRandomGeneratorPropertyDeprecation() {
    $this->expectDeprecation('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445');
    // We purposely test accessing an undefined property here. We need to tell
    // PHPStan to ignore that.
    // @phpstan-ignore-next-line
    $this->assertInstanceOf(Random::class, $this->randomGenerator);
  }

}
+3 −2
Changes for core/tests/Drupal/Tests/UnitTestCase.php: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Tests\Traits\PhpUnitWarnings;
use Drupal\TestTools\Random;
use Drupal\TestTools\TestVarDumper;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
@@ -70,7 +69,9 @@ protected function setUp(): void {
   */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      return Random::getGenerator();
      @trigger_error('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445', E_USER_DEPRECATED);

      return $this->getRandomGenerator();
    }
  }

Loading