FixtureDeprecatedClass example


class PhpUnitBridgeTest extends KernelTestBase {

  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());
  }

}

class PhpUnitBridgeTest extends UnitTestCase {

  /** * 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 */

class PhpUnitBridgeRequiresTest extends UnitTestCase {

  /** * Tests the @requires annotation. * * @dataProvider providerTestWillNeverRun */
  public function testWillNeverRun(): void {
    $deprecated = new FixtureDeprecatedClass();
    $this->assertEquals('test', $deprecated->testFunction());
  }

  /** * Data provider for ::testWillNeverRun(). */
  public function providerTestWillNeverRun(): array {
    return [
      ['this_will_never_run'],
    ];
  }

}

class PhpUnitBridgeIsolatedTest extends UnitTestCase {

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

}
Home | Imprint | This part of the site doesn't use cookies.