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

Support PHPUnit 9 #42

Closed bobbingwide closed 3 years ago

bobbingwide commented 3 years ago

In order to be able to run unit tests with PHP 8 I need to use PHPunit 9.5.2. This requires a couple of changes to the bootstrap.php and testcase.php files used by oik routines that are tested in situ.

Problem areas

Fix that appears to work

bobbingwide commented 3 years ago

I should have closed this off but today I got the following

C:\apache\htdocs\wordpress\wp-content\plugins\oik>pu
C:\apache\htdocs\phpLibraries\phpunit\phpunit-9.5.2.phar
Searching for wp-config.php in directories leading to: C:\apache\htdocs\wordpress\wp-content\plugins\oik
Found wp-config.php in: C:\apache\htdocs\wordpress/
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.

syntax error, unexpected token "global"

There's no indication where the unexpected token has been found!

bobbingwide commented 3 years ago

With PHP 7.3 and 7.4 the error is slightly different

C:\php>php -v
PHP 7.4.0 (cli) (built: Nov 27 2019 10:14:18) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

C:\php>cd C:\apache\htdocs\wordpress\wp-content\plugins\oik
C:\apache\htdocs\wordpress\wp-content\plugins\oik>pu
C:\apache\htdocs\phpLibraries\phpunit\phpunit-9.5.2.phar
#!/usr/bin/env php
Searching for wp-config.php in directories leading to: C:\apache\htdocs\wordpress\wp-content\plugins\oik
Found wp-config.php in: C:\apache\htdocs\wordpress/
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.

syntax error, unexpected 'global' (T_GLOBAL)
bobbingwide commented 3 years ago

I downloaded PHPUnit v9.5.5 and got a slightly better message.

C:\apache\htdocs\wordpress\wp-content\plugins\oik>php C:\apache\htdocs\phpLibraries\phpunit\phpunit-9.5.5.phar
PHPUnit 9.5.5 by Sebastian Bergmann and contributors.

Error in bootstrap script: ParseError:
syntax error, unexpected token "global"

I then ran the bootstrap routine standalone.

C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch>php oik-wp.php

Parse error: syntax error, unexpected token "global" in C:\apache\htdocs\wordpress\wp-includes\query.php on line 997

This made more sense. I'd been changing adding trace records into query.php while problem solving WooCommerce reviews. I'd left an incomplete change.

C:\apache\htdocs\wordpress>git diff wp-includes\query.php
diff --git a/wp-includes/query.php b/wp-includes/query.php
index b915119c..77e4aaee 100644
--- a/wp-includes/query.php
+++ b/wp-includes/query.php
@@ -993,6 +993,7 @@ function the_post() {
  * @return bool True if comments are available, false if no more comments.
  */
 function have_comments() {
+       bw_trace2
        global $wp_query;
        return $wp_query->have_comments();
 }

Removing the incomplete bw_trace2 call resolved the issue. I'm going to close this issue now.