Skip to content
Snippets Groups Projects

Issue #3130606: MockBuilder::setMethods is deprecated in PHPUnit8 and removed from PHPUnit10

Closed Issue #3130606: MockBuilder::setMethods is deprecated in PHPUnit8 and removed from PHPUnit10
1 unresolved thread
1 unresolved thread

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
38 38 if (!$b instanceof BubbleableMetadata) {
39 39 $renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
40 40 ->disableOriginalConstructor()
41 ->setMethods(['mergeAttachments'])
  • Why is there no replacement for the adding of mergeAttachments?

  • Author Contributor

    mergeAttachments is not (or no longer is) a method of Drupal\Core\Render\Renderer. When converting to using onlyMethods, the mock builder now checks if the method exists on the mocked object. If not, an error is thrown:

    PHPUnit\Framework\MockObject\CannotUseOnlyMethodsException: Trying to configure method "mergeAttachments" with onlyMethods(), but it does not exist in class "Drupal\Core\Render\Renderer". Use addMethods() for methods that do not exist in the class

    see https://www.drupal.org/pift-ci-job/2175338.

    Another method is added to the mock builder to manage 'extending' the mock with new methods, addMethods. But in this case apparently in the test there is no behavior set for mergeAttachments on the mock, so we just do not need to add it.

  • @mondrake: thank you for the explanation.

    This thread can be marked as resolved.

  • Please register or sign in to reply
  • closed

  • Please register or sign in to reply
    Loading