Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of some non-existing classes from some unit tests code in the… #37629

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Jun 17, 2023

… Magento framework.

Description (*)

In an attempt at slowly fixing phpstan reported issues in the entire Magento codebase, I took a look today at the Framework code and searched for classes used that don't exist (any more). I've only found some fixes for some unit tests in the Framework code. This fixes 7 errors out of 173 phpstan errors found in total when scanning on level 0 on the Framework code.

Errors fixed:

 ------ ---------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/Filesystem/Test/Unit/File/ExcludeFilterTest.php  
 ------ ---------------------------------------------------------------------------- 
  55     Class SplFileInfoClass not found.                                           
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols         
 ------ ---------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/ObjectManager/Test/Unit/Factory/CompiledTest.php  
 ------ ----------------------------------------------------------------------------- 
  302    Class Magento\Framework\ObjectManager\Test\Unit not found.                   
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols          
  308    Class Magento\Framework\ObjectManager not found.                             
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols          
 ------ ----------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/ObjectManager/Test/Unit/Helper/SortItemsTest.php                                                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  18     Property Magento\Framework\ObjectManager\Test\Unit\Helper\SortItemsTest::$_itemInterpreter has unknown class Magento\Framework\ObjectManager\Test\Unit\Helper\InterpreterInterface as its type.  
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                                                                              
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

------ ---------------------------------------------------------------------- 
  Line   internal/Magento/Framework/Pricing/Test/Unit/Render/PriceBoxTest.php  
 ------ ---------------------------------------------------------------------- 
  77     Class Magento\Store\Model\Store\Config not found.                     
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols   
 ------ ---------------------------------------------------------------------- 

------ ------------------------------------------------------------------------ 
  Line   internal/Magento/Framework/TestFramework/Unit/Helper/ObjectManager.php  
 ------ ------------------------------------------------------------------------ 
  163    Class Magento\Framework\Api\Builder not found.                          
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols     
 ------ ------------------------------------------------------------------------ 

------ -------------------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/DeserializerFactoryTest.php  
 ------ -------------------------------------------------------------------------------------- 
  65     Class Magento\Framework\Webapi\Response\Rest\Renderer\Json not found.                 
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                   
 ------ -------------------------------------------------------------------------------------- 

Related Pull Requests

None

Fixed Issues (if relevant)

None

Manual testing scenarios (*)

  1. Run: vendor/bin/phpstan clear-result-cache && bin/magento setup:di:compile && composer dump-autoload
  2. Run: vendor/bin/phpstan analyse --level=0 lib/
  3. After applying the changes from this PR and re-running steps 1 and 2 from above, you should have 7 fewer errors.
  4. Also check if after these changes, all unit tests keep running correctly (but the automated tests on github should take care of testing this).

Questions or comments

It is my hope that it's Adobe's goal one day to have zero issues that phpstan finds on level 0, since those are the most important ones to fix usually. If we finally have level 0 tackled across the entire codebase, we can slowly go up one by one which would also allow the checks in pull requests here to be made against a higher level than only 0, which in the end should hopefully result in a lot more stable code then what we have right now.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Cleanup of some non-existing classes from some unit tests code in the… #37636: Cleanup of some non-existing classes from some unit tests code in the…

@m2-assistant
Copy link

m2-assistant bot commented Jun 17, 2023

Hi @hostep. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@hostep
Copy link
Contributor Author

hostep commented Jun 17, 2023

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep
Copy link
Contributor Author

hostep commented Jun 18, 2023

Fixed 2 more static failures:

1) Magento\Test\Php\LiveCodeTest::testCodeStyle
PHP Code Sniffer detected 1 violation(s): 

FILE: /var/www/html/lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/DeserializerFactoryTest.php
------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------
 3 | WARNING | Copyright is missing or has wrong format
------------------------------------------------------------------------------------------------------------



Failed asserting that 1 matches expected 0.

/var/www/html/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php:254

2) Magento\Test\Php\LiveCodeTest::testPhpStan
PHPStan detected violation(s):
 ------ ----------------------------------------------------------------------- 
  Line   lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ExcludeFilte  
         rTest.php                                                              
 ------ ----------------------------------------------------------------------- 
  39     Variable $result might not be defined.                                 
 ------ ----------------------------------------------------------------------- 

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@ihor-sviziev ihor-sviziev added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jun 19, 2023
@m2-community-project m2-community-project bot added this to Pending Review in Pull Requests Dashboard Jun 19, 2023
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔ Approved.

Failing tests look not related to changes from this PR.

@m2-community-project m2-community-project bot moved this from Pending Review to Ready for Testing in Pull Requests Dashboard Jun 19, 2023
@engcom-Lima engcom-Lima self-assigned this Jun 19, 2023
@engcom-Lima engcom-Lima moved this from Ready for Testing to Testing in Progress in Pull Requests Dashboard Jun 19, 2023
@m2-community-project m2-community-project bot moved this from Testing in Progress to Ready for Testing in Pull Requests Dashboard Jun 19, 2023
@m2-community-project m2-community-project bot moved this from Ready for Testing to Testing in Progress in Pull Requests Dashboard Jun 19, 2023
@engcom-Lima
Copy link
Contributor

@magento create issue

@engcom-Lima
Copy link
Contributor

@magento run Functional Tests B2B ,Functional Tests EE, Functional Tests CE, WebAPI Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Lima
Copy link
Contributor

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop and PHP 8.1

Manual testing scenario:

  • Run: vendor/bin/phpstan clear-result-cache && bin/magento setup:di:compile && composer dump-autoload
  • Run: vendor/bin/phpstan analyse --level=0 lib/

After: ✔️ Verified below errors are not coming in the output &
Unit test were running smoothly

 ------ ---------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/Filesystem/Test/Unit/File/ExcludeFilterTest.php  
 ------ ---------------------------------------------------------------------------- 
  55     Class SplFileInfoClass not found.                                           
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols         
 ------ ---------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/ObjectManager/Test/Unit/Factory/CompiledTest.php  
 ------ ----------------------------------------------------------------------------- 
  302    Class Magento\Framework\ObjectManager\Test\Unit not found.                   
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols          
  308    Class Magento\Framework\ObjectManager not found.                             
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols          
 ------ ----------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/ObjectManager/Test/Unit/Helper/SortItemsTest.php                                                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  18     Property Magento\Framework\ObjectManager\Test\Unit\Helper\SortItemsTest::$_itemInterpreter has unknown class Magento\Framework\ObjectManager\Test\Unit\Helper\InterpreterInterface as its type.  
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                                                                              
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

------ ---------------------------------------------------------------------- 
  Line   internal/Magento/Framework/Pricing/Test/Unit/Render/PriceBoxTest.php  
 ------ ---------------------------------------------------------------------- 
  77     Class Magento\Store\Model\Store\Config not found.                     
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols   
 ------ ---------------------------------------------------------------------- 

------ ------------------------------------------------------------------------ 
  Line   internal/Magento/Framework/TestFramework/Unit/Helper/ObjectManager.php  
 ------ ------------------------------------------------------------------------ 
  163    Class Magento\Framework\Api\Builder not found.                          
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols     
 ------ ------------------------------------------------------------------------ 

------ -------------------------------------------------------------------------------------- 
  Line   internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/DeserializerFactoryTest.php  
 ------ -------------------------------------------------------------------------------------- 
  65     Class Magento\Framework\Webapi\Response\Rest\Renderer\Json not found.                 
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                   
 ------ -------------------------------------------------------------------------------------- 


1) Magento\Test\Php\LiveCodeTest::testCodeStyle
PHP Code Sniffer detected 1 violation(s): 

FILE: /var/www/html/lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/DeserializerFactoryTest.php
------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------
 3 | WARNING | Copyright is missing or has wrong format
------------------------------------------------------------------------------------------------------------



Failed asserting that 1 matches expected 0.

/var/www/html/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php:254

2) Magento\Test\Php\LiveCodeTest::testPhpStan
PHPStan detected violation(s):
 ------ ----------------------------------------------------------------------- 
  Line   lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ExcludeFilte  
         rTest.php                                                              
 ------ ----------------------------------------------------------------------- 
  39     Variable $result might not be defined.                                 
 ------ ----------------------------------------------------------------------- 

Builds are failed. Hence, moving this PR to Extended Testing.

@engcom-Lima engcom-Lima moved this from Testing in Progress to Extended Testing (optional) in Pull Requests Dashboard Jun 20, 2023
@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, WebAPI Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep
Copy link
Contributor Author

hostep commented Jun 27, 2023

@ihor-sviziev: the only code touched is from within unit test code, I'm almost 100% sure that the functional & web api tests don't use any of this code.

@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests B2B, WebAPI Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Echo
Copy link
Contributor

@magento run Functional Tests B2B,WebAPI Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Echo
Copy link
Contributor

Functional Tests B2B test failure are different on last two run on same commit.
Run1
image

Run2
image

Hence moving to Merge In Progress.

@engcom-Echo engcom-Echo moved this from Extended Testing (optional) to Merge in Progress in Pull Requests Dashboard Jul 13, 2023
@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 8e9fd0e into magento:2.4-develop Oct 20, 2023
11 of 12 checks passed
@engcom-Charlie engcom-Charlie moved this from Merge in Progress to Recently Merged in Pull Requests Dashboard Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept
Projects
Pull Requests Dashboard
  
Recently Merged
Development

Successfully merging this pull request may close these issues.

[Issue] Cleanup of some non-existing classes from some unit tests code in the…
5 participants