deprecation_test_function example

/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests deprecation message from deprecation_test_function(). */
  public function testSilencedError() {
    $this->expectDeprecation('This is the deprecation message for deprecation_test_function().');
    $this->assertEquals('known_return_value', deprecation_test_function());
  }

  /** * Tests deprecation message from deprecated route. */
  public function testErrorOnSiteUnderTest() {
    $this->expectDeprecation('This is the deprecation message for deprecation_test_function().');
    $this->drupalGet(Url::fromRoute('deprecation_test.route'));
  }

}

class DeprecatedController {

  /** * Controller callback. * * @return array * Render array. */
  public function deprecatedMethod() {
    return [
      '#markup' => deprecation_test_function(),
    ];
  }

}
protected static $modules = ['deprecation_test'];

  public function testDeprecatedClass() {
    $this->expectDeprecation('Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass is deprecated.');
    $deprecated = new FixtureDeprecatedClass();
    $this->assertEquals('test', $deprecated->testFunction());
  }

  public function testDeprecatedFunction() {
    $this->expectDeprecation('This is the deprecation message for deprecation_test_function().');
    $this->assertEquals('known_return_value', \deprecation_test_function());
  }

}
/** * Tests class-level deprecation. */
  public function testDeprecatedClass() {
    $this->expectDeprecation('Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass is deprecated.');
    $deprecated = new FixtureDeprecatedClass();
    $this->assertEquals('test', $deprecated->testFunction());
  }

  public function testDeprecatedFunction() {
    $this->markTestIncomplete('Modules are not loaded for unit tests, so deprecated_test_function() will not be available.');
    $this->assertEquals('known_return_value', \deprecation_test_function());
  }

  /** * Tests the @requires annotation in conjunction with DrupalListener. * * This test method will be skipped and should not cause the test suite to * fail. * * @requires extension will_hopefully_never_exist * @see \Drupal\Tests\Listeners\DrupalListener */
  
Home | Imprint | This part of the site doesn't use cookies.