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.
Problem/Motivation
The the static factory methods, when there is a problem parsing input and creating an object, the method throws a generic \Exception. This is too generic, and doesn't allow calling code to distinguish between problems.
Proposed resolution
Use \InvalidArgumentException and \UnexpectedValueException as appropriate.
Remaining tasks
User interface changes
API changes
Different exceptions.
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#9 | interdiff-02-09.txt | 5.58 KB | mpdonadio |
#9 | 2830079-09.patch | 8.72 KB | mpdonadio |
#2 | 2830079-02.patch | 4.46 KB | mpdonadio |
Comments
Comment #2
mpdonadioThis is going to fail. Run locally to see what is going on
../vendor/bin/phpunit --debug --verbose tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
Comment #7
jhedstromWhat's left to be done to fix the failure?
Comment #8
mpdonadioThe problem is that the invalid date "23 abc 2012" is failing against the format "d M Y" instead of the sanity check to make sure. This means InvalidArgumentException gets thrown instead of UnexpectedValueException. Fixing this would mean adjusting the test, which I am always hesitant to do. I guess adjusting the provider to provide the exception class would be OK? Will post that later.
Comment #9
mpdonadioOK, this should pass. Will write up a draft CR later.
Comment #10
jhedstromGiven the nature of this issue, that seems completely reasonable to me.
This is good to see too, given the goals of #2822837: Replace @expectedException @expectedExceptionMessage with $this->setExpectedException.
Once the CR is in place, I think this is good to go.
Comment #11
mpdonadioOk, draft CR is ready for review.
Comment #12
jhedstromI reviewed (and added some minor formatting changes to) the CR, and that looks good too.
Comment #13
alexpottCommitted 45d2568 and pushed to 8.3.x. Thanks!