Commit 19ee0de2 authored by catch's avatar catch
Browse files

Issue #3319683 by alexpott, mallezie, mondrake: Fix PHPStan errors from...

Issue #3319683 by alexpott, mallezie, mondrake: Fix PHPStan errors from UserCreationTrait and AssertMailTrait
parent 806be299
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -82,13 +82,8 @@ protected function assertMail($name, $value = '', $message = '', $group = 'Email
   *   messages: use \Drupal\Component\Render\FormattableMarkup to embed
   *   variables in the message text, not t(). If left blank, a default message
   *   will be displayed.
   * @param string $group
   *   (optional) The group this message is in, which is displayed in a column
   *   in test output. Use 'Debug' to indicate this is debugging output. Do not
   *   translate this string. Defaults to 'Other'; most tests do not override
   *   this default.
   */
  protected function assertMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
  protected function assertMailString($field_name, $string, $email_depth, $message = '') {
    $mails = $this->getMails();
    $string_found = FALSE;
    // Cast MarkupInterface objects to string.
@@ -107,7 +102,7 @@ protected function assertMailString($field_name, $string, $email_depth, $message
    if (!$message) {
      $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $string]);
    }
    $this->assertTrue($string_found, $message, $group);
    $this->assertTrue($string_found, $message);
  }

  /**
@@ -122,20 +117,15 @@ protected function assertMailString($field_name, $string, $email_depth, $message
   *   messages: use \Drupal\Component\Render\FormattableMarkup to embed
   *   variables in the message text, not t(). If left blank, a default message
   *   will be displayed.
   * @param string $group
   *   (optional) The group this message is in, which is displayed in a column
   *   in test output. Use 'Debug' to indicate this is debugging output. Do not
   *   translate this string. Defaults to 'Other'; most tests do not override
   *   this default.
   */
  protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
  protected function assertMailPattern($field_name, $regex, $message = '') {
    $mails = $this->getMails();
    $mail = end($mails);
    $regex_found = preg_match("/$regex/", $mail[$field_name]);
    if (!$message) {
      $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $regex]);
    }
    $this->assertTrue((bool) $regex_found, $message, $group);
    $this->assertTrue((bool) $regex_found, $message);
  }

}
+3 −3
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ protected function createUser(array $permissions = [], $name = NULL, $admin = FA
    $account->save();

    $valid_user = $account->id() !== NULL;
    $this->assertTrue($valid_user, new FormattableMarkup('User created with name %name and pass %pass', ['%name' => $edit['name'], '%pass' => $edit['pass']]), 'User login');
    $this->assertTrue($valid_user, new FormattableMarkup('User created with name %name and pass %pass', ['%name' => $edit['name'], '%pass' => $edit['pass']]));
    if (!$valid_user) {
      return FALSE;
    }
@@ -272,7 +272,7 @@ protected function createRole(array $permissions, $rid = NULL, $name = NULL, $we
    }
    $result = $role->save();

    $this->assertSame(SAVED_NEW, $result, new FormattableMarkup('Created role ID @rid with name @name.', ['@name' => var_export($role->label(), TRUE), '@rid' => var_export($role->id(), TRUE)]), 'Role');
    $this->assertSame(SAVED_NEW, $result, new FormattableMarkup('Created role ID @rid with name @name.', ['@name' => var_export($role->label(), TRUE), '@rid' => var_export($role->id(), TRUE)]));

    if ($result === SAVED_NEW) {
      // Grant the specified permissions to the role, if any.
@@ -303,7 +303,7 @@ protected function checkPermissions(array $permissions) {
    $valid = TRUE;
    foreach ($permissions as $permission) {
      if (!in_array($permission, $available)) {
        $this->fail(new FormattableMarkup('Invalid permission %permission.', ['%permission' => $permission]), 'Role');
        $this->fail(new FormattableMarkup('Invalid permission %permission.', ['%permission' => $permission]));
        $valid = FALSE;
      }
    }
+69 −1259

File changed.

Preview size limit exceeded, changes collapsed.