de-loke
de-loke

Reputation: 61

phpunit for wordpress in docker (inherit from final class)

I am writing a wordpressplugin and want to create a phpunit testenvironment for it. For that I've created a docker container using a php:7.2-apache base container and installed phpunit on it via phar archive on the image. After that I have set some environment variables and used the following bashscript, which is similear to the one created by "wp scaffold plugin-tests", as entrypoint.

# INSTALL WP-CORE
wp core download --path="${WPPATH}" --allow-root
waitforit -t 60 database:3306 -- wp config create --dbuser="${WPDBUSER}" --dbpass="${WPDBPASS}" --dbname="${WPDBNAME}" --dbhost="${WPDBHOST}" --path="${WPPATH}" --allow-root

wp db create --path="${WPPATH}" --allow-root
wp core install --url="${WPURL}" --title="SpitzeDev" --admin_user="${ADMINUSER}" --admin_password="${ADMINPASS}" --admin_email="${ADMINMAIL}" --path="${WPPATH}" --allow-root
chown www-data:www-data "/var/www/html" -R

# Install WP-Testsuite for PHPUnit
if [ ! -d $WP_TESTS_DIR ]; then
    mkdir -p $WP_TESTS_DIR
    svn co --quiet https://develop.svn.wordpress.org/tags/$(wp core version --allow-root --path=${WPPATH})/tests/phpunit/includes/ $WP_TESTS_DIR/includes
    svn co --quiet https://develop.svn.wordpress.org/tags/$(wp core version --allow-root --path=${WPPATH})/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

# Configure WP-Testuite for PHPUnit
if [ ! -f wp-tests-config.php ]; then
    download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
    # remove all forward slashes in the end
    WP_CORE_DIR=$(echo ${WPPATH} | sed "s:/\+$::")
    sed -i "s:dirname( __FILE__ ) . '/src/':'${WP_CORE_DIR}/':" "$WP_TESTS_DIR"/wp-tests-config.php
    sed -i "s/youremptytestdbnamehere/$WPDBNAME/" "$WP_TESTS_DIR"/wp-tests-config.php
    sed -i "s/yourusernamehere/$WPDBUSER/" "$WP_TESTS_DIR"/wp-tests-config.php
    sed -i "s/yourpasswordhere/$WPDBPASS/" "$WP_TESTS_DIR"/wp-tests-config.php
    sed -i "s|localhost|${WPDBHOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi
phpunit

The script works fine until phpunit is called. But then the follwing exception is thrown:

"Fatal error: Class PHPUnit_Util_Test may not inherit from final class (PHPUnit\Util\Test) in /tmp/wordpress-tests-lib/includes/phpunit6-compat.php on line 18"

I don't really understand how this error could occure. If I use this the phpunit tests of my plugin the error is not thrown. If use these Tests on my local maschine they work just fine.

Upvotes: 3

Views: 1007

Answers (1)

piersb
piersb

Reputation: 598

I had this problem when trying to test using the wordpress core test framework with phpunit 7.0.3 and PHP 7.1.6

Solved by switching to phpunit 6.1.0 and PHP 7.0.20.

Upvotes: 5

Related Questions