Problem/Motivation

The story of this issue:

#2863267: Convert web tests of views gave us Drupal\Tests\views\Functional\ViewTestBase and a deprecation of the WTB base class it replaces. Yay!

However, that led to some interesting results in #2870194-9: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code, where phpunit autoloading policy led to failed test runs based on the WTB version of ViewTestBase.

One chat between @Mile23 and @alexpott in IRC later: We originally agreed it's good deprecation policy to put @trigger_error() for test base classes in the setUp() method. So agreeable were we that the testing policy was changed: https://www.drupal.org/core/deprecation#how-test-base-class

Subsequent discussion on this issue and we've decided to put @trigger_error() in WTB base class constructors.

Now existing deprecated WebTestBase base classes need an update for the policy.

Since then, however, we realized that it's not a problem with the deprecation policy, but the existing deprecation policy actually told us the real problem: ConfigTranslationViewListUiTest is a WTB-based test incorrectly placed in the Functional\ namespace by #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits

Steps to reproduce:

  1. Run ./vendor/bin/phpunit -c ./core --filter AccessManagerTest
  2. See deprecation error

Proposed resolution

@Mile23 did some excellent research in #23. The problem described in this issue summary actually just matters for phpunit, so we don't have to adapt the WTB logic of putting it into the header of the file.

Move ConfigTranslationViewListUiTest back to WTB namespace.

Re-update deprecation policy document: https://www.drupal.org/core/deprecation#how-test-base-class

Remaining tasks

Eventually deprecate WebTestBase itself: #2847678: Deprecate WebTestBase and its required classes in favour of BrowserTestBase

User interface changes

API changes

Data model changes

Comments

Mile23 created an issue. See original summary.

mile23’s picture

Status: Active » Needs review
StatusFileSize
new994 bytes

And a patch...

alexpott’s picture

Issue summary: View changes
lendude’s picture

Issue tags: +phpunit initiative

Good to know for any further conversions!

Should we update \Drupal\datetime\Tests\DateTestBase in this issue too? That also has the trigger_error after the namespace.

lendude’s picture

And \Drupal\views\Tests\Wizard\WizardTestBase

And what about base classes that don't implement setUp() like these
\Drupal\views\Tests\Plugin\PluginTestBase
\Drupal\views\Tests\Handler\HandlerTestBase

I guess implement setUp just to add the trigger_error?

alexpott’s picture

Status: Needs review » Needs work

yep let's do them all in this issue.

lendude’s picture

Title: Move ViewTestBase's @trigger_error() call to setUp() » Move deprecated WebTestBase base classes @trigger_error() call to setUp()
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new3.64 KB
new5.1 KB

Here we go

dawehner’s picture

I would expect other classes to potentially do similar kind of stuff in the constructor, so I'm wondering whether we should do the same here.

dawehner’s picture

The advantage of using the constructor would be to have it really explicit, unlike with the setup() method, which is basically in the middle of nowhere and potentially harder to see.

michielnugter’s picture

StatusFileSize
new4.81 KB
new5.26 KB

I agree with @dawehner. The constructor makes it hard to miss and very specific. Patch moves the messages to a constructor.

michielnugter’s picture

Issue tags: +needs documentation updates, +Needs title update

Adding tags to make sure we don't forget these. Not changing the title yet to wait for more opinions..

alexpott’s picture

+1 to adding a constructor with the deprecation

mile23’s picture

Title: Move deprecated WebTestBase base classes @trigger_error() call to setUp() » Move deprecated WebTestBase base classes @trigger_error() call to constructor
Issue summary: View changes
Related issues: +#2847678: Deprecate WebTestBase and its required classes in favour of BrowserTestBase

Constructor it is. :-) Hopefully the branch will pass soon and the test in #10 can run.

Eventually, we'll have to figure out how to @trigger_error() in WebTestBase itself: #2847678: Deprecate WebTestBase and its required classes in favour of BrowserTestBase

lendude’s picture

+1 for the constructor. Also, setUp() will get called multiple times so the trigger_error would get called multiple times too, which seems a little redundant.

+++ b/core/modules/views/src/Tests/Handler/HandlerTestBase.php
@@ -11,4 +10,13 @@
+    @trigger_error('\Drupal\views\Tests\Handler\HandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);

would be nice to use the __NAMESPACE__ pattern consistently

other then that, this looks good to me.

michielnugter’s picture

Issue tags: -needs documentation updates, -Needs title update
StatusFileSize
new1.75 KB
new6.38 KB

Fixed the namespace thing.

Seems we forgot this one: #2865992: Convert Datetime module Views tests to Kerneltest tough. I did another search and it's the only one missed I think.

Removing title and documentation tags. Title was updated and I just updated the documentation on this.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good, doc changes look good and I think we have a consensus on how to handle this. Nice!

dawehner’s picture

+++ b/core/modules/views/src/Tests/Handler/HandlerTestBase.php
@@ -16,7 +16,7 @@
-    @trigger_error('\Drupal\views\Tests\Handler\HandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
+    @trigger_error(__NAMESPACE__ . '\HandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);

+++ b/core/modules/datetime/src/Tests/Views/DateTimeHandlerTestBase.php
@@ -43,6 +41,15 @@
+    @trigger_error(__NAMESPACE__ . '\DateTimeHandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\BrowserTestBase', E_USER_DEPRECATED);

What about using static::class here?

mpdonadio’s picture

static::class will be the late-static binding class name not the base class that we are deprecating; it's basically the same as get_called_class().

catch’s picture

Status: Reviewed & tested by the community » Needs review

What about __CLASS__ then?

dawehner’s picture

oh well you could have also used self::class

mile23’s picture

Status: Needs review » Needs work

Since this is about deprecation policy and not just this single change, let's not use __construct().

Because: If you use the constructor to throw a deprecation error in a phpunit-based test, and you use the phpunit tool with --group or --filter, you end up with a triggered error for every class that was initially discovered, not just the ones you ran.

That takes us back to setUp(), which is better, but which also is called for every test method and every case provided by a @dataProvider in phpunit. This is at least limited to test classes which ran, but gives a lot of thrown errors in your results.

That leaves us with setUpBeforeClass() in phpunit, which only happens once per class (obviously).

We don't have that for WebTestBase, however, so I propose as a policy we do the following:

  • @throw_error() in setUp() for WebTestBase base classes.
  • @throw_error() in setUpBeforeClass() for phpunit base classes.

If that's too complicated or inconsistent then just setUp() is fine.

So for this issue: move the @throw_error back to setUp() for all the deprecated WebTestBase base classes.

michielnugter’s picture

Because: If you use the constructor to throw a deprecation error in a phpunit-based test, and you use the phpunit tool with --group or --filter, you end up with a triggered error for every class that was initially discovered, not just the ones you ran.

That would mean that it would be no problem to trigger it in the constructor for simpletests as they're not run via phpunit right?

I for one would like the most ideal solution for the PHPUnit tests as that's the future and adapt to what's possible for Simpletest. If we're going to differ on solution for Simpletest: do we have a reason for not adding the trigger_error calls in the constructor?

mile23’s picture

Component: views.module » phpunit
Status: Needs work » Needs review
Issue tags: +Needs issue summary update, +Needs followup
StatusFileSize
new774 bytes
new7.17 KB

OK, so the ideal place for this kind of deprecation error in PHPUnit-based tests is setUpBeforeClass(). This is a little out of scope for this issue, but we're going to update policy so we need to decide it.

For simpletest based tests, we have two problems in this issue:

1) We don't like seeing simpletest-based tests doing @trigger_error() during phpunit test runs. We want WTB tests to only trigger_error() when they're actually run and not when they're loaded because we don't like fails. This means either setUp() or __construct(). We seem to have decided on the constructor by consensus. However: Read on. :-)

Note that the simpletest infrastructure has no idea what a @trigger_error() is, so nothing happens with it now. The only problem we're solving here is that simpletest-based tests are throwing errors during phpunit test runs. Which brings us to:

2) Why is a phpunit test run autoloading a simpletest-based test base, if it's not a test of that test base? We don't know. To answer it, adding a stacktrace output to the thrown error tells us that Drupal\Tests\config_translation\Functional\ConfigTranslationViewListUiTest extends Drupal\views_ui\Tests\UITestBase, which means it's a PHPUnit functional test using a WTB base class. Which is wrong. :-)

This happened during the scripted mass-conversion of #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits so it's reasonable that we didn't see it.

So re-evaluating all that has come before, we might reach the following conclusion:

We want to find errors like this, so WTB base classes should @throw_error() as before: Right after the namespace declaration. Since simpletest won't catch those, it's all fine and dandy, but they'll scream in our face under phpunit when we have a test framework mismatch as with ConfigTranslationViewListUiTest. We might find that we need to change this policy later, but for now it does the right thing: Tell us that we're using the wrong framework. It won't tell us that if we move it to setUp() or the constructor.

Also, we might well see more of these types of deprecation errors once we add the @trigger_error() to WebTestBase.

So here's a patch that turns ConfigTranslationViewListUiTest back into a WTB test since that's the easiest move. It also throws errors after the namespace declaration as before for all the deprecated base classes.

Needs a follow-up to re-convert ConfigTranslationViewListUiTest to BTB, since this patch is a little bit like a regression.

mile23’s picture

Category: Task » Bug report

Also, it really is a bug, and should be an 8.3.x issue, but I neglected to change that.

mile23’s picture

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

Patch applies successfully to 8.3.x. Adding an 8.3.x test to the patch in #23.

michielnugter’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +needs documentation updates

It won't tell us that if we move it to setUp() or the constructor.

This alone makes the move back to right after the namespace worth it.

Good catch on the ConfigTranslationViewListUiTest, will try and find out if we have more of these. It's on my radar and I'll post this in the view_ui conversion issue and handle the conversion or follow-up there.

With the extensive research and history of the issue it's ready for RTBC I think.

dawehner’s picture

Issue summary: View changes
mile23’s picture

Issue tags: -needs documentation updates

Updated the documentation to remove the special case for test base deprecations: https://www.drupal.org/core/deprecation

mile23’s picture

Title: Move deprecated WebTestBase base classes @trigger_error() call to constructor » ConfigTranslationViewListUiTest is a WTB test in the Functional namespace
alexpott’s picture

@Mile23 was just about to ask for the title update - nice! But also the issue summary needs updating and the followup created.

mile23’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated IS with some more info.

@michielnugter mentions a follow-up so if he could link to it and remove the tag, that'd be great.

michielnugter’s picture

Issue tags: -Needs followup

Just commented on #2747167: Convert first part of web tests of views_ui on the follow-up issue here, that should cover it right?

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed d284ae8 to 8.4.x and 9717b3a to 8.3.x. Thanks!

  • alexpott committed d284ae8 on 8.4.x
    Issue #2876145 by michielnugter, Mile23, Lendude, dawehner, alexpott:...

  • alexpott committed 9717b3a on 8.3.x
    Issue #2876145 by michielnugter, Mile23, Lendude, dawehner, alexpott:...

Status: Fixed » Closed (fixed)

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