Problem/Motivation

In core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php setUp() initializes $method_definitions but never uses it.

$method_definitions = [
      LanguageNegotiationUrl::METHOD_ID => [
        'class' => '\Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl',
        'weight' => 9,
      ],
    ];

Proposed resolution

$method_definitions needs to be removed from the code.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hardik_Patel_12 created an issue. See original summary.

Hardik_Patel_12’s picture

Title: Remove Unused variable $node_storage from PathProcessorTest.php file » Remove Unused variable $method_definitions from PathProcessorTest.php file
Hardik_Patel_12’s picture

Status: Active » Needs review
FileSize
792 bytes

Kindly review a patch.

Status: Needs review » Needs work

The last submitted patch, 3: 3156345-3.patch, failed testing. View results

S_Bhandari’s picture

Assigned: Unassigned » S_Bhandari
S_Bhandari’s picture

Added a patch for the same.

ravi.shankar’s picture

Status: Needs work » Needs review
S_Bhandari’s picture

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

Status: Needs work » Needs review
apaderno’s picture

Issue summary: View changes
apaderno’s picture

Status: Needs review » Reviewed & tested by the community

$method_definitions was added in #1862202: Objectify the language system, which changed the code of PathProcessorTest::setUp() to the following one. (The relative commit is 0b55dcd84190efb23e9db99e9fc135979aeec9bc.)

  public function setUp() {

    // Set up some languages to be used by the language-based path processor.
    $languages = array();
    foreach (array('en' => 'English', 'fr' => 'French') as $langcode => $language_name) {
      $language = new \stdClass();
      $language->id = $langcode;
      $language->name = $language_name;
      $languages[$langcode] = $language;
    }
    $this->languages = $languages;

    // Create a stub configuration.
    $language_prefixes = array_keys($this->languages);
    $config = array(
      'url' => array(
        'prefixes' => array_combine($language_prefixes, $language_prefixes)
      )
    );

    // Create a URL-based language negotiation method definition.
    $method_definitions = array(
      LanguageNegotiationUrl::METHOD_ID => array(
        'class' => '\Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl',
      ),
    );

    // Create a URL-based language negotiation method.
    $method_instance = new LanguageNegotiationUrl($config);

    // Create a language manager stub.
    $language_manager = $this->getMockBuilder('Drupal\language\ConfigurableLanguageManagerInterface')
      ->getMock();
    $language_manager->expects($this->any())
      ->method('getCurrentLanguage')
      ->will($this->returnValue($languages['en']));
    $language_manager->expects($this->any())
      ->method('getLanguages')
      ->will($this->returnValue($this->languages));
    $language_manager->expects($this->any())
      ->method('getLanguageTypes')
      ->will($this->returnValue(array(Language::TYPE_INTERFACE)));
    $language_manager->expects($this->any())
      ->method('getNegotiationMethods')
      ->will($this->returnValue($method_definitions));
    $language_manager->expects($this->any())
      ->method('getNegotiationMethodInstance')
      ->will($this->returnValue($method_instance));

    $method_instance->setLanguageManager($language_manager);
    $this->languageManager = $language_manager;
  }

Effectively, $method_definitions was used.

Successive commits changed that code, removing the $language_manager->expects($this->any())->method('getNegotiationMethods')->will($this->returnValue($method_definitions)); part. More exactly, it happened in commit 03fd77c842e3606da859e5bb7c04b2da0b85c720, done for #2927806: Use PHPUnit 6 for testing when PHP version >= 7.2. The committed patches contains the following lines.

diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
index 929930a521..e6215caac8 100644
--- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
+++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
@@ -76,12 +76,6 @@ protected function setUp() {
     $language_manager->expects($this->any())
       ->method('getLanguageTypes')
       ->will($this->returnValue([LanguageInterface::TYPE_INTERFACE]));
-    $language_manager->expects($this->any())
-      ->method('getNegotiationMethods')
-      ->will($this->returnValue($method_definitions));
-    $language_manager->expects($this->any())
-      ->method('getNegotiationMethodInstance')
-      ->will($this->returnValue($method_instance));

It removes the line using $method_definitions, but not the lines initializing that variable.

The lines initializing $method_definitions are therefore a left-over that should have been removed from that patch.

The patch provided here is correct.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 3156345-5.patch, failed testing. View results

apaderno’s picture

Status: Needs work » Needs review
jungle’s picture

Status: Needs review » Reviewed & tested by the community

#12 is a random failure. Setting back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Nice sleuthing @kiamlaluno - and that was removed because these methods don't exist on the language manager and PHPUnit 6 correctly reported the error.

However looking carefully at this - this means we can also remove

    // Create a URL-based language negotiation method.
    $method_instance = new LanguageNegotiationUrl($config);

and

  $method_instance->setLanguageManager($language_manager);

As these lines are doing nothing too...

jungle’s picture

Status: Needs work » Needs review
FileSize
1.21 KB
959 bytes

Thanks @alexpott for the closing look.

Addressing #15, tested the attached patch on my local, it passes. So i will cycle back and set back to RTBC once the CI run passes if no one does.

jungle’s picture

Status: Needs review » Reviewed & tested by the community

It's GREEN

alexpott’s picture

Version: 9.1.x-dev » 9.0.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 72cb9b6f06 to 9.1.x and 45f6306200 to 9.0.x and 20f191f34e to 8.9.x. Thanks!

Backported to 8.9.x to keep the tests aligned.

  • alexpott committed 72cb9b6 on 9.1.x
    Issue #3156345 by jungle, S_Bhandari, Hardik_Patel_12, kiamlaluno,...

  • alexpott committed 45f6306 on 9.0.x
    Issue #3156345 by jungle, S_Bhandari, Hardik_Patel_12, kiamlaluno,...

  • alexpott committed 20f191f on 8.9.x
    Issue #3156345 by jungle, S_Bhandari, Hardik_Patel_12, kiamlaluno,...
alexpott’s picture

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

Status: Fixed » Closed (fixed)

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