diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index 8eec2cf8a4..689384e57d 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -142,9 +142,6 @@ public static function getSkippedDeprecations() { return [ // The following deprecation message is skipped for testing purposes. '\Drupal\Tests\SkippedDeprecationTest deprecation', - // The following is a test PHPUnit deprecation warning re-thrown as a - // deprecation. - 'Skipped warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$deprecationWarnings', // The following are PHPUnit 8 deprecations that need to be resolved prior // to PHPUnit 9 compatibility. 'expectExceptionMessageRegExp() is deprecated in PHPUnit 8 and will be removed in PHPUnit 9.', diff --git a/core/tests/Drupal/Tests/PhpUnit8WarningsTest.php b/core/tests/Drupal/Tests/PhpUnit8WarningsTest.php new file mode 100644 index 0000000000..8b83322ce2 --- /dev/null +++ b/core/tests/Drupal/Tests/PhpUnit8WarningsTest.php @@ -0,0 +1,74 @@ +assertContains('string', 'aaaastringaaa'); + $this->assertContains('STRING', 'aaaastringaaa', '', TRUE); + } + + /** + * @expectedDeprecation Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead. + * @expectedDeprecation The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9. + */ + public function testAssertNotContains() { + $this->assertNotContains('foo', 'bar'); + $this->assertNotContains('FOO', 'bar', '', TRUE); + } + + /** + * @expectedDeprecation assertArraySubset() is deprecated and will be removed in PHPUnit 9. + */ + public function testAssertArraySubset() { + $this->assertArraySubset(['a'], ['a', 'b']); + } + + /** + * @expectedDeprecation 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. + */ + public function testAssertInternalType() { + $this->assertInternalType('string', 'string'); + } + + /** + * @expectedDeprecation assertAttributeEquals() is deprecated and will be removed in PHPUnit 9. + * @expectedDeprecation readAttribute() is deprecated and will be removed in PHPUnit 9. + * @expectedDeprecation getObjectAttribute() is deprecated and will be removed in PHPUnit 9. + * @expectedDeprecation assertAttributeSame() is deprecated and will be removed in PHPUnit 9. + * @expectedDeprecation assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9. + * @expectedDeprecation assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9. + */ + public function testAssertAttribute() { + $obj = new class() { + protected $attribute = 'value'; + protected $class; + protected $empty; + + public function __construct() { + $this->class = new \stdClass(); + } + + }; + $this->assertAttributeEquals('value', 'attribute', $obj); + $this->assertAttributeSame('value', 'attribute', $obj); + $this->assertAttributeInstanceOf(\stdClass::class, 'class', $obj); + $this->assertAttributeEmpty('empty', $obj); + } + + /** + * @expectedDeprecation The optional $canonicalize parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsCanonicalizing() instead. + */ + public function testAssertEquals() { + $this->assertEquals(['a', 'b'], ['b', 'a'], '', 0.0, 10, TRUE); + } + +} diff --git a/core/tests/Drupal/Tests/SkippedDeprecationTest.php b/core/tests/Drupal/Tests/SkippedDeprecationTest.php index 65178df95c..b65bdd22e3 100644 --- a/core/tests/Drupal/Tests/SkippedDeprecationTest.php +++ b/core/tests/Drupal/Tests/SkippedDeprecationTest.php @@ -14,7 +14,6 @@ class SkippedDeprecationTest extends UnitTestCase { */ public function testSkippingDeprecations() { @trigger_error('\Drupal\Tests\SkippedDeprecationTest deprecation', E_USER_DEPRECATED); - $this->addWarning('Skipped warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$deprecationWarnings'); $this->addToAssertionCount(1); } @@ -25,7 +24,6 @@ public function testSkippingDeprecations() { */ public function testSkippingDeprecationsAgain() { @trigger_error('\Drupal\Tests\SkippedDeprecationTest deprecation', E_USER_DEPRECATED); - $this->addWarning('Skipped warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$deprecationWarnings'); $this->addToAssertionCount(1); } diff --git a/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php b/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php index 3efe66c401..55a6b60504 100644 --- a/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php +++ b/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php @@ -40,9 +40,6 @@ trait PHPUnit8Warnings { '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.', - // Warnings for testing. - 'Skipped warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$deprecationWarnings', - 'Un-skipped warning for \\Drupal\\Tests\\Traits\\PHPUnit8Warnings::$deprecationWarnings', ]; /**