Problem/motivation:

Warnings of deprecation code and coding standards

Line   phpunit_example/tests/src/Unit/AddClassTest.php                    
 ------ ------------------------------------------------------------------- 
  114    Call to deprecated method setExpectedException() of class          
         Drupal\Tests\UnitTestCase:                                         
         in drupal:8.8.0 and is removed from drupal:9.0.0.                  
         Backward compatibility for PHPUnit 4 will no longer be supported.  

 Line   phpunit_example/tests/src/Unit/ProtectedPrivatesTest.php           
 ------ ------------------------------------------------------------------- 
  113    Call to deprecated method setExpectedException() of class          
         Drupal\Tests\UnitTestCase:                                         
         in drupal:8.8.0 and is removed from drupal:9.0.0.                  
         Backward compatibility for PHPUnit 4 will no longer be supported.  
  143    Call to deprecated method setExpectedException() of class          
         Drupal\Tests\UnitTestCase:                                         
         in drupal:8.8.0 and is removed from drupal:9.0.0.                  
         Backward compatibility for PHPUnit 4 will no longer be supported. 

  1x: Drupal\Tests\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/3083055, which includes recommendations on which theme to use.
    1x in PHPUnitExampleMenuTest::testLinksAndPages from Drupal\Tests\phpunit_example\Functional

FILE: examples/phpunit_example/src/ProtectedPrivates.php
--------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------
 52 | WARNING | Unused private method privateAdd()
--------------------------------------------------------------------------------------------------------


FILE: examples/phpunit_example/src/DisplayManager.php
-----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------
 20 | ERROR | Missing member variable doc comment
--------------------------------------------------------------------------------
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Malevi4 created an issue. See original summary.

Malevi4’s picture

Issue summary: View changes
Malevi4’s picture

Add patch replace_deprecated_class-3072441-1.patch

osab’s picture

Status: Active » Needs review
andypost’s picture

Title: Replace deprecated class setExpectedException() » [8.8 core] Replace deprecated class setExpectedException()
Issue tags: +PHPUnit
Kristen Pol’s picture

Issue tags: +Drupal 9 compatibility

Per a Slack discussion with Gábor Hojtsy regarding usage of D9 tags (Drupal 9, Drupal 9 compatibility, Drupal 9 readiness, etc.), "Drupal 9 compatibility" should be used for contributed projects that need updating and "Drupal 9" was the old tag for D8 issues before the D9 branch was ready. Doing tag cleanup here based on that discussion.

jungle’s picture

Title: [8.8 core] Replace deprecated class setExpectedException() » Tidy up phpunit_example
Assigned: Unassigned » jungle
Issue summary: View changes
Status: Needs review » Needs work

There are two more tiny issues in the phpunit_example module, for which I do not want to create new issues. So I'd submit a little big patch in one go to get the whole module looks good again here.

  • $defaultTheme is required
  • coding standards
jungle’s picture

Assigned: jungle » Unassigned
Status: Needs work » Needs review
FileSize
3.99 KB

BTW, the attached patch passed on my local.

................................. 33 / 33 (100%)

OK (33 tests, 43 assertions)

jungle’s picture

jungle’s picture

Title: Tidy up phpunit_example » Tidy up and fix phpunit_example
Issue summary: View changes

  • marvil07 committed 8517d03 on 8.x-1.x authored by Malevi4
    Issue #3072441 by Malevi4, jungle: Tidy up and fix phpunit_example
    
marvil07’s picture

Status: Needs review » Fixed

Thanks for all contributions here!

I ran tests for the phpunit_example module locally, before and after the latest patch; and indeed fixes the problem, as mainly mentioned on the related change record.

diff --git a/phpunit_example/src/ProtectedPrivates.php b/phpunit_example/src/ProtectedPrivates.php
index 56c75c4..24278ba 100644
--- a/phpunit_example/src/ProtectedPrivates.php
+++ b/phpunit_example/src/ProtectedPrivates.php
@@ -35,6 +35,7 @@ class ProtectedPrivates {
     return $adder->add($a, $b);
   }
   
+  // phpcs:disable
   /**
    * A simple addition method with validity checking.
    *
@@ -53,5 +54,6 @@ class ProtectedPrivates {
     $adder = new AddClass();
     return $adder->add($a, $b);
   }
+  // phpcs:enable
 
 }

I am not fully convinced of this change, but since it is mainly used from tests itself, I am OK with for now.
We can revert this hunk if needed in the future.

Status: Fixed » Closed (fixed)

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