- Issue created by @mondrake
- Issue was unassigned.
- Status changed to Needs review
over 1 year ago 4:48pm 23 June 2023 - last update
over 1 year ago 29,487 pass, 21 fail - 🇮🇹Italy mondrake 🇮🇹
In general, Prophecy does not allow mocking magic methods.
PHPUnit mocks would, but in this case it seemed to me that
+++ b/core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php @@ -69,241 +74,130 @@ public function testValidate($items, $expected_violation, $name = FALSE) { - $items->expects($this->any()) - ->method('getValue') - ->willReturn('changed-value'); - $items->expects($this->once()) - ->method('__get') - ->with('value') - ->willReturn('changed-value');
->getValue()
and->value
are totally overlapping.So here I removed the expectation to access
->value
via__get
, leaving only the one for->getValue()
.But, this has an impact on runtime code that needs to be assessed:
+++ b/core/modules/user/src/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidator.php @@ -83,7 +83,7 @@ public function validate($items, Constraint $constraint) { // Special case for the password, it being empty means that the existing // password should not be changed, ignore empty password fields. - $value = $items->value; + $value = $items->getValue(); if ($field->getName() != 'pass' || !empty($value)) { // Compare the values of the field this is being validated on. $changed = $items->getValue() != $account_unchanged->get($field->getName())->getValue();
The last submitted patch, 2: 3369099-2.patch, failed testing. View results →
- Status changed to Needs work
8 months ago 9:58am 18 April 2024 - Status changed to Needs review
8 months ago 9:23pm 23 April 2024 - 🇬🇧United Kingdom longwave UK
Couldn't see any easy way of doing this one as the mocks are all so complex, so converted the data provider into the test method itself. Thought about splitting it up into 11 separate test methods, but doesn't seem worth the effort.
- Merge request !7680Remove data provider in ProtectedUserFieldConstraintValidatorTest. → (Open) created by longwave
- Status changed to RTBC
8 months ago 3:07pm 24 April 2024 - 🇮🇹Italy mondrake 🇮🇹
Looks good.
Nit - I think it would be more readable if instead of
protected function validate($items, string $name = NULL): void
it were
protected function assertValidation($items, string $constraintMessageOnValidationFailure = NULL): void
But it's just me having had the difficulty to understand what was going on.
- Status changed to Fixed
8 months ago 6:04pm 24 April 2024 - 🇬🇧United Kingdom catch
Looks good. Took me a minute to realise we're just doing away with a test provider here, good idea.
Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!
Automatically closed - issue fixed for 2 weeks with no activity.