protected function UnitTestBase::getBasicMocks in Select (or other) 8
Same name and namespace in other branches
- 4.x tests/src/Unit/UnitTestBase.php \Drupal\Tests\select_or_other\Unit\UnitTestBase::getBasicMocks()
Creates and returns two basic mocks.
One WidgetBase and one for the tested class.
Return value
array The two mocks.
1 call to UnitTestBase::getBasicMocks()
- ListWidgetTest::testFormElement in tests/
src/ Unit/ ListWidgetTest.php - Test if formElement() adds the expected information.
File
- tests/
src/ Unit/ UnitTestBase.php, line 98
Class
Namespace
Drupal\Tests\select_or_other\UnitCode
protected function getBasicMocks() {
$methods = [
'getSetting',
'getSelectedOptions',
'getColumn',
];
$parent = $this
->getMockBuilder('Drupal\\select_or_other\\Plugin\\Field\\FieldWidget\\WidgetBase')
->setMethods($methods)
->disableOriginalConstructor()
->getMockForAbstractClass();
$mock = $this
->getMockBuilder($this
->getTestedClassName())
->setMethods($methods)
->disableOriginalConstructor()
->getMock();
$mocks = [
$parent,
$mock,
];
$reflected_field_definition = new ReflectionProperty('Drupal\\select_or_other\\Plugin\\Field\\FieldWidget\\WidgetBase', 'fieldDefinition');
$reflected_field_definition
->setAccessible(TRUE);
/** @var PHPUnit_Framework_MockObject_MockObject $current_mock */
foreach ($mocks as $current_mock) {
$field_definition_methods = [
'getFieldStorageDefinition' => $this
->getMockForAbstractClass('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'),
];
$field_definition = $this
->getMockForAbstractClassWithMethods('\\Drupal\\Core\\Field\\FieldDefinitionInterface', $field_definition_methods);
$reflected_field_definition
->setValue($current_mock, $field_definition);
$current_mock
->method('getSelectedOptions')
->willReturn([]);
$current_mock
->method('getColumn')
->willReturn('');
}
return $mocks;
}