1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Tests\Driver; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Base class for field handler tests. |
9
|
|
|
*/ |
10
|
|
|
abstract class FieldHandlerAbstractTest extends TestCase { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
public function tearDown() { |
16
|
|
|
\Mockery::close(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Factory method to build and returned a mocked field handler. |
21
|
|
|
* |
22
|
|
|
* @param string $handler |
23
|
|
|
* The name of the field handler class under test. |
24
|
|
|
* @param object $entity |
25
|
|
|
* An object representing an entity. Should contain a single property which |
26
|
|
|
* represents a field containing a value. |
27
|
|
|
* @param string $entity_type |
28
|
|
|
* The entity type under test. |
29
|
|
|
* @param array $field |
30
|
|
|
* An associative array with the following keys: |
31
|
|
|
* - 'field_name': the field name that is used for the property on $entity. |
32
|
|
|
* - 'columns': an optional array containing the column names of the field |
33
|
|
|
* as keys. |
34
|
|
|
* |
35
|
|
|
* @return \Mockery\MockInterface |
36
|
|
|
* The mocked field handler. |
37
|
|
|
*/ |
38
|
|
|
protected function getMockHandler($handler, $entity, $entity_type, array $field) { |
39
|
|
|
$mock = \Mockery::mock(sprintf('Drupal\Driver\Fields\Drupal7\%s', $handler)); |
40
|
|
|
$mock->makePartial(); |
41
|
|
|
$mock->shouldReceive('getFieldInfo')->andReturn($field); |
42
|
|
|
$mock->shouldReceive('getEntityLanguage')->andReturn('en'); |
43
|
|
|
$mock->__construct($entity, $entity_type, $field); |
|
|
|
|
44
|
|
|
|
45
|
|
|
return $mock; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Simulate __call() since mocked handlers will not run through magic methods. |
50
|
|
|
* |
51
|
|
|
* @param mixed $values |
52
|
|
|
* The field value(s). |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
* The values parameter cast to an array. |
56
|
|
|
*/ |
57
|
|
|
protected function values($values) { |
58
|
|
|
return (array) $values; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.