Automattic / wordbless

WorDBless allows you to use WordPress core functions in your PHPUnit tests without having to set up a database and the whole WordPress environment
Other
131 stars 6 forks source link

Add db_server_info method #63

Closed nateweller closed 1 year ago

nateweller commented 1 year ago

This PR adds a mock method to override $wpdb->db_server_info() in dbless-wpdb.php.

The purpose of this is to allow graceful execution of dbDelta() in WorDBless test cases.

Currently, the dbDelta function calls $wpdb->db_server_info(), which will end up calling mysql_get_server_info(), which fatals. The reasons mysql_get_server_info breaks will either be due to the fact that it was removed in PHP 7.0.0, or if you're running an earlier version of PHP, because the method expects $wpdb->dbh to not be false or null.

Would this be a useful addition? While this doesn't necessarily add support for using dbDelta in WorDBless, it does prevent it from breaking when the function is executed inside a WorDBless test case.

szepeviktor commented 1 year ago

Why not return a valid MySQL version as in db_version()?

nateweller commented 1 year ago

Why not return a valid MySQL version as in db_version()?

This seems more appropriate since WorDBless is already in the practice of mocking a specific database environment. Most of the use cases for db_server_info() is for handling special cases surrounding MariaDB, so I don't see any potential issues.

szepeviktor commented 1 year ago

Thank you.