Problem/Motivation

If you run phpunit test via ./vendor/bin/phpunit -c ./core --testsuite unit they will fail with:

There were 2 failures:

1) Drupal\Tests\Core\Test\PhpUnitBridgeTest::testDeprecatedClass
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
 @expectedDeprecation:
-%A  Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass is deprecated.
+

/Volumes/devdisk/dev/sites/drupal8alt.dev/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:286
/Volumes/devdisk/dev/sites/drupal8alt.dev/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListener.php:57

2) Drupal\Tests\link\Unit\Plugin\migrate\cckfield\LinkCckTest::testProcessCckFieldValues
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
 @expectedDeprecation:
-%A  CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
-%A  MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
-%A
+  LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d6\LinkField instead.
+

/Volumes/devdisk/dev/sites/drupal8alt.dev/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:286
/Volumes/devdisk/dev/sites/drupal8alt.dev/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListener.php:57

Proposed resolution

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

neclimdul’s picture

Thanks alex. I took a stab at this but either I'm doing something wrong or it is a bit tricky. Fixing one problem causes different failures.

alexpott’s picture

Status: Active » Needs review
FileSize
2.18 KB

So we can fix Drupal\Tests\Core\Test\PhpUnitBridgeTest really simply. But the other one is an interesting tangle because even making it run in a separate process doesn't fix it because the @covers checking in \Drupal\Tests\Listeners\DrupalStandardsListenerTrait causes the class to be loaded. Not sure how to get around that. Ideally \Drupal\Tests\Listeners\DrupalStandardsListenerTrait would not trigger deprecation errors.

alexpott’s picture

This is green... what fun. There's a bug in Symfony's PHPUnit deprecation counter whereby you only need to match on one expected deprecation for a pass. Given their focus on unit tests it's obviously the multiple deprecation testing probably needs more test coverage.

Status: Needs review » Needs work

The last submitted patch, 4: 2933991-4.patch, failed testing. View results

neclimdul’s picture

hahahaha see... tricky.

"you only need to match on one expected deprecation for a pass."
Not sure about how the deprecation matching is implemented but are they handled through exceptions? If so the first one will stop execution and you can never have more then one match so matching any expected exception makes sense.

neclimdul’s picture

I spent some time banging on this and am basically cross eyed and delirious now so documenting what I've seen.

1) Obviously not exceptions. You're working with the error handler to fix things. derp on my part.
2) That error handling change is the "problem". Removing it "fixes" the tests.
3) "problem" and "fixes" because I don't think they ever tested what we thought. They tested the coverage weirdness because removing the covers annotations on a clean install causes the assertion to fail in both run-test.sh and phpunit
4) There _should_ be a deprecation to test in both of these tests. Neither work and it seems connected to the subprocess phpunit serialization magic which might not be working correctly in Drupal's test suite. Inspecting the serialized value reveals an empty array.

All of this to say, I think this patch might be fine the way it is but our deprecation testing doesn't seem to work 100%. Bonus observation, since unit tests run in their own process on testbot and their testing works, it is likely something kernel tests do specifically that is breaking things.

alexpott’s picture

Status: Needs work » Needs review
FileSize
6.26 KB
946 bytes

Ah the fun. So we shouldn't be skipping deprecations when we are dealing with a legacy test. The only reason this test generates deprecation notices in HEAD atm is the Drupal standards checker which is obviously nonsense.

alexpott’s picture

Some minor improvements.

neclimdul’s picture

Thank god you knew where to look because I was going in circles trying to figure out how the interprocess communications wasn't working.

+++ b/core/modules/link/tests/src/Unit/Plugin/migrate/cckfield/LinkCckTest.php
@@ -11,6 +11,8 @@
+ * @arunInSeparateProcess
+ * @apreserveGlobalState disabled

Think this is the only thing keeping it from being RTBC

alexpott’s picture

@neclimdul I think we should just have a comment for that. It needs to be in a separate process because some other test is also loading the code so the deprecation error is not triggered unless this is in a separate process.

neclimdul’s picture

currently they're not running in a separate process though. there's an "a" in front.

alexpott’s picture

@neclimdul lol - yeah right - at one point that was necessary but once I fixed the standards checker to ignore deprecations it was no longer necessary... new patch.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

:-D wfm. No real change from previous patch so going to assume it'll pass and preemptively RTBC.

larowlan’s picture

Crediting @neclimdul for the time spent on #7

  • larowlan committed 891c39b on 8.5.x
    Issue #2933991 by alexpott, neclimdul: Deprecation tests fail when all...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as 891c39b and pushed to 8.5.x

Thanks folks

Wim Leers’s picture

+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -21,8 +21,20 @@
+      if (strpos($method, 'testLegacy') === 0
+        || strpos($method, 'provideLegacy') === 0
+        || strpos($method, 'getLegacy') === 0
+        || strpos(get_class($test), '\Legacy')
+        || in_array('legacy', $util_test_class::getGroups(get_class($test), $method), TRUE)) {
+        // This is a legacy test don't skip deprecations.

Shouldn't we have a CR for these? Apparently I can write test methods like testLegacySomethingBlah() and it won't skip deprecations?

Also: we have nothing that actually uses this?

alexpott’s picture

@Wim Leers this is not really from us this is from Symfony. See https://github.com/symfony/phpunit-bridge/blob/master/DeprecationErrorHa... - nothing has actually changed here. In order to get Symfony's deprecation testing we can't have test methods or classes with legacy in the name as this is deprecated (by Symfony).

Wim Leers’s picture

Ahhh! A comment indicating that that's there just to match upstream logic would've helped make that clear: wouldn't have asked then.

Status: Fixed » Closed (fixed)

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

narasimhan_gobear’s picture

Hi all : Is there a ticket for following the upstream changes and adding them later within phpunit?

Edit : I made the above comment before learning about symfony/phpunit-bridge. Please ignore