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

Use '===' operator to check if file was written. #26688

Conversation

vovayatsyuk
Copy link
Member

Description

This commit prevents incorrect logic when writing empty string (0 bytes).

See manuals for corresponding functions:

Manual testing scenarios

To test this PR, you need to edit some PHP code. The easiest way is to edit some core code:

  1. Open Magento/Catalog/Controller/Adminhtml/Product/Index.php

  2. Add the following code at the top of execute method:

    $result = \Magento\Framework\App\ObjectManager::getInstance()
        ->get(\Magento\Framework\Filesystem\Driver\File::class)
        ->filePutContents(BP . '/var/log/system.log', '');
    
    echo "Bytes written: " . $result;
    die;
  3. Now open Catalog > Products page.

  4. An exception will be thrown: "The specified "var/log/system.log" file couldn't be written."

  5. Apply the patch and you'll see "Bytes written: 0" message instead of exception.

Questions or comments

Make sure that your web server has write access to the "var/log/system.log" file.

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)

This prevents incorrect logic when writing empty string (0 bytes).
@m2-assistant
Copy link

m2-assistant bot commented Feb 4, 2020

Hi @vovayatsyuk. Thank you for your contribution
Here is 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

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

@ihor-sviziev ihor-sviziev self-assigned this Feb 4, 2020
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 @vovayatsyuk,
Could you fix failing static tests in files that you’ve touched and cover your changes with some kind of tests? I think integration tests is most suitable here

@ihor-sviziev ihor-sviziev added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Feb 11, 2020
… fix-incorrect-exception-when-writing-0-bytes
@engcom-Echo
Copy link
Contributor

I will take care of test coverage.

@engcom-Echo engcom-Echo force-pushed the fix-incorrect-exception-when-writing-0-bytes branch 2 times, most recently from 94cf975 to e2e9a86 Compare February 12, 2020 11:54
@engcom-Echo engcom-Echo force-pushed the fix-incorrect-exception-when-writing-0-bytes branch from e2e9a86 to 66d2cbc Compare February 13, 2020 16:28
@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Feb 14, 2020
@ihor-sviziev
Copy link
Contributor

Functional test failures not related to changes from this pr

@magento-engcom-team
Copy link
Contributor

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

@engcom-Delta
Copy link
Contributor

✔️ QA passed

@m2-assistant
Copy link

m2-assistant bot commented Feb 20, 2020

Hi @vovayatsyuk, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants