bobbingwide / oik-batch

Batch interface to WordPress
https://www.oik-plugins.com/oik-plugins/oik-batch
GNU General Public License v2.0
0 stars 0 forks source link

Add logic to check compatibility of wordpress-develop-tests with WordPress #17

Closed bobbingwide closed 6 years ago

bobbingwide commented 7 years ago

When I first started running my in situ PHPUnit tests under WordPress 4.7 I was still using the wordpress-develop-tests plugin built against WordPress 4.6, and oik-batch v0.8.7.

It proved to be incompatible - see the table below. Explanation: In order to test the changes to WordPress core, the PHP Unit testing code needed to reflect the changes.

Solution: Update the wordpress-develop-tests to v4.7 AND update oik-batch ( v0.9.0 ). v0.9.0 of oik-batch contains its own version of WP_UnitTestCase and a different version of functions.php. The alternative versions are loaded by oik-batch's tests\bootstrap.php file.

See #16 and https://github.com/bobbingwide/wordpress-develop-tests/issues/2

The table below summarises what happens with different levels of WordPress, wordpress-develop-tests and oik-batch.

WordPress version wordpress-develop-tests version oik-batch Result
4.6.x v4.6 v0.8.7 OK - this works
4.6.x v4.6 v0.9.0 Error: __clone method called on non-object
4.6.x v4.7 v0.8.7 Fatal error: Cannot redeclare wp_clear_auth_cookie
4.6.x v4.7 v0.9.0 Error: __clone method called on non-object
4.7 v4.6 v0.8.7 Undefined index: merged_filters
4.7 v4.6 v0.9.0 OK - this works
4.7 v4.7 v0.8.7 Fatal error: Cannot redeclare wp_clear_auth_cookie()
4.7 v4.7 v0.9.0 OK - this works

As you can see, the changes make in v0.9.0 makes it incompatible with PHP Unit testing using WordPress 4.6.

Proposed solution

oik-batch's bootstrap code should detect the versions in use and either report it nicely or, if possible, deal with it.

Current workaround

Using the table below, checkout the Git repositories to the appropriate levels before running the tests.

bobbingwide commented 7 years ago

An additional problem arose with tables that had been created with a storage engine that's not capable of supporting transactions. i.e.. MyISAM tables. Even though the PHPUnit tests are constructed to disable auto commit and ROLLBACK changes at the end of the transaction, MyISAM tables will reflect all the changes that had been made.

Proposed solution

Detect MyISAM tables in the database and not run the tests if any are present. Optionally offer to convert the tables to InnoDB.

See stack overflow for explanations and conversion routines. E.g.

http://stackoverflow.com/questions/20148/myisam-versus-innodb

bobbingwide commented 7 years ago

Both WordPress and wordpress-develop-tests have now been updated to v4.8. The test that has been implemented supports WordPress being at a higher level than the wordpress-develop-tests.

bobbingwide commented 6 years ago

The covert_engine method() in oik-innodb.php was never completed. When I ran it for real, against qw/oikcom) I found that the routine needed updating.

Running ALTER TABLE 'oikplug_wp993.wp_commentmeta' engine='InnoDB' produced a WordPress database error [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use.

Rather than using $query = $wpdb->prepare( "ALTER TABLE %s engine=%s", DB_NAME . "." . $result->table_name, $to_engine ); we'll just use $query = sprintf( "ALTER TABLE %s engine=%s", $result->table_name, $to_engine );