Problem/Motivation
DateTimePlus doesn't initialize DateTimePlus::errors properly, and doesn't handle the errors from date_parse properly.
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Instructions | Done | |
| Add automated tests | Instructions | Done | |
| Update the patch to incorporate feedback from reviews (include an interdiff) | Instructions | Done | |
| Manually test the patch | Novice | Instructions | Done |
| Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions | Done |
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | interdiff-19-23.txt | 1.1 KB | mpdonadio |
| #23 | 2858295-23.patch | 4.08 KB | mpdonadio |
| #19 | 2858295-19.patch | 4.14 KB | mpdonadio |
Comments
Comment #2
mpdonadioComment #3
mpdonadioThis is the problem and the basic fix. Per http://php.net/manual/en/function.date-parse.php, $test['errors'] is an array, so we need to merge them in with anything else that may have been set during preparation. HEAD just pushes the errors array onto the errors, resulting in a multidimensional array.
+= is probably wrong here, and above. We need to ignore the keys and just tack on the values to the array. Need to be fixed.
This patch is going to come up green. The first point (1) fixed above should have triggered a notice w/o the patch, which would cause a test fail in HEAD; nothing in this patch will change that. I suspect we are only testing invalid input with the static factory methods, so this part of the constructor logic isn't being exercised properly with bad values in DateTimePlusTest. Hence the Needs Tests tag and setting this back to Needs Work.
(edited to actually make sense...)
Comment #4
goz commentedWe should not just use array_values() here.
+=merge arrays depending of keys. In case$errors = ['error 1', 'error 2'];and$errors['errors'] = ['error 2', 'error 3'];,$this->errors += array_values($errors['errors']);will still result to['error 1', 'error 2']Should use something like.
Tests should reproduce this case (+ 1 patch with only test which should fail)
Comment #5
goz commentedComment #6
goz commentedComment #7
goz commentedComment #8
mpdonadioStill need to double check this fixes the problem I found in #2824717: Add a format constraint to DateTimeItem to provide REST error message, but here is the more better error merging with test coverage, which shows the problem.
Edit: Yes, this fixes the other issue. This is ready for review.
Comment #10
wim leersThis is the bugfix. Makes sense.
Nit:
string[]Comment #11
goz commentedLooks good. Nice catch, thanks mpdonadio
Comment #12
goz commentedMiss to check one step in summary
Comment #13
alexpottWhy are we not just asserting what
$date->getErrors()returns? This seems a bit fragile.Also the return of
$date->getErrors()for['YYYY-MM-DD']is:The array indexing looks weird.
Comment #14
wim leersComment #15
mpdonadioShould address #13.
Comment #16
mpdonadioPicking my own nits to make this consistent, and fix a phpcs warning on a changed hunk.
Comment #18
wim leersThanks!
Nit: s/errors messages/error messages/
Nit: this comment seems pointless.
This comment seems wrong.
Comment #19
mpdonadioI think that test method reads fine w/o the comments; the class methods have decent names on them so it is pretty apparent what is being tested now.
Comment #21
wim leersExactly :)
Back to RTBC!
Comment #22
alexpottThis looks weird. Why do we need to
array_merge()after$this->errors = [];?Can't we just do
$this->errors = $test['errors'];?Comment #23
mpdonadio#22 is addressed. Also can remove another array_values() b/c array_merge() rekeys numeric indexes.
Double checked this against #2824717: Add a format constraint to DateTimeItem to provide REST error message and it will unblock it.
Comment #24
chiranjeeb2410 commented@mpdonadio,
Changes look good and patch applies cleanly. Changing to RTBC.
Comment #25
alexpottCommitted ade0589 and pushed to 8.4.x. Thanks!
I'm pretty certain we should put this in 8.3.x - as we're in RC going to get a +1 from another committer before cherry-picking.
Comment #27
catch+1 on cherry-picking back to 8.3.x.
Comment #29
alexpottCommitted 52e84ae and pushed to 8.3.x. Thanks!