Skip to content

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Jul 21, 2023

Description (*)

These were found by running phpstan with level 0 on all code in app/code/Magento

The first commit deals with the description here, further commits are to fix failing tests.

Related Pull Requests

Similar fixes as in #37629 (but that was for code in lib/internal/Magento/Framework)

Fixed Issues (if relevant)

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 -c ./dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon app/code/Magento/ (if you don't use a very modern computer with a very good processor and enough memory, it might take a long time to run, or even crash)
  3. After applying the changes from this PR and re-running steps 1 and 2 from above, you should have 16 fewer errors.
  4. Try printing a creditmemo as pdf file in the backoffice, the filename you get should be creditmemo{current-date}.pdf
  5. Make sure reindexing of stocks still works as expected
  6. All automated tests should keep running correctly I hope

Questions or comments

Changes include:

  • properly ignoring phpstan errors for classes that don't exist in the codebase but are declared as a virtualType (which phpstan doesn't know about)
  • fixing non existing classes in unit tests to existing classes (shows that all this mocking of classes in phpunit doesn't assure anything)
  • a real bugfix in Magento\CatalogInventory\Model\Indexer\Stock\Action\FullAction where if you inherit from the class, and call the parent constructor and do not provide a value for $batchSizeManagement, it will try to load a non-existing class and crash
  • a real bugfix in Magento\Sales\Controller\Adminhtml\Creditmemo\AbstractCreditmemo\PrintAction to fix the filename for creditmemo pdf files, it seems like this bug was accidentally introduced in d7ff74d#diff-b6974c4da004f8f764ba347774b2f3dbfeebab760c91f2f4c647dff63fcb6bfe
  • implementing HttpGetActionInterface interface PrintAction class (revealed by failing static test in this PR)
  • fixing extra phpstan failures around activeTableSwitcher->switchTable line where the variables $indexer aren't guaranteed to exist
  • a bunch of static test failure fixes

This fixes the following phpstan errors:

 ------ -------------------------------------------------------------------------------------- Line Catalog/Model/ProductRepository.php ------ -------------------------------------------------------------------------------------- 809 Class Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ -------------------------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line Catalog/Test/Unit/Model/ResourceModel/AttributeTest.php ------ --------------------------------------------------------------------- 82 Class Magento\ResourceConnections\DB\Select not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- ------ ----------------------------------------------------------------------------------- Line CatalogInventory/Model/Indexer/Stock/Action/Full.php ------ ----------------------------------------------------------------------------------- 128 Class Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 206 Variable $indexer might not be defined. 206 Variable $indexer might not be defined. ------ ----------------------------------------------------------------------------------- ------ ----------------------------------------------------------------------------------- Line CatalogRule/Model/ResourceModel/Rule.php ------ ----------------------------------------------------------------------------------- 266 Class Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ----------------------------------------------------------------------------------- ------ ----------------------------------------------------------------------------------- Line CatalogRule/Model/ResourceModel/Rule/Collection.php ------ ----------------------------------------------------------------------------------- 168 Class Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ----------------------------------------------------------------------------------- ------ ------------------------------------------------------------------------------- Line Cms/Model/PageRepository.php ------ ------------------------------------------------------------------------------- 294 Class Magento\Cms\Model\Api\SearchCriteria\PageCollectionProcessor not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ------------------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line Paypal/Observer/AddPaypalShortcutsObserver.php ------ --------------------------------------------------------------------- 60 Class Magento\Paypal\Block\WpsExpress\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 61 Class Magento\Paypal\Block\WpsBml\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 62 Class Magento\Paypal\Block\PayflowExpress\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 63 Class Magento\Paypal\Block\Payflow\Bml\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- ------ -------------------------------------------------------------------------- Line Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php ------ -------------------------------------------------------------------------- 76 Class creditmemo not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ -------------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line Sales/Test/Unit/Helper/ReorderTest.php ------ --------------------------------------------------------------------- 81 Class Magento\Sales\Model\Store not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- ------ --------------------------------------------------------------------------------- Line SalesRule/Model/ResourceModel/Rule.php ------ --------------------------------------------------------------------------------- 88 Class Magento\SalesRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------------------- ------ --------------------------------------------------------------------------------- Line SalesRule/Model/ResourceModel/Rule/Collection.php ------ --------------------------------------------------------------------------------- 456 Class Magento\SalesRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line Theme/Test/Unit/Model/Config/ValidatorTest.php ------ --------------------------------------------------------------------- 77 Class Magento\Email\Model\TemplateInterface not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 122 Class Magento\Email\Model\TemplateInterface not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- 

I won't be adding more automated tests, unless it's really expected, but I might need some help for that...

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] Fixes incorrect classes being referenced in Magento modules. #39126: Fixes incorrect classes being referenced in Magento modules.
@m2-assistant
Copy link

m2-assistant bot commented Jul 21, 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 Jul 21, 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 hostep force-pushed the cleanup-some-non-existing-classes-from-magento-modules branch from f5663d3 to 09f3deb Compare July 21, 2023 16:15
@hostep
Copy link
Contributor Author

hostep commented Jul 21, 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 Jul 21, 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 Jul 22, 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 Jul 22, 2023

Okay, everything seems to be stable again. Current failed tests don't look related to changes in this PR at first sight.

Can be reviewed & tested now, let me know if something is not clear, thanks! 🙂

@engcom-Charlie engcom-Charlie added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jul 25, 2023
@hostep hostep force-pushed the cleanup-some-non-existing-classes-from-magento-modules branch from 4a962f5 to 105ef98 Compare April 17, 2024 07:23
@hostep
Copy link
Contributor Author

hostep commented Apr 17, 2024

Rebased on latest 2.4-develop branch, fixed merge conflicts and force pushed, because the file app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php was in conflict due to changes introduced in 9ab6691

@magento run all tests

@engcom-Delta engcom-Delta added the Project: Community Picked PRs upvoted by the community label Aug 16, 2024
@engcom-Bravo engcom-Bravo added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Aug 19, 2024
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.

Hi @hostep,
Could you please fix the conflicts?

@hostep
Copy link
Contributor Author

hostep commented Aug 20, 2024

@hostep hostep force-pushed the cleanup-some-non-existing-classes-from-magento-modules branch from 105ef98 to 9aef3e7 Compare August 20, 2024 19:20
@hostep
Copy link
Contributor Author

hostep commented Aug 20, 2024

Rebased, solved conflicts and force pushed.

Only 13 errors got fixed now instead of 16 before, because in the commits referenced earlier some fixes were already done, these are the 13 ones that are fixed now:

 ------ -------------------------------------------------------------------------------------- Line Catalog/Model/ProductRepository.php ------ -------------------------------------------------------------------------------------- 817 Class Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ -------------------------------------------------------------------------------------- ------ ----------------------------------------------------------------------------------- Line CatalogInventory/Model/Indexer/Stock/Action/Full.php ------ ----------------------------------------------------------------------------------- 128 Class Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ----------------------------------------------------------------------------------- ------ ----------------------------------------------------------------------------------- Line CatalogRule/Model/ResourceModel/Rule.php ------ ----------------------------------------------------------------------------------- 133 Class Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ----------------------------------------------------------------------------------- ------ ----------------------------------------------------------------------------------- Line CatalogRule/Model/ResourceModel/Rule/Collection.php ------ ----------------------------------------------------------------------------------- 168 Class Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ----------------------------------------------------------------------------------- ------ ------------------------------------------------------------------------------- Line Cms/Model/PageRepository.php ------ ------------------------------------------------------------------------------- 294 Class Magento\Cms\Model\Api\SearchCriteria\PageCollectionProcessor not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ------------------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line Paypal/Observer/AddPaypalShortcutsObserver.php ------ --------------------------------------------------------------------- 60 Class Magento\Paypal\Block\WpsExpress\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 61 Class Magento\Paypal\Block\WpsBml\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 62 Class Magento\Paypal\Block\PayflowExpress\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 63 Class Magento\Paypal\Block\Payflow\Bml\Shortcut not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- ------ -------------------------------------------------------------------------- Line Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php ------ -------------------------------------------------------------------------- 76 Class creditmemo not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ -------------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line Sales/Test/Unit/Helper/ReorderTest.php ------ --------------------------------------------------------------------- 81 Class Magento\Sales\Model\Store not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- ------ --------------------------------------------------------------------------------- Line SalesRule/Model/ResourceModel/Rule.php ------ --------------------------------------------------------------------------------- 88 Class Magento\SalesRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------------------- ------ --------------------------------------------------------------------------------- Line SalesRule/Model/ResourceModel/Rule/Collection.php ------ --------------------------------------------------------------------------------- 467 Class Magento\SalesRule\Model\ResourceModel\Rule\AssociatedEntityMap not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------------------- 

@magento run all tests

@hostep
Copy link
Contributor Author

hostep commented Aug 21, 2024

Failed tests don't seem related to changes here, so can be reviewed again.

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run Static Tests, Integration Tests

@engcom-November
Copy link
Contributor

Hello @hostep,

Thank you for the collaboration and contribution!

✔️ QA Passed

Steps to reproduce:

  • Run: vendor/bin/phpstan clear-result-cache && bin/magento setup:di:compile && composer dump-autoload
  • Run: vendor/bin/phpstan analyse --level=0 -c ./dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon app/code/Magento/

Before: ✖️
There used to be 210 phpstan errors.
image

After: ✔️
13 error's has been fixed.
image

Since there are build failures, moving this to Extended Testing.

@engcom-November
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests EE, Static Tests

@engcom-November
Copy link
Contributor

engcom-November commented Aug 28, 2024

The repeating Functional Test EE failure is falky and known issue.

Functional Tests B2B
Run 1:
image

Run 2:
image

Functional Tests EE
Run 1:
image

Run 2:
image

Known issues:
ACQE-6331 - StorefrontCreateOrderAllQuantityGroupedProductOptionDefaultStockTest

Hence moving this to Merge in progress.

@engcom-November
Copy link
Contributor

@magento create issue

@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 86074a0 into magento:2.4-develop Sep 5, 2024
9 of 11 checks passed
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 Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
8 participants