magento2
magento2 copied to clipboard
Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById
Add null as possible type returned by getItemById
method.
Method returns null when item is not found.
PHPStan complains in the code using that method: Sample usage:
$product = $productCollection->getItemById(42);
if ($product) { # phpstan: If condition is always true.
// some logic
}
Result in PHPStorm:
Description (*)
Adds null
type to PHPDocs of \Magento\Framework\Data\Collection::getItemById
.
Fixes minor grammar issues in PHPDocs of that class.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
- Create a module that uses any Collection and add code which reflects
if
condition specified in the PR summary - Configure PHPStan with enabled
Treat PHPDoc types as certain
(usually it is enabled by default) - Run static analysis (or open file in IDE with static analysis capabilities such as PHPStorm)
- There should be no warning/error
if condition is always true
Questions or comments
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:
- [x] resolves magento/magento2#38485: Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById
Hi @MTheProgrammer. 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
:exclamation: 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:
-
Database Compare
-
Functional Tests CE
-
Functional Tests EE
-
Functional Tests B2B
-
Integration Tests
-
Magento Health Index
-
Sample Data Tests CE
-
Sample Data Tests EE
-
Sample Data Tests B2B
-
Static Tests
-
Unit Tests
-
WebAPI Tests
-
Semantic Version Checker
You can find more information about the builds here :information_source: 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.
@magento give me test instance
Hi @MTheProgrammer. Thank you for your request. I'm working on Magento instance for you.
Hi @MTheProgrammer, here is your Magento Instance: https://296b3eb03075feb591a2247b997bcc77.instances-prod.magento-community.engineering Admin access: https://296b3eb03075feb591a2247b997bcc77.instances-prod.magento-community.engineering/admin_69bf Login: c25b35a9 Password: 875676b05f1f
@magento run all tests
@magento create issue
@magento run all tests
It fails Semantic Version Checker test because of the fix in PHPDocs, but no API is changed in reality. Code is the same. How to deal with this?
Suggested version increase (based on PHP code analysis and files changed) MAJOR
@magento run all tests
:heavy_check_mark: QA Passed
Manual testing scenario:
- Create a module that uses any Collection and add code which reflects if condition specified in the PR summary
- Configure PHPStan with enabled Treat PHPDoc types as certain (usually it is enabled by default)
- Run static analysis (or open file in IDE with static analysis capabilities such as PHPStorm)
- There should be no warning/error if condition is always true
Before: ❌
Warning stating that if condition is always true.
After: :heavy_check_mark:
There is no warning/error that if condition is always true.
Since the tests are failing, moving this to Extended Testing.
@magento run Functional Tests B2B, Functional Tests EE, Semantic Version Checker
@magento run all tests
@magento run all tests
As SVC tests are failing we have raised a internal approval jira AC-11580, hence moving this to Pending Approval.
Since we got the approval for SVC failure AC-11580, moving this to extended testing because of failed builds.
@magento run all tests
@magento run Functional Tests CE, Functional Tests EE, Functional Tests B2B, Integration Tests, WebAPI Tests
@magento run Functional Tests EE
Functional Tests CE, Functional Tests EE and Functional Tests B2B are different on last two runs on same commit.
Functional Tests CE :
Contains know failures:
ACQE-6102
Run 1 :
Run 2 :
Functional Tests EE :
Contains know failures:
ACQE-6331
Run 1 :
Run 2 :
Functional Tests B2B :
Contains know failures:
ACQE-6363
Run 1 :
Run 2 :
WebAPI Tests :
GRAPHQL WebAPI tests for CE :
Run 1 :
Run 2 :
Executed the same test locally but the error was not reproducible. So this seems to be flaky.
Hence moving this to Merge in Progress
.