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.
if (!isset($context['target_instance'])) {
throw new LogicException('$context[\'target_instance\'] must be set to denormalize with the FieldItemNormalizer');
}
if ($context['target_instance']->getParent() == NULL) {
throw new LogicException('The field item passed in via $context[\'target_instance\'] must have a parent set.');
}
Is incorrect LogicException
should be \LogicException
Comment | File | Size | Author |
---|---|---|---|
#17 | 2225333-fielditemnormalizer-logicexception-17-tests-only.patch | 4.66 KB | Boobaa |
#17 | 2225333-fielditemnormalizer-logicexception-17-tests-and-fix.patch | 7.49 KB | Boobaa |
Comments
Comment #1
jessebeach CreditAttribution: jessebeach commentedWe need to do two things for this issue.
One is super simple: Roll a patch changing
LogicException
to\LogicException
-- not the preceding slash.Two is a little more tricky. We need to create a test that will trigger the two exceptions noted in the issue summary. These two exceptions are currently untested.
Comment #2
BoobaaAttached is a patch with tests only and another patch with tests and fix.
Comment #4
dawehnerNote: There is a logicexception as part of the serializer namespace, see Symfony\Component\Serializer\Exception\LogicException. The original code intended to use that, as it was probably copied from another place. On top of that I really wonder why we don't use an InvalidArgumentException given that seems to have a better semantic
These bits probably have to be adapted based on the previous point.
Comment #5
BoobaaFirstly, @alexpott asked at #drupaldevdays to convert this mocking mess to proper getMock() stuff, so I implemented that one instead.
Secondly, I have changed from LogicException to InvalidArgumentException as @dawehner asked.
Attached is a patch with tests only and another patch with tests and the fix.
Comment #7
BoobaaThe bot threw this issue back to NW because of the patch which contains only the tests, so it must have failed. The other patch contains tests AND the fix and passed, so setting the issue to NR, as @ianthomas_uk suggested on IRC.
Comment #8
jessebeach CreditAttribution: jessebeach commentedRead through the code; it looks succinct and well written. The fix changes the incorrect
LogicException
to an\InvalidArgumentException
.Comment #9
alexpottNo need for this - can use the phpunit annotation
@expectedException
and this should be two tests or use a data providerNo new line at end of file
Plus lets fix and test
Drupal\hal\Normalizer\FieldNormalizer
too as this has the same bug.Comment #10
BoobaaHere we go. Changes:
@expectedException
.Drupal\hal\Normalizer\FieldNormalizer
too.Comment #11
dawehnerDo we also want to unit test the other class?
You could also use Symfony\Component\Serializer\Exception\InvalidArgumentException.
Comment #14
Boobaa10: 2225333-fielditemnormalizer-logicexception-10-tests-and-fix.patch queued for re-testing.
Comment #16
Boobaa10: 2225333-fielditemnormalizer-logicexception-10-tests-and-fix.patch queued for re-testing.
Comment #17
BoobaaRerolled the pair of patches as @dawehner asked at #drupaldevdays: testing
FieldItemNormalizer::denormalize()
andFieldNormalizer::denormalize()
in two different classes, but they have a common abstract ancestor as the dataProvider for the two is the same.Additionally, changed from
\InvalidArgumentException
to\Symfony\Component\Serializer\Exception\InvalidArgumentException
which is eventually the same at code level, but makes more sense semantically.Comment #18
dawehnerAwesome!
Comment #20
jessebeach CreditAttribution: jessebeach commentedThe "fail" patch failed in #17. The green patch passed.
Comment #21
dawehnerAwesome!
Comment #22
alexpottNice test!
Committed 5a0edc3 and pushed to 8.x. Thanks!