function FormTestBase::getMockForm

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::getMockForm()

Provides a mocked form object.

Parameters

string $form_id: The form ID to be used.

mixed $expected_form: (optional) If provided, the expected form response for buildForm() to return. Defaults to NULL.

int $count: (optional) The number of times the form is expected to be built. Defaults to 1.

Return value

\PHPUnit\Framework\MockObject\MockObject|\Drupal\Core\Form\FormInterface The mocked form object.

File

core/tests/Drupal/Tests/Core/Form/FormTestBase.php, line 216

Class

FormTestBase
Provides a base class for testing form functionality.

Namespace

Drupal\Tests\Core\Form

Code

protected function getMockForm($form_id, $expected_form = NULL, $count = 1) {
  $form = $this->createMock('Drupal\\Core\\Form\\FormInterface');
  $form->expects($this->once())
    ->method('getFormId')
    ->willReturn($form_id);
  if ($expected_form) {
    $form->expects($this->exactly($count))
      ->method('buildForm')
      ->willReturn($expected_form);
  }
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.