You are here

class CompiledRouteLegacyTest in Drupal 9

@coversDefaultClass \Drupal\Core\Routing\CompiledRoute @group Routing @group legacy

Hierarchy

Expanded class hierarchy of CompiledRouteLegacyTest

File

core/tests/Drupal/Tests/Core/Routing/CompiledRouteLegacyTest.php, line 13

Namespace

Drupal\Tests\Core\Routing
View source
class CompiledRouteLegacyTest extends UnitTestCase {

  /**
   * A compiled route object for testing purposes.
   *
   * @var \Drupal\Core\Routing\CompiledRoute
   */
  private $compiled_route;

  /**
   * @var \Symfony\Component\Routing\Route
   *   A mocked Route object.
   */
  private $mocked_route;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();

    // We can pass in dummy values because we're not doing anything in this
    // test except for verifying the deprecation notices are being thrown.
    $this->compiled_route = new CompiledRoute(0, "", 0, "", "", [], []);
    $this->mocked_route = $this
      ->createMock('Symfony\\Component\\Routing\\Route');
    $this->mocked_route
      ->expects($this
      ->any())
      ->method('getDefaults')
      ->willReturn([]);
    $this->mocked_route
      ->expects($this
      ->any())
      ->method('getRequirements')
      ->willReturn([]);
    $this->mocked_route
      ->expects($this
      ->any())
      ->method('getOptions')
      ->willReturn([]);
  }

  /**
   * Tests for deprecated message and no PHP error.
   *
   * @covers ::getOptions
   */
  public function testOptionsDeprecated() {
    $this
      ->expectDeprecation('Drupal\\Core\\Routing\\CompiledRoute::getOptions() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3159706');
    if (PHP_VERSION_ID >= 80000) {
      $this
        ->expectWarning();
      $this
        ->expectWarningMessage('Undefined property: Drupal\\Core\\Routing\\CompiledRoute::$route');
    }
    else {
      $this
        ->expectNotice();
      $this
        ->expectNoticeMessage('Undefined property: Drupal\\Core\\Routing\\CompiledRoute::$route');
    }
    $this->compiled_route
      ->getOptions();
  }

  /**
   * Tests to make sure we get an array when dynamically setting.
   *
   * @covers ::getOptions
   */
  public function testOptionsDynamicallySet() {
    $this
      ->expectDeprecation('Drupal\\Core\\Routing\\CompiledRoute::getOptions() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3159706');
    $this->compiled_route->route = $this->mocked_route;
    $this->compiled_route
      ->getOptions();
  }

  /**
   * Tests for deprecated message and no PHP error.
   *
   * @covers ::getDefaults
   */
  public function testDefaultsDeprecated() {
    $this
      ->expectDeprecation('Drupal\\Core\\Routing\\CompiledRoute::getDefaults() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3159706');
    if (PHP_VERSION_ID >= 80000) {
      $this
        ->expectWarning();
      $this
        ->expectWarningMessage('Undefined property: Drupal\\Core\\Routing\\CompiledRoute::$route');
    }
    else {
      $this
        ->expectNotice();
      $this
        ->expectNoticeMessage('Undefined property: Drupal\\Core\\Routing\\CompiledRoute::$route');
    }
    $this->compiled_route
      ->getDefaults();
  }

  /**
   * Tests to make sure we get an array when dynamically setting.
   *
   * @covers ::getDefaults
   */
  public function testDefaultsDynamicallySet() {
    $this
      ->expectDeprecation('Drupal\\Core\\Routing\\CompiledRoute::getDefaults() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3159706');
    $this->compiled_route->route = $this->mocked_route;
    $this->compiled_route
      ->getDefaults();
  }

  /**
   * @covers ::getRequirements
   */
  public function testRequirementsDeprecated() {
    $this
      ->expectDeprecation('Drupal\\Core\\Routing\\CompiledRoute::getRequirements() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3159706');
    if (PHP_VERSION_ID >= 80000) {
      $this
        ->expectWarning();
      $this
        ->expectWarningMessage('Undefined property: Drupal\\Core\\Routing\\CompiledRoute::$route');
    }
    else {
      $this
        ->expectNotice();
      $this
        ->expectNoticeMessage('Undefined property: Drupal\\Core\\Routing\\CompiledRoute::$route');
    }
    $this->compiled_route
      ->getRequirements();
  }

  /**
   * Tests to make sure we get an array when dynamically setting.
   *
   * @covers ::getRequirements
   */
  public function testRequirementsDynamicallySet() {
    $this
      ->expectDeprecation('Drupal\\Core\\Routing\\CompiledRoute::getRequirements() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3159706');
    $this->compiled_route->route = $this->mocked_route;
    $this->compiled_route
      ->getRequirements();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CompiledRouteLegacyTest::$compiled_route private property A compiled route object for testing purposes.
CompiledRouteLegacyTest::$mocked_route private property A mocked Route object.
CompiledRouteLegacyTest::setUp protected function Overrides UnitTestCase::setUp
CompiledRouteLegacyTest::testDefaultsDeprecated public function Tests for deprecated message and no PHP error.
CompiledRouteLegacyTest::testDefaultsDynamicallySet public function Tests to make sure we get an array when dynamically setting.
CompiledRouteLegacyTest::testOptionsDeprecated public function Tests for deprecated message and no PHP error.
CompiledRouteLegacyTest::testOptionsDynamicallySet public function Tests to make sure we get an array when dynamically setting.
CompiledRouteLegacyTest::testRequirementsDeprecated public function @covers ::getRequirements
CompiledRouteLegacyTest::testRequirementsDynamicallySet public function Tests to make sure we get an array when dynamically setting.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUpBeforeClass public static function