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 {
56 public function getMock($originalClassName) {
63 * Test class for \PHPUnit\Framework\TestCase in PHPUnit 6.
65 class Phpunit6TestClass {
67 public function createMock($originalClassName) {
71 public function getMockbuilder() {
72 return new Mockbuilder();
78 * Test double for PHPUnit_Framework_MockObject_MockBuilder.
82 public function __call($name, $arguments) {
86 public function getMock() {
93 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
95 class UnitTestCasePhpunit4TestClass extends Phpunit4TestClass {
96 use PhpunitCompatibilityTrait;
101 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
103 class UnitTestCasePhpunit4TestClassExtends extends UnitTestCasePhpunit4TestClass {
107 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
109 class UnitTestCasePhpunit6TestClass extends Phpunit6TestClass {
110 use PhpunitCompatibilityTrait;
115 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
117 class UnitTestCasePhpunit6TestClassExtends extends UnitTestCasePhpunit6TestClass {