magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById

Open MTheProgrammer opened this issue 1 year ago • 7 comments

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: image

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 (*)

  1. Create a module that uses any Collection and add code which reflects if condition specified in the PR summary
  2. Configure PHPStan with enabled Treat PHPDoc types as certain (usually it is enabled by default)
  3. Run static analysis (or open file in IDE with static analysis capabilities such as PHPStorm)
  4. 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:

  1. [x] resolves magento/magento2#38485: Fix PHPDocs for \Magento\Framework\Data\Collection::getItemById

MTheProgrammer avatar Feb 13 '24 02:02 MTheProgrammer

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

m2-assistant[bot] avatar Feb 13 '24 02:02 m2-assistant[bot]

@magento give me test instance

MTheProgrammer avatar Feb 13 '24 02:02 MTheProgrammer

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

MTheProgrammer avatar Feb 13 '24 02:02 MTheProgrammer

@magento create issue

engcom-Delta avatar Feb 29 '24 13:02 engcom-Delta

@magento run all tests

andrewbess avatar Feb 29 '24 15:02 andrewbess

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

MTheProgrammer avatar Mar 05 '24 02:03 MTheProgrammer

@magento run all tests

engcom-Echo avatar Mar 05 '24 10:03 engcom-Echo

:heavy_check_mark: QA Passed

Manual testing scenario:

  1. Create a module that uses any Collection and add code which reflects if condition specified in the PR summary
  2. Configure PHPStan with enabled Treat PHPDoc types as certain (usually it is enabled by default)
  3. Run static analysis (or open file in IDE with static analysis capabilities such as PHPStorm)
  4. There should be no warning/error if condition is always true

Before: ❌ image Warning stating that if condition is always true.

After: :heavy_check_mark: Screenshot 2024-03-07 at 1 42 54 PM There is no warning/error that if condition is always true.

Since the tests are failing, moving this to Extended Testing.

engcom-November avatar Mar 07 '24 12:03 engcom-November

@magento run Functional Tests B2B, Functional Tests EE, Semantic Version Checker

engcom-November avatar Mar 07 '24 12:03 engcom-November

@magento run all tests

engcom-November avatar Mar 07 '24 13:03 engcom-November

@magento run all tests

engcom-November avatar Mar 11 '24 05:03 engcom-November

As SVC tests are failing we have raised a internal approval jira AC-11580, hence moving this to Pending Approval.

engcom-November avatar Mar 13 '24 05:03 engcom-November

Since we got the approval for SVC failure AC-11580, moving this to extended testing because of failed builds.

engcom-November avatar Mar 19 '24 07:03 engcom-November

@magento run all tests

engcom-Hotel avatar Apr 02 '24 05:04 engcom-Hotel

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

engcom-November avatar Apr 02 '24 09:04 engcom-November

@magento run Functional Tests EE

engcom-November avatar Apr 03 '24 09:04 engcom-November

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 : image

Run 2 : image

Functional Tests EE : Contains know failures: ACQE-6331 Run 1 : image

Run 2 : image

Functional Tests B2B : Contains know failures: ACQE-6363 Run 1 : image

Run 2 : image

engcom-November avatar Apr 03 '24 12:04 engcom-November

WebAPI Tests : GRAPHQL WebAPI tests for CE : Run 1 : image

Run 2 : image

Executed the same test locally but the error was not reproducible. So this seems to be flaky.

Hence moving this to Merge in Progress.

engcom-November avatar Apr 03 '24 13:04 engcom-November