class DrupalDebugClassLoaderTest
Tests the DrupalDebugClassLoader.
Attributes
#[CoversClass(DrupalDebugClassLoader::class)]
#[Group('TestTools')]
Hierarchy
- class \Drupal\Tests\TestTools\ErrorHandler\DrupalDebugClassLoaderTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of DrupalDebugClassLoaderTest
File
-
core/
tests/ Drupal/ Tests/ TestTools/ ErrorHandler/ DrupalDebugClassLoaderTest.php, line 16
Namespace
Drupal\Tests\TestTools\ErrorHandlerView source
class DrupalDebugClassLoaderTest extends TestCase {
/**
* A DrupalDebugClassLoader instance for testing.
*/
private DrupalDebugClassLoader $loader;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->loader = new DrupalDebugClassLoader(function () : void {
});
}
/**
* Tests that cross-module return type deprecations are generated.
*/
public function testCrossModuleReturnTypeDeprecation() : void {
$deprecations = $this->getReturnTypeDeprecations('Drupal\\drupal_debug_test_other\\ChildWithoutReturnType');
$this->assertSame([
'Method "Drupal\\drupal_debug_test_core\\ParentWithReturn::testMethod()" might add "string" as a native return type declaration in the future. Do the same in child class "Drupal\\drupal_debug_test_other\\ChildWithoutReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
], $deprecations);
}
/**
* Tests scenarios that should NOT trigger cross-module deprecations.
*/
public function testNoDeprecation(string $class) : void {
$this->assertEmpty($this->getReturnTypeDeprecations($class));
}
/**
* Returns only the return-type deprecations for a given class.
*/
private function getReturnTypeDeprecations(string $class) : array {
$deprecations = $this->loader
->checkAnnotations(new \ReflectionClass($class), $class);
return array_values(array_filter($deprecations, fn($d) => str_contains($d, 'might add')));
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| DrupalDebugClassLoaderTest::$loader | private | property | A DrupalDebugClassLoader instance for testing. |
| DrupalDebugClassLoaderTest::getReturnTypeDeprecations | private | function | Returns only the return-type deprecations for a given class. |
| DrupalDebugClassLoaderTest::setUp | protected | function | |
| DrupalDebugClassLoaderTest::testCrossModuleReturnTypeDeprecation | public | function | Tests that cross-module return type deprecations are generated. |
| DrupalDebugClassLoaderTest::testNoDeprecation | public | function | Tests scenarios that should NOT trigger cross-module deprecations. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.