class PhpunitCompatibilityTraitTest in Drupal 8
Tests the PHPUnit forward compatibility trait.
@coversDefaultClass \Drupal\Tests\PhpunitCompatibilityTrait @group Tests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\PhpunitCompatibilityTraitTest
Expanded class hierarchy of PhpunitCompatibilityTraitTest
File
- core/
tests/ Drupal/ Tests/ PhpunitCompatibilityTraitTest.php, line 13
Namespace
Drupal\TestsView source
class PhpunitCompatibilityTraitTest extends UnitTestCase {
/**
* Tests that getMock is available.
*
* @covers ::getMock
* @group legacy
* @expectedDeprecation \Drupal\Tests\PhpunitCompatibilityTrait::getMock() is deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\PhpunitCompatibilityTrait::createMock() instead. See https://www.drupal.org/node/2907725
*/
public function testGetMock() {
$this
->assertInstanceOf('\\Drupal\\Tests\\MockTestClassInterface', $this
->getMock(MockTestClassInterface::class));
}
/**
* Tests that setExpectedException is available.
*
* @covers ::setExpectedException
* @group legacy
* @expectedDeprecation \Drupal\Tests\PhpunitCompatibilityTrait:setExpectedException() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Backward compatibility for PHPUnit 4 will no longer be supported. See https://www.drupal.org/node/3056869
*/
public function testSetExpectedException() {
$expectedMessage = "Expected message";
$expectedCode = 100;
$this
->setExpectedException(\Exception::class, $expectedMessage, $expectedCode);
throw new \Exception($expectedMessage, $expectedCode);
}
/**
* Tests that assert*StringContainsString* methods are available.
*
* @covers ::assertStringContainsString
* @covers ::assertStringContainsStringIgnoringCase
* @covers ::assertStringNotContainsString
* @covers ::assertStringNotContainsStringIgnoringCase
*/
public function testAssertStringContainsString() {
$this
->assertStringContainsString("bingo", "foobarbingobongo");
$this
->assertStringContainsStringIgnoringCase("bingo", "foobarBiNgObongo");
$this
->assertStringNotContainsString("buzzer", "BUZZERbingobongo");
$this
->assertStringNotContainsStringIgnoringCase("buzzer", "foobarBiNgObongo");
// Test with stringable objects.
$this
->assertStringContainsString(new FormattableMarkup("bingo", []), new FormattableMarkup("foobarbingobongo", []));
$this
->assertStringContainsStringIgnoringCase(new FormattableMarkup("bingo", []), new FormattableMarkup("foobarBiNgObongo", []));
$this
->assertStringNotContainsString(new FormattableMarkup("buzzer", []), new FormattableMarkup("BUZZERbingobongo", []));
$this
->assertStringNotContainsStringIgnoringCase(new FormattableMarkup("buzzer", []), new FormattableMarkup("foobarBiNgObongo", []));
}
/**
* Tests that assert(Not)EqualsCanonicalizing methods are available.
*
* @covers ::assertEqualsCanonicalizing
* @covers ::assertNotEqualsCanonicalizing
*/
public function testAssertEqualsCanonicalizing() {
$this
->assertEqualsCanonicalizing([
3,
2,
1,
], [
2,
3,
1,
]);
$this
->assertNotEqualsCanonicalizing([
3,
2,
1,
], [
2,
3,
0,
1,
]);
}
/**
* Tests that assertIs(Not)* methods are available.
*
* @covers ::assertIsArray
* @covers ::assertIsBool
* @covers ::assertIsFloat
* @covers ::assertIsInt
* @covers ::assertIsNumeric
* @covers ::assertIsObject
* @covers ::assertIsResource
* @covers ::assertIsString
* @covers ::assertIsScalar
* @covers ::assertIsCallable
* @covers ::assertIsNotArray
* @covers ::assertIsNotBool
* @covers ::assertIsNotFloat
* @covers ::assertIsNotInt
* @covers ::assertIsNotNumeric
* @covers ::assertIsNotObject
* @covers ::assertIsNotResource
* @covers ::assertIsNotString
* @covers ::assertIsNotScalar
* @covers ::assertIsNotCallable
*/
public function testAssertIs() {
$this
->assertIsArray([]);
$this
->assertIsBool(TRUE);
$this
->assertIsFloat(1.0);
$this
->assertIsInt(1);
$this
->assertIsNumeric(1);
$this
->assertIsObject(new class {
});
$this
->assertIsResource(fopen(__FILE__, 'rb'));
$this
->assertIsString('');
$this
->assertIsScalar(1);
$this
->assertIsCallable(function () {
});
$this
->assertIsNotArray(1);
$this
->assertIsNotBool([]);
$this
->assertIsNotFloat(1);
$this
->assertIsNotInt(1.0);
$this
->assertIsNotNumeric('');
$this
->assertIsNotObject('');
$this
->assertIsNotResource('');
$this
->assertIsNotString(1);
$this
->assertIsNotScalar([]);
$this
->assertIsNotCallable(1);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
PhpunitCompatibilityTraitTest:: |
public | function | Tests that assert(Not)EqualsCanonicalizing methods are available. | |
PhpunitCompatibilityTraitTest:: |
public | function | Tests that assertIs(Not)* methods are available. | |
PhpunitCompatibilityTraitTest:: |
public | function | Tests that assert*StringContainsString* methods are available. | |
PhpunitCompatibilityTraitTest:: |
public | function | Tests that getMock is available. | |
PhpunitCompatibilityTraitTest:: |
public | function | Tests that setExpectedException is available. | |
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 | Mocks a block with a block plugin. | 1 |
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 | 340 |