phpstan-drupal icon indicating copy to clipboard operation
phpstan-drupal copied to clipboard

False positives on AddressDefaultWidgetTest::assertOptionSelected

Open mglaman opened this issue 3 years ago • 0 comments

  /**
   * Asserts that a select field has a selected option.
   *
   * @param string $id
   *   ID of select field to assert.
   * @param string $option
   *   Option to assert.
   * @param string $message
   *   (optional) A message to display with the assertion. Do not translate
   *   messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
   *   variables in the message text, not t(). If left blank, a default message
   *   will be displayed.
   */
  protected function assertOptionSelected($id, $option, $message = '') {
    $elements = $this->xpath('//select[@name=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
    foreach ($elements as $element) {
      $this->assertNotEmpty($element->isSelected(), $message ? $message : new FormattableMarkup('Option @option for field @id is selected.', ['@option' => $option, '@id' => $id]));
    }
  }

PHPStan is saying this is a deprecated method, when it's not.

Call to deprecated method assertOptionSelected() of class [Drupal\Tests\address\FunctionalJavascript\AddressDefaultWidgetTest](https://api.drupal.org/api/drupal/core!tests!Drupal!Tests!address!FunctionalJavascript!AddressDefaultWidgetTest.php/class/AddressDefaultWidgetTest/9.4.0-beta1.x). Deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute yourself.

mglaman avatar Jun 06 '22 21:06 mglaman