Problem/Motivation

Remove unused variable $result from MoveTest. There are couple of instances

    try {
      $result = $this->fileRepository->move(clone $source, $source->getFileUri(), FileSystemInterface::EXISTS_ERROR);
      $this->fail('expected FileExistsException');
    }
    try {
      $result = $this->fileRepository->move(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_ERROR);
      $this->fail('expected FileExistsException');
    }

Steps to reproduce

Proposed resolution

Remaining tasks

Investigate the history of the variable. Why was it added and what happened that made it unused.

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3331212

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anmolgoyal74 created an issue. See original summary.

anmolgoyal74’s picture

Title: Use unused variable $result from MoveTest » Remove unused variable $result from MoveTest
Issue summary: View changes
prabuela’s picture

Assigned: Unassigned » prabuela
prabuela’s picture

StatusFileSize
new1.28 KB

The unused variable are removed from the file.

prabuela’s picture

Assigned: prabuela » Unassigned
Status: Active » Needs review

anup.sinha’s picture

StatusFileSize
new14.84 KB

Hi All,

I have reviewed the changes and it looks good to me. I have executed the kernel "MoveTest" after applying the patch in my local setup and it ran successfully. PFA the screenshot(MoveTest_Success_Execution.png) of the test execution.

Thanks & Regards,
Anup

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work

The code change looks correct. However, when removing an unused variable we should look in to the history. The variable may have been used in the past and perhaps it still should be. Why was the usage removed? Have we lost some test coverage?

Setting needs works for investigation into the history of $result.

anup.sinha’s picture

Status: Needs work » Needs review

Hi @quietone,

Old code in 9.2.x branch:
// Copy the file over itself. Clone the object so we don't have to worry
// about the function changing our reference copy.
$result = file_move(clone $source, $source->uri, FILE_EXISTS_REPLACE);
$this->assertFalse($result, t('File move failed.'));
$this->assertEqual($contents, file_get_contents($source->uri), t('Contents of file were not altered.'));

The file was changed in 9.3.x release in this commit - https://git.drupalcode.org/project/drupal/-/commit/64074071d1c78274df253...
Issue link - https://www.drupal.org/project/drupal/issues/3223209

Here deprecated file_move() function was replaced with service method fileRepository->move(). Now earlier there was an assertFalse() as file_move() function returns TRUE/FALSE but the new service move() function either returns the File entity or throws exception in case of errors. So we cannot use the old assertFalse() check anymore.

So as per my analysis current patch is fine as no test coverage is removed. Request you to check the mentioned commit and let me know please if there is any observation.

Thanks & Regards,
Anup

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new150 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

anup.sinha’s picture

Hi @Prabu,

The automated test bot actually tried to test your merge request instead of the patch. As a a result it failed as there are no changes in that merge request. So request you to close that merge request if you are not planning to use it and put the issue status to needs review.

Thanks & Regards,
Anup

prabuela’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the analysis in #9. We no longer need the variable now we have an exception, so this is change is correct and ready to commit.

  • catch committed bf30a58e on 10.1.x
    Issue #3331212 by PrabuEla, anup.sinha, anmolgoyal74, longwave, quietone...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.