-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
feat(database): add closable connection wrapper for PDO connection #875
base: main
Are you sure you want to change the base?
feat(database): add closable connection wrapper for PDO connection #875
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks great! Can you think of a way to test that the connection is actually closed? 🤔
#[Singleton] | ||
public function initialize(Container $container): Connection | ||
{ | ||
// Reuse same connection instance in unit tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is only meant to be used in tests, can we ensure we are actually running in tests? We can check the current environment from the Kernel I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a cary over from the PDOInitializer which had the same. But yeah, good suggestion. I will make it such that it only "caches" when in testing. This is more of a test speed+memory improvement than anything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented the check.
It depends on your meaning of "test".. I can Add a test for the close functionality: yes. It will just check if the PDO connection has been set to null. I cannot test if the PDO driver really closes the connection, PDO doesn't expose anything for this. Do you want me to add a unit test for the connect + close functionality? |
I think what would be ideal is that the Then, we can write a test that first ensure the connection works by issuing a query, then closing the connection, and finally expecting the exception when issuing another query |
Implemented the exception and the test using sqllite. |
What
Closes #872
Why
task
component #857 it is sometimes needed to manually close the PDO connection. With this PR you can manually close (and re-connect) the PDO connection.