Skip to content

Github #31984: fix for array offset bug during some 404s (PHP 7.4) #31985

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

Conversation

erfanimani
Copy link
Contributor

@erfanimani erfanimani commented Feb 8, 2021

Description (*)

Fixes "Trying to access array offset on value of type bool" when accessing certain non existing category paths for known products, on PHP 7.4.

Fixed Issues (if relevant)

  1. Fixes Expecting 404, getting 500: "Trying to access array offset on value of type bool" #31984

Manual testing scenarios (*)

  1. On PHP 7.4, as an admin, set "Generate "category/product" URL Rewrites" to "No"
  2. Make a GET request to {nonexistentcategory}/{product_url} (where product_url is an existing saleable product)
  3. Ensure status code is 404, not 500

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)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Feb 8, 2021

Hi @erfanimani. Thank you for your contribution
Here are some useful tips 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

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

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 @erfanimani,
Could you cover your changes with any type of automated tests?

@ihor-sviziev ihor-sviziev added Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Award: bug fix Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Feb 8, 2021
@erfanimani
Copy link
Contributor Author

@ihor-sviziev I'm thinking it might be hard to isolate this particular issue as it's nested within a few private method calls, but I'll have a look tomorrow — thanks for the feedback

@erfanimani
Copy link
Contributor Author

Hi @ihor-sviziev, I can't create unit tests as the SUT contains only private/protected methods. I can create a MFTF test that reproduces the error (although sometimes it won't, depending on PHP error reporting and PHP version), and simply returns a 404 not found if successful. I'm not sure how relevant a test like that would be for the future. What's your opinion?

See the original issue for steps to reproduce.

@ihor-sviziev
Copy link
Contributor

I don’t think mftf test sis suitable here.
@engcom-Charlie do you feel we can cover this change with some unit / integration test? If so - could you share your thoughts how to do that?

@engcom-Charlie
Copy link
Contributor

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Feb 12, 2021

@erfanimani @engcom-Charlie
TBH I have a feeling that this logic should be extracted to a separate model and tested separately. What do you think?

@m2-community-project m2-community-project bot added Priority: P3 May be fixed according to the position in the backlog. Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Feb 15, 2021
@ihor-sviziev ihor-sviziev added Risk: low and removed Priority: P3 May be fixed according to the position in the backlog. labels Feb 26, 2021
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 @erfanimani,
Could you cover your changes with the unit test, as suggested in #31985 (comment) ?

@erfanimani
Copy link
Contributor Author

Thanks @ihor-sviziev, I'll try and update the PR.

@erfanimani erfanimani force-pushed the github-31984-fix-array-offset-bug branch from b95f3ff to 6316620 Compare March 4, 2021 04:51
@erfanimani
Copy link
Contributor Author

@ihor-sviziev, please see the updated PR. I believe I've got 100% test coverage of the method that was changed. Feedback is appreciated.

Thanks.

@erfanimani erfanimani closed this Mar 5, 2021
@m2-assistant
Copy link

m2-assistant bot commented Mar 5, 2021

Hi @erfanimani, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

/**
* @var UrlRewriteFactory|MockObject
*/
private $urlRewriteFactory;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add "Mock" suffix to all mocks

Suggested change
private $urlRewriteFactory;
private $urlRewriteFactoryMock;

Comment on lines 140 to 147
public function testFindProductRewriteByRequestPath(
$data,
$productFromDb,
$categorySuffix,
$categoryFromDb,
$canBeShownInCategory,
$expectedProductRewrite
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's define object types

Suggested change
public function testFindProductRewriteByRequestPath(
$data,
$productFromDb,
$categorySuffix,
$categoryFromDb,
$canBeShownInCategory,
$expectedProductRewrite
) {
public function testFindProductRewriteByRequestPath(
array $data,
$productFromDb,
string? $categorySuffix,
$categoryFromDb,
bool $canBeShownInCategory,
array? $expectedProductRewrite
): void {

Comment on lines 131 to 136
* @param $data
* @param $productFromDb
* @param $categorySuffix
* @param $categoryFromDb
* @param $canBeShownInCategory
* @param $expectedProductRewrite
Copy link
Contributor

Choose a reason for hiding this comment

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

please define expected types for params

@erfanimani
Copy link
Contributor Author

Thanks for the feedback @ihor-sviziev, I've updated the PR with your suggestions.

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@ihor-sviziev
Copy link
Contributor

@magento run Integration Tests

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-8884 has been created to process this Pull Request

@dmitriyprime
Copy link
Contributor

dmitriyprime commented Apr 23, 2021

✔️ QA pass

Before:
before

✔️ After
after

@m2-assistant
Copy link

m2-assistant bot commented Apr 26, 2021

Hi @erfanimani, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: CatalogUrlRewrite Event: Adobe Summit Hackathon Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4 Risk: low Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expecting 404, getting 500: "Trying to access array offset on value of type bool"
5 participants