Problem/Motivation

In \\Drupal\FunctionalJavascriptTests\Core\MachineNameTest::testMachineName there is an if (empty($machine_name_1_value ))-statement a few lines after we assertNotEmpty the exact same variable.

Steps to reproduce

Proposed resolution

Remove redundant if (empty($machine_name_1_value ))-statement, since the variable can never be empty, the assertNotEmpty would already have thrown a ExpectationFailedException and fail the tests if it would be.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3387556

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

Spokje created an issue. See original summary.

spokje’s picture

Status: Active » Needs review
spokje’s picture

Title: Remove unneeded if-statements after assertEmpty()s in \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::getTranslation » Remove unneeded if (empty())-statements after assertEmpty()s
spokje’s picture

Assigned: Unassigned » spokje
Status: Needs review » Needs work
spokje’s picture

Title: Remove unneeded if (empty())-statements after assertEmpty()s » Remove unneeded if (empty($foo))-statements after assertEmpty($foo)s
Issue summary: View changes
spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

If I search for in empty\\(\\) always exists and is not falsy find about 39 instances. Should they addressed?

spokje’s picture

They should and will. just not in here.

There are a few smaller ones about "empty not falsy" coming up and after that I am preparing one big issue for the rest of them that have the same, general problem.

These three ones are part of the smaller ones that are specific and don't fit that same, general problem.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for clarifying!

LGTM

xjm’s picture

Status: Reviewed & tested by the community » Needs work

This has some exciting merge conflicts.

spokje’s picture

Issue summary: View changes
spokje’s picture

spokje’s picture

Title: Remove unneeded if (empty($foo))-statements after assertEmpty($foo)s » Remove unneeded if (empty($foo))-statement in MachineNameTest::testMachineName
spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes
spokje’s picture

Title: Remove unneeded if (empty($foo))-statement in MachineNameTest::testMachineName » Remove redundant if (empty($machine_name_1_value))-statement in MachineNameTest::testMachineName
Issue summary: View changes
spokje’s picture

Status: Needs work » Needs review

TIL:

- Merge conflicts can be exiting
- Downscaling due to 2/3 of the original problem already being fixed elsewhere creates a lot of noise when the person behind keyboard tries to make the IS correct again.

Back to NR.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Nice easy fix here, glad that we have PHPStan to spot such things.

  • xjm committed 063a9f70 on 11.x
    Issue #3387556 by Spokje, smustgrave: Remove redundant if (empty($...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

I confirmed the issue reading core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php locally. Very nice cleanup. In PHPStan we trust!

Adding credit for @smustgrave for the scope check. @Spokje's answer makes sense, but it's good to ask the question if the reason for the current scope is not already documented.

Committed to 11.x. I also tried to backport it to 10.1.x since it's a patch-eligible test code cleanup, but there were more merge conflicts in the baseline. (Not exciting ones, just "regenerate the baseline" ones.) That seemed maybe not worth the effort, so leaving fixed against 11.x. Thanks everyone!

Status: Fixed » Closed (fixed)

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