Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / PhpunitCompatibilityTraitTest.php
1 <?php
2
3 namespace Drupal\Tests;
4
5 /**
6  * Tests the PHPUnit forward compatibility trait.
7  *
8  * @coversDefaultClass \Drupal\Tests\PhpunitCompatibilityTrait
9  * @group Tests
10  */
11 class PhpunitCompatibilityTraitTest extends UnitTestCase {
12
13   /**
14    * Tests that getMock is available and calls the correct parent method.
15    *
16    * @covers ::getMock
17    * @dataProvider providerMockVersions
18    */
19   public function testGetMock($className, $expected) {
20     $class = new $className();
21     $this->assertSame($expected, $class->getMock($this->randomMachineName()));
22   }
23
24   /**
25    * Tests that createMock is available and calls the correct parent method.
26    *
27    * @covers ::createMock
28    * @dataProvider providerMockVersions
29    */
30   public function testCreateMock($className, $expected) {
31     $class = new $className();
32     $this->assertSame($expected, $class->createMock($this->randomMachineName()));
33   }
34
35   /**
36    * Returns the class names and the string they return.
37    *
38    * @return array
39    */
40   public function providerMockVersions() {
41     return [
42       [UnitTestCasePhpunit4TestClass::class, 'PHPUnit 4'],
43       [UnitTestCasePhpunit4TestClassExtends::class, 'PHPUnit 4'],
44       [UnitTestCasePhpunit6TestClass::class, 'PHPUnit 6'],
45       [UnitTestCasePhpunit6TestClassExtends::class, 'PHPUnit 6'],
46     ];
47   }
48
49 }
50
51 /**
52  * Test class for \PHPUnit\Framework\TestCase in PHPUnit 4.
53  */
54 class Phpunit4TestClass {
55
56   public function getMock($originalClassName) {
57     return 'PHPUnit 4';
58   }
59
60 }
61
62 /**
63  * Test class for \PHPUnit\Framework\TestCase in PHPUnit 6.
64  */
65 class Phpunit6TestClass {
66
67   public function createMock($originalClassName) {
68     return 'PHPUnit 6';
69   }
70
71   public function getMockbuilder() {
72     return new Mockbuilder();
73   }
74
75 }
76
77 /**
78  * Test double for PHPUnit_Framework_MockObject_MockBuilder.
79  */
80 class Mockbuilder {
81
82   public function __call($name, $arguments) {
83     return $this;
84   }
85
86   public function getMock() {
87     return 'PHPUnit 6';
88   }
89
90 }
91
92 /**
93  * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
94  */
95 class UnitTestCasePhpunit4TestClass extends Phpunit4TestClass {
96   use PhpunitCompatibilityTrait;
97
98 }
99
100 /**
101  * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
102  */
103 class UnitTestCasePhpunit4TestClassExtends extends UnitTestCasePhpunit4TestClass {
104 }
105
106 /**
107  * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
108  */
109 class UnitTestCasePhpunit6TestClass extends Phpunit6TestClass {
110   use PhpunitCompatibilityTrait;
111
112 }
113
114 /**
115  * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
116  */
117 class UnitTestCasePhpunit6TestClassExtends extends UnitTestCasePhpunit6TestClass {
118 }