Skip to content

Conversation

mkuettel
Copy link

When i was trying to run PHPUnit tests using the database they always instantly failed as soon as a Model with relations got used, because of the automatic scanning which tries to instaniate one of my abstract classes in my project:

Error: Cannot instantiate abstract class

While there is a try-catch block surrounding the new this will not catch this error, so instead use the RelectionClass is instantiable to check whether the class can be instantiated before doing so.

When i was trying to run PHPUnit tests using the database they always
instantly failed as soon as a Model with relations got used, because
of the automatic scanning which tries to instaniate one of my abstract
classes in my project:

  Error: Cannot instantiate abstract class

While there is a try-catch block surrounding the new this will not
catch this error, so instead use the RelectionClass is instantiable to
check whether the class can be instantiated before doing so.
@mkuettel
Copy link
Author

  • Now there may be other places where this is done
  • catch(\Throwable) might also work as well
  • Reflection tends to be slow

I can adjust this PR accordingly, please let me know what you think.

Mortiz Küttel added 2 commits March 12, 2024 04:08
Now that the ModelHandler isn't that sensitive anymore and I have
a project wherein I use relations in test models within tests/_support,
and i don't know how to override this, let's just remove it by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant