class PhpUnitWarningsTest in Drupal 9
@coversDefaultClass \Drupal\Tests\Traits\PhpUnitWarnings @group legacy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\PhpUnitWarningsTest
Expanded class hierarchy of PhpUnitWarningsTest
File
- core/
tests/ Drupal/ Tests/ PhpUnitWarningsTest.php, line 11
Namespace
Drupal\TestsView source
class PhpUnitWarningsTest extends UnitTestCase {
/**
* Tests that selected PHPUnit warning is converted to deprecation.
*/
public function testAddWarning() {
$this
->expectDeprecation('Test warning for \\Drupal\\Tests\\PhpUnitWarningsTest::testAddWarning()');
$this
->addWarning('Test warning for \\Drupal\\Tests\\PhpUnitWarningsTest::testAddWarning()');
}
/**
* Tests assertContains.
*/
public function testAssertContains() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, argument 2 passed to PHPUnit\\Framework\\Assert::assertContains() must be iterable.");
}
$this
->expectDeprecation('Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.');
$this
->expectDeprecation('The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.');
$this
->assertContains('string', 'aaaa_string_aaa');
$this
->assertContains('STRING', 'aaaa_string_aaa', '', TRUE);
}
/**
* Tests assertNotContains.
*/
public function testAssertNotContains() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, argument 2 passed to PHPUnit\\Framework\\Assert::assertNotContains() must be iterable.");
}
$this
->expectDeprecation('Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.');
$this
->expectDeprecation('The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.');
$this
->assertNotContains('foo', 'bar');
$this
->assertNotContains('FOO', 'bar', '', TRUE);
}
/**
* Tests assertArraySubset.
*/
public function testAssertArraySubset() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, assertArraySubset() is removed.");
}
$this
->expectDeprecation('assertArraySubset() is deprecated and will be removed in PHPUnit 9.');
$this
->assertArraySubset([
'a',
], [
'a',
'b',
]);
}
/**
* Tests assertInternalType.
*/
public function testAssertInternalType() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, assertInternalType() is removed.");
}
$this
->expectDeprecation('assertInternalType() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertIsString() instead.');
$this
->assertInternalType('string', 'string');
}
/**
* Tests assertion methods accessing class attributes.
*/
public function testAssertAttribute() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, assertion methods accessing class attributes are removed.");
}
$this
->expectDeprecation('assertAttributeEquals() is deprecated and will be removed in PHPUnit 9.');
$this
->expectDeprecation('readAttribute() is deprecated and will be removed in PHPUnit 9.');
$this
->expectDeprecation('getObjectAttribute() is deprecated and will be removed in PHPUnit 9.');
$this
->expectDeprecation('assertAttributeSame() is deprecated and will be removed in PHPUnit 9.');
$this
->expectDeprecation('assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9.');
$this
->expectDeprecation('assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9.');
$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);
}
/**
* Tests assertEquals.
*/
public function testAssertEquals() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, the \$canonicalize parameter of assertEquals() is removed.");
}
$this
->expectDeprecation('The optional $canonicalize parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsCanonicalizing() instead.');
$this
->assertEquals([
'a',
'b',
], [
'b',
'a',
], '', 0.0, 10, TRUE);
}
/**
* Tests expectExceptionMessageRegExp.
*/
public function testExpectExceptionMessageRegExp() {
if (RunnerVersion::getMajor() > 8) {
$this
->markTestSkipped("In PHPUnit 9+, expectExceptionMessageRegExp() is removed.");
}
$this
->expectDeprecation('expectExceptionMessageRegExp() is deprecated in PHPUnit 8 and will be removed in PHPUnit 9. Use expectExceptionMessageMatches() instead.');
$this
->expectException(\Exception::class);
$this
->expectExceptionMessageRegExp('/An exception .*/');
throw new \Exception('An exception has been triggered');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
PhpUnitWarningsTest:: |
public | function | Tests that selected PHPUnit warning is converted to deprecation. | |
PhpUnitWarningsTest:: |
public | function | Tests assertArraySubset. | |
PhpUnitWarningsTest:: |
public | function | Tests assertion methods accessing class attributes. | |
PhpUnitWarningsTest:: |
public | function | Tests assertContains. | |
PhpUnitWarningsTest:: |
public | function | Tests assertEquals. | |
PhpUnitWarningsTest:: |
public | function | Tests assertInternalType. | |
PhpUnitWarningsTest:: |
public | function | Tests assertNotContains. | |
PhpUnitWarningsTest:: |
public | function | Tests expectExceptionMessageRegExp. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 308 | |
UnitTestCase:: |
public static | function |