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

Fixes incorrectly cased namespace usages. #37574

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Jun 3, 2023

Description (*)

While playing around with phpstan on level 0 on the Magento codebase, these problems showed up (among many others, but those are for another day)

$ vendor/bin/phpstan analyse --level=0 lib | grep 'referenced with incorrect case'
 3929/3929 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

  10     Class Magento\Framework\DB\Select referenced with incorrect case: Magento\Framework\Db\Select.

$ vendor/bin/phpstan analyse --level=0 app/code/Magento | grep 'referenced with incorrect case'
 14097/14097 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

  116    Class Magento\GiftMessage\Model\Save referenced with incorrect case: Magento\Giftmessage\Model\Save.
  12     Class Magento\Sales\Model\Order\Creditmemo\Item referenced with incorrect case: Magento\Sales\Model\Order\CreditMemo\Item.
  28     Class Magento\Framework\DB\Select referenced with incorrect case: Magento\Framework\Db\Select.
  9      Class Magento\Sales\Model\Order\Creditmemo\Item referenced with incorrect case: Magento\Sales\Model\Order\CreditMemo\Item.

Update 2025-01-02: More cases were found then the ones listed above. This time not only by using phpstan, but by searching for those I already fixed which revealed more than phpstan was able to find (in comments for example).

This PR fixes these.
I don't think these caused real issues, I think composer's autoloader is gracefully enough to load those incorrectly cased namespaces, but let's make them correct anyways.

Related Pull Requests

Fixed Issues (if relevant)

Manual testing scenarios (*)

  1. Run vendor/bin/phpstan analyse --level=0 {some-path} | grep 'referenced with incorrect case' on all Magento code, it should not output anything (don't run this on the root the M2 codebase, otherwise it will take hours and might crash your computer if you don't have at least 32 GB of memory)
  2. Test all affected code and make sure that everything keeps working as expected (I'm assuming the automated tests will take care of this)

Questions or comments

I might fix (static) test failures if they don't turn out to be too complex to handle, but won't write new automated tests, because I think that's not relevant in scope of this PR.

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 incorrectly cased namespace usages. #38640: Fixes incorrectly cased namespace usages.

@m2-assistant
Copy link

m2-assistant bot commented Jun 3, 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 3, 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 3, 2023

The failure of the semantic version check is in my opinion something to ignore, in practice it shouldn't cause an issue.

Pushed new commit to fix static tests.

@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 5, 2023

Failures in functional tests don't look related at first sight (flaky tests probably)

Only the failure in the semantic version checker is related to this PR, that one will need approval I guess? (is more of a false positive)

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jun 6, 2023
@engcom-Lima
Copy link
Contributor

@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.

@engcom-Charlie
Copy link
Contributor

Hi @hostep,

Thank you for your contribution!

✔️ QA Passed

In order to proceed further on this PR, I have followed the mentioned steps
Before: ✖️
image

After: ✔️
image

As the build is failing, currently moving it further in Extended Testing.

Thank you!

@engcom-Charlie
Copy link
Contributor

@magento run all tests

@engcom-Charlie
Copy link
Contributor

Raised internal approval JIRA for the SVC failure. Moving this PR to Pending Approval now. We will proceed ahead on this once will get all the required approvals.

image

@engcom-Charlie
Copy link
Contributor

@magento create issue

@hostep
Copy link
Contributor Author

hostep commented Dec 30, 2024

@engcom-Charlie: any news?

@engcom-Charlie
Copy link
Contributor

Hi @hostep, as mentioned in here, we are waiting for all required approvals for the SVC failure. Once will get it, we will inform here and proceed further on this.

Thank you for your contribution!!

@hostep
Copy link
Contributor Author

hostep commented Dec 31, 2024

I know, but that was 8 months ago, can't you send a reminder in your approval ticket, maybe somebody forgot to check it?

@hostep
Copy link
Contributor Author

hostep commented Dec 31, 2024

Note to self, found another violation in latest codebase in the setup directory:

$ vendor/bin/phpstan analyse -c ./dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon --level=0 . | grep -B3 'incorrect case'
 20783/20783 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ------------------------------------------------------------------------------------------------------
  Line   app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/Items/GridTest.php
 ------ ------------------------------------------------------------------------------------------------------
  118    Class Magento\GiftMessage\Model\Save referenced with incorrect case: Magento\Giftmessage\Model\Save.
--
 ------ ----------------------------------------------------------------------------------------------------------------------------
  Line   app/code/Magento/Tax/Block/Item/Price/Renderer.php
 ------ ----------------------------------------------------------------------------------------------------------------------------
  12     Class Magento\Sales\Model\Order\Creditmemo\Item referenced with incorrect case: Magento\Sales\Model\Order\CreditMemo\Item.
--
 ------ ------------------------------------------------------------------------------------------------
  Line   app/code/Magento/Tax/Model/Api/SearchCriteria/JoinProcessor/CalculationData.php
 ------ ------------------------------------------------------------------------------------------------
  28     Class Magento\Framework\DB\Select referenced with incorrect case: Magento\Framework\Db\Select.
--
 ------ ------------------------------------------------------------------------------------------------
  Line   lib/internal/Magento/Framework/Setup/Declaration/Schema/DataSavior/SelectGenerator.php
 ------ ------------------------------------------------------------------------------------------------
  10     Class Magento\Framework\DB\Select referenced with incorrect case: Magento\Framework\Db\Select.
--
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------
  Line   setup/src/Magento/Setup/Model/BasePackageInfo.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------
  8      Class Magento\Framework\Filesystem\Directory\ReadFactory referenced with incorrect case: Magento\Framework\FileSystem\Directory\ReadFactory.

Also note to self, make following adjustments, so running phpstan against the entire codebase runs quicker and without errors:

diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon
index c6cf0a2a9c1..d356723e4c7 100644
--- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon
+++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon
@@ -4,11 +4,12 @@ parameters:
     reportUnmatchedIgnoredErrors: false
     excludePaths:
         - %rootDir%/../../../lib/internal/Magento/Framework/ObjectManager/Test/Unit/*
+        - %rootDir%/../../../lib/internal/Magento/Framework/TestFramework/Unit/Listener/*
         - %rootDir%/../../../*/_files/*
-        - %rootDir%/../../../dev/tests/*/Fixtures/*
-        - %rootDir%/../../../dev/tests/*/tmp/*
-        - %rootDir%/../../../dev/tests/*/_generated/*
+        - %rootDir%/../../../dev/tests/*
+        - %rootDir%/../../../generated/*
         - %rootDir%/../../../pub/*
+        - %rootDir%/../../../vendor/*
     scanDirectories:
         - %rootDir%/../../../dev/tests/static/framework/tests/unit/testsuite/Magento
         - %rootDir%/../../../dev/tests/integration/framework/tests/unit/testsuite/Magento

Will try to fix that one in setup as well when I find a bit of time.

@hostep hostep force-pushed the fixes-incorrectly-case-namespace-usages branch from 7336733 to 763b519 Compare December 31, 2024 13:57
@hostep
Copy link
Contributor Author

hostep commented Dec 31, 2024

Fixed more similar problems, have no more time to fix static tests, will follow up in a few days. No need to run tests, I'm aware that failures will happen. Happy NY! :)

@hostep
Copy link
Contributor Author

hostep commented Jan 2, 2025

Found some more issues and fixed more static test failures. Then rebased interactively and squashed/splitted some commits together/out, so they are easier to understand. First commit solves all incorrect case-sensitive usages I was able to find, and the second commit deals with fixing of static test failures.

@magento run all tests

@hostep
Copy link
Contributor Author

hostep commented Jan 2, 2025

@magento run all tests

@hostep
Copy link
Contributor Author

hostep commented Jan 2, 2025

@magento run Static Tests, Integration Tests

@hostep hostep force-pushed the fixes-incorrectly-case-namespace-usages branch from 68744ab to ab8b57e Compare January 2, 2025 23:23
@hostep
Copy link
Contributor Author

hostep commented Jan 2, 2025

@magento run all tests

@hostep
Copy link
Contributor Author

hostep commented Jan 3, 2025

The additional changes done to app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/Items/GridTest.php were to fix a complaint from php mess detector that the number of lines in a method shouldn't exceed 100, since I didn't touch anything originally in that method, I just removed some newslines, to get the number of lines under 100. I didn't want to refactor the whole thing, that is out of scope of this PR.

@magento run Database Compare

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: ready for testing 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
Projects
Status: Pending Approval
Development

Successfully merging this pull request may close these issues.

[Issue] Fixes incorrectly cased namespace usages.
6 participants