Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model handler: only try to instantiate what is instantiable #49

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

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.

None yet

1 participant