Fix PHP Unit tests and code style

Created on 13 October 2023, about 1 year ago

Problem/Motivation

PHP Unit test failing and PHPCS is reporting errors after ugrading masquerade to revision 2.0.0-rc4 and PHP8.

Steps to reproduce

Run PHPUnit tests and PHPCS.

PHPUnit

Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::testMasqueradeAsRole
Undefined property: Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user
/builds/wsg/drupal9/web/modules/contrib/masquerade_as_role/tests/src/Functional/MasqueradeAsRoleTest.php:29
/builds/wsg/drupal9/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
3) Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::testCleanupRegular
Undefined property: Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user
/builds/wsg/drupal9/web/modules/contrib/masquerade_as_role/tests/src/Functional/MasqueradeAsRoleTest.php:73
/builds/wsg/drupal9/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
4) Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::testMasqueradeAsRoleCron
Undefined property: Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user
/builds/wsg/drupal9/web/modules/contrib/masquerade_as_role/tests/src/Functional/MasqueradeAsRoleTest.php:95
/builds/wsg/drupal9/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

PHPStan reports the same errors:

------ ------------------------------------------------------------------------------------------------------------------- 
  Line   modules/contrib/masquerade_as_role/tests/src/Functional/MasqueradeAsRoleTest.php                                   
 ------ ------------------------------------------------------------------------------------------------------------------- 
  29     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  34     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$auth_user.       
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  39     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  41     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$editor_role.     
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  42     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$moderator_role.  
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  45     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  46     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  53     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  55     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  63     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  73     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  77     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$editor_role.     
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  78     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$moderator_role.  
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  95     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$admin_user.      
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  99     Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$editor_role.     
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
  100    Access to an undefined property Drupal\Tests\masquerade_as_role\Functional\MasqueradeAsRoleTest::$moderator_role.  
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property                               
 ------ ------------------------------------------------------------------------------------------------------------------- 

PHPCS

----------------------------------------------------------------------
FILE: ...s/contrib/masquerade_as_role/src/Controller/SwitchController.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | ERROR | [x] Use statements should be sorted alphabetically. The
   |       |     first wrong one is
   |       |     Drupal\masquerade\Controller\SwitchController.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
FILE: ...web/modules/contrib/masquerade_as_role/masquerade_as_role.module
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 9 | ERROR | [x] Use statements should be sorted alphabetically. The
   |       |     first wrong one is
   |       |     Drupal\Core\Block\BlockPluginInterface.
----------------------------------------------------------------------

Proposed resolution

Member variable names were changed in the base class MasqueradeWebTestBase. See https://git.drupalcode.org/project/masquerade/-/commit/8a9cb9ded6c72787b...
Use the new variable names.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇨🇦Canada karolinam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024