Problem/Motivation

In core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php file testRange() function has unused variables such as $name_field and $age_field

 public function testRangeUndo() {
     $query = $this->connection->select('test');
     $name_field = $query->addField('test', 'name');
     $age_field = $query->addField('test', 'age', 'age');
     $query->range(0, 2);
     $query->range(NULL, NULL);
     $query_result = $query->countQuery()->execute()->fetchField();

Proposed resolution

 public function testRangeUndo() {
     $query = $this->connection->select('test');
-    $name_field = $query->addField('test', 'name');
-    $age_field = $query->addField('test', 'age', 'age');
+    $query->addField('test', 'name');
+    $query->addField('test', 'age', 'age');
     $query->range(0, 2);
     $query->range(NULL, NULL);
     $query_result = $query->countQuery()->execute()->fetchField();
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hardik_Patel_12 created an issue. See original summary.

siddhant.bhosale’s picture

Assigned: Unassigned » siddhant.bhosale
siddhant.bhosale’s picture

Assigned: siddhant.bhosale » Unassigned
Status: Needs review » Reviewed & tested by the community

Hi, the patch applies cleanly and the test run without errors. Looks good to be merged.

siddhant.bhosale’s picture

Status: Reviewed & tested by the community » Needs work

As per @kiamlaluno's comment on the similar issue https://www.drupal.org/project/drupal/issues/3158266,
I am changing the status to Needs work.

paulocs’s picture

Status: Needs work » Needs review

So we can see in the issue #1806606: Drupal\Core\Database\Query\Select::range() doesn't correctly implement SelectInterface that those variables were added there.
It's no problem to remove them as they are not used. Bellow is code that added the variablels:

function testRangeUndo() {
    $query = db_select('test');
    $name_field = $query->addField('test', 'name');
    $age_field = $query->addField('test', 'age', 'age');
    $query->range(0, 2);
    $query->range(NULL, NULL);
    $query_result = $query->countQuery()->execute()->fetchField();

    $this->assertEqual($query_result, 4, 'Returned the correct number of rows.');
  }

Cheers,
Paulo

paulocs’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed fde0132b02 to 9.1.x and 1345c2113c to 9.0.x and bcc48076e3 to 8.9.x. Thanks!

  • alexpott committed fde0132 on 9.1.x
    Issue #3158270 by Hardik_Patel_12, siddhant.bhosale, paulocs: Unused...

  • alexpott committed 1345c21 on 9.0.x
    Issue #3158270 by Hardik_Patel_12, siddhant.bhosale, paulocs: Unused...

  • alexpott committed bcc4807 on 8.9.x
    Issue #3158270 by Hardik_Patel_12, siddhant.bhosale, paulocs: Unused...
alexpott’s picture

Version: 9.1.x-dev » 8.9.x-dev

Backported to 8.9.x to keep tests aligned.

Status: Fixed » Closed (fixed)

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