Problem/Motivation

There are two fake mocks used in AjaxCommandsTest that can be completely removed if PHPUnit mocks are used instead.

Proposed resolution

Remove the fake mock classes:

  • Drupal\Core\Ajax\OpenDialogCommand
  • Drupal\Core\Ajax\OpenModalDialogCommand

and replace with PHPUnit mocks.

Remaining tasks

None.

User interface changes

No.

API changes

No.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task
Unfrozen changes Unfrozen because it only changes internal unit test code.
Prioritized changes The main goal of this issue is to clean up some code in unit tests, and it removes custom objects that are not needed.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

YesCT’s picture

YesCT’s picture

Issue tags: +Novice
cs_shadow’s picture

Status: Active » Needs review
Issue tags: -Novice
Related issues: -#1906474: [policy adopted] Stop documenting methods with "Overrides …"
FileSize
858 bytes

Replaced {@inheritdoc} on the two classes with actual documentation.

cs_shadow’s picture

Issue tags: +Novice
YesCT’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php
@@ -440,7 +441,7 @@ protected function drupalAttachLibrary($name) {
 /**
  * Wraps OpenDialogCommand::drupalAttachLibrary().
  *
- * {@inheritdoc}
+ * Defines an AJAX command to open certain content in a dialog.

maybe we should look at the usages of TestOpenDialogCommand to help us know what it does and why. (and/or use git blame or git log -S to help us find the issue that put it there. that might also help with it's summary)

We might actually just be able to delete the {@inheritdoc} (and the newline), if the Wraps .... line is sufficient to tell us a one line summary of what this class is doing.

Although the classes it is extending does more than just provide the drupalAttachLibrary()

Since the class is Test...
I kind of expected the docs to mention Tests or testing.

andriyun’s picture

Issue tags: +dcdn-sprint
tetranz’s picture

Title: replace {@inheritdoc} on classes with actual documentation » Replace fake mocks with actual OpenDialogCommand stubs in AjaxCommandsTest
Issue tags: -Novice
neclimdul’s picture

FileSize
2.83 KB

Here's a patch using phpunit's native stubs to null the method.

neclimdul’s picture

Status: Needs work » Needs review
tetranz’s picture

neclimdul’s picture

FileSize
2.83 KB
906 bytes

nice, thanks tetranz. Based on that discussion, documentation on why we are faking those methods.

neclimdul’s picture

FileSize
3.09 KB

bah, interdiff is correct, patch missing changes though.

YesCT’s picture

+++ b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php
@@ -332,10 +337,17 @@ public function testOpenDialogCommand() {
    * Tests that OpenModalDialogCommand objects can be constructed and rendered.
    */
   public function testOpenModalDialogCommand() {
...
+      // This method calls drupal_render which isn't available. We want it to do
+      // nothing so we mock it to return null.
+      ->setMethods(array('drupalAttachLibrary'))
+      ->getMock();

the test says it tests if they can be rendered... but the comment sounds like we are not testing that.

Maybe we should update the comment and open an issue to add render testing?

YesCT’s picture

Issue tags: +PHPUnit

tagging phpunit

tvn’s picture

Issue tags: -dcdn-sprint
jhodgdon’s picture

Component: documentation » phpunit
Issue tags: -Coding standards

This is no longer a Docs issue.

neclimdul’s picture

I've struggled with how to document this. The drupal_render() call being nulled here is not really about rendering but passing things into drupal_process_attached(). I'm not familiar enough with the code to say why it isn't relevant to this test or how to document it.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Maybe we should update the comment and open an issue to add render testing?

Mocking methods that call other code is pretty typical. I don't think our unit test here needs to also test rendering.

Replacing these placeholder objects with mocks removes a bunch of code we don't have to maintain. I've added a beta evaluation to the summary.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

The issue summary and the patch don't agree...

jhedstrom’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

It looks like the summary was never updated after the change in direction in #7. I've updated the summary.

jhedstrom’s picture

Issue summary: View changes
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1f43f1b and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation for to the issue summary.

tim.plunkett’s picture

Status: Fixed » Reviewed & tested by the community

This didn't make it to d.o

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Let's try that again...

  • webchick committed 4b69ce8 on 8.0.x
    Issue #2250165 by neclimdul, cs_shadow, YesCT: Replace fake mocks with...

Status: Fixed » Closed (fixed)

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