3 namespace Drupal\Tests;
6 * Tests the PHPUnit forward compatibility trait.
8 * @coversDefaultClass \Drupal\Tests\PhpunitCompatibilityTrait
11 class PhpunitCompatibilityTraitTest extends UnitTestCase {
14 * Tests that getMock is available and calls the correct parent method.
17 * @dataProvider providerMockVersions
19 public function testGetMock($className, $expected) {
20 $class = new $className();
21 $this->assertSame($expected, $class->getMock($this->randomMachineName()));
25 * Tests that createMock is available and calls the correct parent method.
27 * @covers ::createMock
28 * @dataProvider providerMockVersions
30 public function testCreateMock($className, $expected) {
31 $class = new $className();
32 $this->assertSame($expected, $class->createMock($this->randomMachineName()));
36 * Returns the class names and the string they return.
40 public function providerMockVersions() {
42 [UnitTestCasePhpunit4TestClass::class, 'PHPUnit 4'],
43 [UnitTestCasePhpunit4TestClassExtends::class, 'PHPUnit 4'],
44 [UnitTestCasePhpunit6TestClass::class, 'PHPUnit 6'],
45 [UnitTestCasePhpunit6TestClassExtends::class, 'PHPUnit 6'],
52 * Test class for \PHPUnit\Framework\TestCase in PHPUnit 4.
54 class Phpunit4TestClass {
55 public function getMock($originalClassName) {
62 * Test class for \PHPUnit\Framework\TestCase in PHPUnit 6.
64 class Phpunit6TestClass {
65 public function createMock($originalClassName) {
69 public function getMockbuilder() {
70 return new Mockbuilder();
76 * Test double for PHPUnit_Framework_MockObject_MockBuilder.
79 public function __call($name, $arguments) {
83 public function getMock() {
90 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
92 class UnitTestCasePhpunit4TestClass extends Phpunit4TestClass {
93 use PhpunitCompatibilityTrait;
98 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
100 class UnitTestCasePhpunit4TestClassExtends extends UnitTestCasePhpunit4TestClass {
104 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
106 class UnitTestCasePhpunit6TestClass extends Phpunit6TestClass {
107 use PhpunitCompatibilityTrait;
112 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
114 class UnitTestCasePhpunit6TestClassExtends extends UnitTestCasePhpunit6TestClass {