amphp / mysql

An async MySQL client for PHP, optimizing database interactions with efficient non-blocking capabilities. Perfect for responsive, high-performance applications.
Other
359 stars 63 forks source link

Test DB environment setup #15

Closed sagara- closed 6 years ago

sagara- commented 9 years ago

I've written a script to recreate the test database, rather than storing the binary database files themselves in source control. Different versions of MySQL could possibly require running mysql_upgrade to update certain system tables, and the direct binary files don't work using MariaDB.

The new script is stored in test/bin/create-test-db, and can be configured via testdb_config.php to use different MySQL installations by setting a different prefix. This script runs mysql_install_db, then creates the connectiontest database as required by the test code.

I've switched to database name to be 'connectiontest' rather than 'ConnectionTest', as all the test code refers to it via that name. MySQL database names should be viewed as case-sensitive, since they correspond to filesystem names (see https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html).

I removed the trailing ' from the mysqld startup check code, so that it can match versions such as '10.0.18-MariaDB'.

For convinence, I've also added two new scripts to composer.json: test (which runs phpunit) and test-env-setup (which runs create-test-db).

Other minor tweaks involved setting an explicit bind-address in the conf, as the error resulting from not being able to bind an ipv6 address on certain systems would cause the test mysqld startup code to assume mysqld failed, and setting the socket to a temporary directory. The original setting wouldn't work correctly unless you ran mysql within the mysql_db directory.

I haven't had the chance to test the code on an actual MySQL implemention, but all commands are used as documented on the MySQL website so there should hopefully be no issues with doing so.

kelunik commented 6 years ago

@bwoebi Could you please close or merge this PR? Thanks.

trowski commented 6 years ago

It at least portions of this idea were implemented some time ago in b44fe53560c5f07080848a4055d57c3c8fd3ae6e.

@sagara- I'm unsure why this PR was not used. This library has been significantly refactored in the last few months. If there are improvements that could still be made, please submit another PR.

EDIT: Forgot to mention I did cherry-pick on commit and manually merge it via 84a428ccd46221b764abe761ed5ffe4ea1097810.