comparison core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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 public function getMock($originalClassName) {
56 return 'PHPUnit 4';
57 }
58
59 }
60
61 /**
62 * Test class for \PHPUnit\Framework\TestCase in PHPUnit 6.
63 */
64 class Phpunit6TestClass {
65 public function createMock($originalClassName) {
66 return 'PHPUnit 6';
67 }
68
69 public function getMockbuilder() {
70 return new Mockbuilder();
71 }
72
73 }
74
75 /**
76 * Test double for PHPUnit_Framework_MockObject_MockBuilder.
77 */
78 class Mockbuilder {
79 public function __call($name, $arguments) {
80 return $this;
81 }
82
83 public function getMock() {
84 return 'PHPUnit 6';
85 }
86
87 }
88
89 /**
90 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
91 */
92 class UnitTestCasePhpunit4TestClass extends Phpunit4TestClass {
93 use PhpunitCompatibilityTrait;
94
95 }
96
97 /**
98 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
99 */
100 class UnitTestCasePhpunit4TestClassExtends extends UnitTestCasePhpunit4TestClass {
101 }
102
103 /**
104 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
105 */
106 class UnitTestCasePhpunit6TestClass extends Phpunit6TestClass {
107 use PhpunitCompatibilityTrait;
108
109 }
110
111 /**
112 * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 6.
113 */
114 class UnitTestCasePhpunit6TestClassExtends extends UnitTestCasePhpunit6TestClass {
115 }