View source
<?php
namespace Drupal\Tests\Traits;
trait PhpUnitWarnings {
private static $deprecationWarnings = [
'Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.',
'Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.',
'assertArraySubset() is deprecated and will be removed in PHPUnit 9.',
'assertInternalType() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(), assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(), assertIsResource(), assertIsString(), assertIsScalar(), assertIsCallable(), or assertIsIterable() instead.',
'readAttribute() is deprecated and will be removed in PHPUnit 9.',
'getObjectAttribute() is deprecated and will be removed in PHPUnit 9.',
'The optional $canonicalize parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsCanonicalizing() instead.',
'assertAttributeEquals() is deprecated and will be removed in PHPUnit 9.',
'assertAttributeSame() is deprecated and will be removed in PHPUnit 9.',
'assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9.',
'assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9.',
'The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.',
'The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.',
'expectExceptionMessageRegExp() is deprecated in PHPUnit 8 and will be removed in PHPUnit 9.',
'expectExceptionMessageRegExp() is deprecated in PHPUnit 8 and will be removed in PHPUnit 9. Use expectExceptionMessageMatches() instead.',
'Test warning for \\Drupal\\Tests\\PhpUnitWarningsTest::testAddWarning()',
'assertFileNotExists() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertFileDoesNotExist() instead.',
'assertRegExp() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertMatchesRegularExpression() instead.',
'assertNotRegExp() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertDoesNotMatchRegularExpression() instead.',
'assertDirectoryNotExists() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertDirectoryDoesNotExist() instead.',
'Support for using expectException() with PHPUnit\\Framework\\Error\\Warning is deprecated and will be removed in PHPUnit 10. Use expectWarning() instead.',
'Support for using expectException() with PHPUnit\\Framework\\Error\\Error is deprecated and will be removed in PHPUnit 10. Use expectError() instead.',
'assertDirectoryNotIsWritable() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertDirectoryIsNotWritable() instead.',
'assertFileNotIsWritable() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertFileIsNotWritable() instead.',
'The at() matcher has been deprecated. It will be removed in PHPUnit 10. Please refactor your test to not rely on the order in which methods are invoked.',
];
public function addWarning(string $warning) : void {
if (in_array($warning, self::$deprecationWarnings, TRUE)) {
@trigger_error($warning, E_USER_DEPRECATED);
return;
}
if (preg_match('/^assertInternalType\\(\\) is deprecated and will be removed in PHPUnit 9. Refactor your test to use assert.*\\(\\) instead.$/', $warning)) {
@trigger_error($warning, E_USER_DEPRECATED);
return;
}
parent::addWarning($warning);
}
}