Do not allow PHPUnit tests to test an interface. Generaly you cannot test an interace, so do not allow it.

Proposed solution
Let the DrupalStandardsListener class generate a failure when a PHPUnit test is testing an interface.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Unfrozen changes Unfrozen because it improves automated testing.
Disruption Not disruptive because no PHPUnit test is testing an interface.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

daffie’s picture

Status: Active » Needs review
FileSize
683 bytes
franksj’s picture

Status: Needs review » Needs work

I changed Drupal\Tests\Component\Utility\HtmlTest to @coversDefaultClass \Drupal\Component\Utility\ArgumentsResolverInterface and it did start giving errors.

1) Drupal\Tests\Component\Utility\HtmlTest::testCleanCssIdentifier with data set #0 ('abcdefghijklmnopqrstuvwxyz_AB...456789', 'abcdefghijklmnopqrstuvwxyz_AB...456789', array())
@coversDefaultClass does not exist '\Drupal\Component\Utility\ArgumentsResolverInterface': Drupal\Tests\Component\Utility\HtmlTest::testCleanCssIdentifier with data set #0

/Users/jfranks/Sites/devdesktop/drupal/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php:30
/Users/jfranks/Sites/devdesktop/drupal/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php:75
/Users/jfranks/Sites/devdesktop/drupal/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php:154

However, the interface does actually exist, it's just that we aren't allowing it. Should we change the failure to reflect why the test is really failing?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

However, the interface does actually exist, it's just that we aren't allowing it. Should we change the failure to reflect why the test is really failing?

I agree that message is not that helpful yet.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs work » Needs review
FileSize
1.76 KB

Reroll + fixes #4.

Status: Needs review » Needs work

The last submitted patch, 9: 2428753.patch, failed testing. View results

borisson_’s picture

Status: Needs work » Needs review
FileSize
664 bytes
2.41 KB

There was one instance in core where this was happening, fixed that.

dawehner’s picture

@borisson_ Nice find!

+++ b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
@@ -71,6 +71,9 @@ private function checkValidCoversForTest(TestCase $test) {
+      if (!$valid_default_class && interface_exists($default_class)) {
+        $this->fail($test, "@coversDefaultClass refers to an interface '$default_class' and those can not be tested.");
+      }
       if (!$valid_default_class) {

Would it make sense to merge these 2 ifs?

borisson_’s picture

@dawehner:

We could do this instead, but I don't think that's a big improvement.

-      if (!$valid_default_class) {
+      else if (!$valid_default_class) {
borisson_’s picture

@dawehner is #13 what you meant to improve in #12?

dawehner’s picture

+1 for #13

borisson_’s picture

FileSize
786 bytes
2.46 KB

Ok, done.

borisson_’s picture

Is there anything we can do other than a review to get this issue in? Does this need a change notice?

dawehner’s picture

Do you know whether we can ship with an invalid use and have that to be a test?

borisson_’s picture

I think #9 is sufficient to prove that this works?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Well, an automated way which doesn't break in the future would be nice I guess. But yeah I see your point. Well, let's see whether a core committer complains.

alexpott’s picture

Version: 8.5.x-dev » 8.6.x-dev

Let's open a followup for testing DrupalStandardsListenerTrait as there is no test so far.

Crediting @dawehner and @franksj for reviews and testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7c6f4ae and pushed to 8.6.x. Thanks!

  • alexpott committed 7c6f4ae on 8.6.x
    Issue #2428753 by borisson_, daffie, dawehner, franksj: Do not allow...

Status: Fixed » Closed (fixed)

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