3 namespace Drupal\Tests\Driver;
6 * Base class for field handler tests.
8 abstract class FieldHandlerAbstractTest extends \PHPUnit_Framework_TestCase {
13 public function tearDown() {
18 * Factory method to build and returned a mocked field handler.
20 * @param string $handler
21 * The name of the field handler class under test.
22 * @param object $entity
23 * An object representing an entity. Should contain a single property which
24 * represents a field containing a value.
25 * @param string $entity_type
26 * The entity type under test.
28 * An associative array with the following keys:
29 * - 'field_name': the field name that is used for the property on $entity.
30 * - 'columns': an optional array containing the column names of the field
33 * @return \Mockery\MockInterface
34 * The mocked field handler.
36 protected function getMockHandler($handler, $entity, $entity_type, array $field) {
37 $mock = \Mockery::mock(sprintf('Drupal\Driver\Fields\Drupal7\%s', $handler));
39 $mock->shouldReceive('getFieldInfo')->andReturn($field);
40 $mock->shouldReceive('getEntityLanguage')->andReturn('en');
41 $mock->__construct($entity, $entity_type, $field);
47 * Simulate __call() since mocked handlers will not run through magic methods.
49 * @param mixed $values
53 * The values parameter cast to an array.
55 protected function values($values) {
56 return (array) $values;