user_expire_set_expiration executing a merge query incorrectly

Created on 4 December 2024, 18 days ago

Problem/Motivation

While running PHPUnit tests on the 2.x version of user_expire module I saw an error.

Drupal\Tests\user_expire\Functional\UserExpireTest::testUserExpire
AssertionError: assert(is_string($field))

/builds/issue/user_expire-3491734/web/core/lib/Drupal/Core/Database/Query/Merge.php:330
/builds/issue/user_expire-3491734/user_expire.module:215
/builds/issue/user_expire-3491734/tests/src/Functional/UserExpireTest.php:41

Upon further investigation I saw that on line 215 of user_expire.module there is an incorrect use of database()->merge()->key()

As of https://www.drupal.org/node/2205327 β†’ key should only contain 1 key in this form

 \Drupal::database()->merge('user_expire')
      ->key('uid' => $account->id())
      ->fields([
        'uid' => $account->id(),
        'expiration' => $expiration,
      ])
      ->execute();

Instead it looks like this (Note the array within the key field)

    \Drupal::database()->merge('user_expire')
      ->key(['uid' => $account->id()])
      ->fields([
        'uid' => $account->id(),
        'expiration' => $expiration,
      ])
      ->execute();

https://git.drupalcode.org/project/user_expire/-/blob/2.x/user_expire.mo...

Steps to reproduce

Run phpunit tests for user_expire module.

Proposed resolution

Update the function's syntax so that it actually works.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024