Problem/Motivation

In #2935755: Add a trait to allow dynamic setting of expected deprecations we've tried to introduce expectDeprecation() for tests but it does not work for Kernel tests or Browser tests because they are run in isolated mode.

Proposed resolution

Fix it so it does and so we can use it in #2936704: Remove REST route deprecations from DeprecationListenerTrait::getSkippedDeprecations(), use ExpectDeprecationTrait::expectDeprecation() instead

Remaining tasks

User interface changes

None

API changes

to be decided

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
9.58 KB
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
794 bytes
9.58 KB

No remarks for #2, except that we need a failing test-only patch. So, extracted that from the patch in #2, and also reuploaded #2.

Ran locally, confirmed the test-only patch fails, the other one passes, so pre-emptively RTBC'ing.

Wim Leers’s picture

Issue tags: +@deprecated

The last submitted patch, 3: 2936802-2-test-only-FAIL.patch, failed testing. View results

Wim Leers’s picture

🎉

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

larowlan’s picture

+++ b/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php
@@ -32,36 +42,53 @@ protected function expectDeprecation($msg) {
+    // @todo something about isolated tests

is this comment still valid?

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.37 KB
9.81 KB

Ah yes I meant to add a comment there. And whilst adding the comment I realised we had not tested both sides of the if in the code below - ie. writing the first expected deprecation to a file and then another.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

#9: Can't believe I did not see that :(

#10: wow, I did not realize you could test multiple deprecations in one test, great!

dawehner’s picture

  1. +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
    @@ -50,6 +69,26 @@ protected function deprecationEndTest($test, $time) {
    +
    +    $r = new \ReflectionProperty($test, 'runTestInSeparateProcess');
    +    $r->setAccessible(TRUE);
    +
    +    return $r->getValue($test);
    

    wow \PHPUnit_Framework_TestCase::setRunTestInSeparateProcess is pretty sad

  2. +++ b/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php
    @@ -32,36 +42,54 @@ protected function expectDeprecation($msg) {
    +      if ($trait = $this->getSymfonyTestListenerTrait()) {
    +        // Add the expected deprecation message to the class property.
    +        $reflection_class = new \ReflectionClass($trait);
    +        $expected_deprecations_property = $reflection_class->getProperty('expectedDeprecations');
    +        $expected_deprecations_property->setAccessible(TRUE);
    +        $expected_deprecations = $expected_deprecations_property->getValue($trait);
    +        $expected_deprecations = array_merge($expected_deprecations, $messages);
    +        $expected_deprecations_property->setValue($trait, $expected_deprecations);
    ...
    +        // Register the error handler if necessary.
    +        $previous_error_handler_property = $reflection_class->getProperty('previousErrorHandler');
    +        $previous_error_handler_property->setAccessible(TRUE);
    +        $previous_error_handler = $previous_error_handler_property->getValue($trait);
    +        if (!$previous_error_handler) {
    +          $previous_error_handler = set_error_handler([$trait, 'handleError']);
    +          $previous_error_handler_property->setValue($trait, $previous_error_handler);
    +        }
    +        return;
    

    Offtopic: Do we have an upstream issue to allow us to do that in a nice way?

Wim Leers’s picture

Offtopic: Do we have an upstream issue to allow us to do that in a nice way?

https://github.com/symfony/symfony/pull/25757

larowlan’s picture

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

Committed 6a3ba02 and pushed to 8.6.x

Can cherry-pick after the alpha

  • larowlan committed 6a3ba02 on 8.6.x
    Issue #2936802 by alexpott, Wim Leers: expectDeprecation() doesn't work...

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2936802-10.patch, failed testing. View results

alexpott’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Needs work » Reviewed & tested by the community

Patch was committed to 8.6.x moving issue back to 8.5.x

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Cherry picked as 9414fb5 and pushed to 8.5.x.

  • larowlan committed 9414fb5 on 8.5.x
    Issue #2936802 by alexpott, Wim Leers: expectDeprecation() doesn't work...

Status: Fixed » Closed (fixed)

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