Problem/Motivation

The phpdoc block for the $form_id argument suggests that this method argument is optional, but the method signature does not have an argument value for $form_id.

/**
  * Provides a mocked form object.
  *
  * @param string $form_id
  *   (optional) The form ID to be used. If none is provided, the form will be
  *   set with no expectation about getFormId().
protected function getMockForm($form_id, $expected_form = NULL, $count = 1) {

Proposed resolution

  1. Change the API documentation to clarify that the method argument is not optional and should be provided.
  2. Change the method signature so that the $form_id argument has a NULL value to match the API documentation.

The only core test class that uses Drupal's getMockForm is \Drupal\Tests\Core\Form\FormBuilderTest. However this probably a useful abstract class for contributed modules.

Remaining tasks

  • Choose the approach.
  • Add a beta evaluation template.
  • Write a patch.
  • Review the patch following documentation and code standards.

User interface changes

No.

API changes

Maybe. The method signature either needs to match the documentation or vice versa.

Data model changes

No.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task
Issue priority Normal, documentation fix.
CommentFileSizeAuthor
#4 2547531-3-do-not-test.patch695 bytessdstyles

Comments

mradcliffe created an issue. See original summary.

mradcliffe’s picture

It may make sense to change the method signature, but I do not see any use for the argument value to be NULL. If I wanted to use the simulateFormSubmission() method then I would need a form id anyway.

If my assertions were only about asserting the generated form element, then it may be of value to change the method signature.

sdstyles’s picture

Issue summary: View changes
sdstyles’s picture

Status: Active » Needs review
StatusFileSize
new695 bytes

Documentation change.

meramo’s picture

Looks good to me

evilfurryone’s picture

Status: Needs review » Reviewed & tested by the community

Looks OK here, updating the status as previous commentor forgot about it :)

webchick’s picture

Component: phpunit » documentation
Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. Thanks!

  • webchick committed 225c65b on 8.0.x
    Issue #2547531 by sdstyles, mradcliffe: Fix documentation for...
webchick’s picture

Committed and pushed to 8.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.