Skip to content

\Magento\Framework\Filesystem\Io\File::read() method is not compatible with \Magento\Framework\Filesystem\Io\IoInterface::read() #27866

Closed
@bnymn

Description

@bnymn

Let's first define some classes here that I am going to mention a lot in the description.

use Magento\Framework\Filesystem\Io\IoInterface;
use Magento\Framework\Filesystem\Io\Sftp;
use Magento\Framework\Filesystem\Io\File;

I am using Sftp class in order to download some files from a remote server. In my class, I depend on IoInterface and resolve the dependency in di.xml. In my test, I would like to use File implementation, because I have more control over the local file system then the remote SFTP server.

In the method definition of IoInterface, it says that the second argument can be a resource.
image

If I give the second argument as a resource it works just fine in the Sftp implementation. However, the File implementation uses copy function of PHP, and it expects the second argument to be a string only.
image

Preconditions (*)

  1. Magento 2.4-develop
  2. PHP 7.4

Steps to reproduce (*)

  1. Try to run the following code block in a fresh magento installation.
$file = \Magento\Framework\App\ObjectManager::getInstance(\Magento\Framework\Filesystem\Io\File::class);
file_put_contents('/tmp/sample_file', 'Some test file');
$targetHandle = fopen('/tmp/' . rand(), 'w');
$file->cd('/tmp');
$result = $file->read('sample_file', $targetHandle);
var_dump($result);

Expected result (*)

  1. I expect the file to be copied to the target path.

Actual result (*)

  1. Unfortunately, it gives an error because the copy function requires the second argument to be string.

Metadata

Metadata

Assignees

Labels

Component: Framework/FilesystemFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.0Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions