You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✏️ Describe the bug
I encountered a rare edge case, which took me quite some time to debug, so I thought it might be useful for every one.
If you need to do any kind of operation in the class's constructor, and something throws ArgumentCountError exception, the package will show the exception message that does not point to the real problem.
↪️ To Reproduce
it('bug-test', function () {
classExampleTestDataextendsData
{
publicfunction__construct(
publicint$id,
publicstring$name,
) {
// Method that throws the `ArgumentCountError` exceptionarray_key_exists('test');
}
}
$test = ExampleTestData::from(['id' => 1, 'name' => 'test']);
});
✅ Expected behavior
So the error message was something like: Could not create ExampleTestData: the constructor requires 2 parameters, 2 given. Parameters given: id, name. Parameters missing: .
If you guys are interested, I could try to submit a PR to fix it?
I made it to work with the changes to DataFromArrayResolver. Instead of checking for ArgumentCountError exception, I added a method to check if all the parameters are supplied. That way, If an ArgumentCountError is thrown it would point to the direct issue.
✏️ Describe the bug
I encountered a rare edge case, which took me quite some time to debug, so I thought it might be useful for every one.
If you need to do any kind of operation in the class's constructor, and something throws
ArgumentCountError
exception, the package will show the exception message that does not point to the real problem.↪️ To Reproduce
✅ Expected behavior
So the error message was something like:
Could not create ExampleTestData: the constructor requires 2 parameters, 2 given. Parameters given: id, name. Parameters missing: .
If you guys are interested, I could try to submit a PR to fix it?
I made it to work with the changes to
DataFromArrayResolver
. Instead of checking forArgumentCountError
exception, I added a method to check if all the parameters are supplied. That way, If anArgumentCountError
is thrown it would point to the direct issue.CannotCreateData::constructorMissingParameters()
would have to be updated as well as there would be no$previous
Throwable.🖥️ Versions
Laravel: 11.27.2
Laravel Data: 4.10.1
PHP: 8.3.3
The text was updated successfully, but these errors were encountered: