Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The documentation for \Drupal\user\UserInterface::setExistingPassword states that the $this
is the return value:
/**
* Sets the existing plain text password.
*
* Required for validation when changing the password, name or email fields.
*
* @param string $password
* The existing plain text password of the user.
*
* @return $this
*/
public function setExistingPassword($password);
However, \Drupal\user\Entity\User::setExistingPassword does not return a value:
/**
* {@inheritdoc}
*/
public function setExistingPassword($password) {
$this->get('pass')->existing = $password;
}
I'll add a patch to the comments.
Comment | File | Size | Author |
---|---|---|---|
#14 | interdiff_9-14.txt | 1.33 KB | johnwebdev |
#14 | 3137119-14.patch | 1.16 KB | johnwebdev |
#9 | interdiff_6-9.txt | 897 bytes | munish.kumar |
#9 | 3137119-9.patch | 1.32 KB | munish.kumar |
#6 | interdiff_2-6.txt | 848 bytes | munish.kumar |
Comments
Comment #2
Jaypan CreditAttribution: Jaypan commentedComment #3
jungleThanks, @Jaypan! The fix is straight. No need to add a test, no CS violation.
Comment #4
init90Added relevant issue.
Comment #5
xjmThis is an interesting case for BC. Technically, returning something different is a BC break. However, since it only ever returned NULL before, there's no reason a caller would do anything with the return value. So, I think this is OK.
However, we should add a unit test for this. Thanks!
Comment #6
munish.kumar CreditAttribution: munish.kumar as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedHi @xjm,
I have updated the patch with the test cases, Please review the patch.
Comment #7
Jaypan CreditAttribution: Jaypan commentedI don't believe that test matches the issue. The test should be confirming that $user->setExistingPassword() returns a Drupal\user\Entity\User object.
Comment #8
munish.kumar CreditAttribution: munish.kumar as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedHi @jaypan,
Thanks for your valuable feedback. I have made changes in the test cases as mentioned in #7. Please review.
Comment #9
munish.kumar CreditAttribution: munish.kumar as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedPlease ignore the previous patch, Please review the latest one in which #7 is addressed.
Comment #10
Jaypan CreditAttribution: Jaypan commentedLooks good to me.
Comment #11
jungleBTW, would be better to alter an existed test to demonstrate the usage of chaining with
setExistingPassword()
, however, no such alterable test found.Prefer one-line
$this->assertInstanceOf(User::class, $user->setExistingPassword('existing_pass'));
but it really does not matter.The test added in #9 is good and enough. So RTBC +1.
Comment #12
johnwebdev CreditAttribution: johnwebdev commentedComment #13
catchThis could be done in a new kernel test - doing it in a new method on a functional test means we have to do a full install of Drupal.
Comment #14
johnwebdev CreditAttribution: johnwebdev commentedMoved the test to UserEntityTest instead. Removed the ::save() call because it's not needed, also renamed the test case to be more descriptive of what we're actually testing.
Comment #19
smustgrave CreditAttribution: smustgrave at Mobomo commentedLooks good to me.
Comment #20
alexpottCommitted and pushed 51e7a08352 to 10.1.x and 0763535604 to 10.0.x and 6764848b9a to 9.5.x. Thanks!
Committed 844acce and pushed to 9.4.x. Thanks!
Comment #24
mondrakeThis broke PHPStan testing on 10+, please revert
Comment #28
xjmReverted from 9.5.x, 10.0.x, and 10.1.x.
I think the 9.5.x patch was fine, but the D10 patches need to do something with the phpstan baseline or something. https://www.drupal.org/pift-ci-job/2422757
Comment #33
mondrakeThis is the error on D10+ branches:
That means that the pattern indicated, that can be found in phpstan-baseline.json in the core directory for the 10+ branches, should be removed from that file since the error is not occurring anymore.
Comment #34
mondrake@alexpott fixed this.