emeraldjava
emeraldjava

Reputation: 11202

WP_UnitTestCase - how to configure the include_path correctly with phpunit PHAR

I'm trying to write a php unit test for my wordpress plugin and have been following the writing-wordpress-plugin-unit-tests tutorial. I've cloned the 'core.trac.wordpress.org/browser/tests/trunk/includes' locally

I have installed phpunit via the PHAR mechanism as described here : https://phpunit.de/manual/current/en/installation.html#installation.requirements. I also have a composer.json configuration

[14:11:04@~]$ phpunit --version
PHPUnit 4.7.3 by Sebastian Bergmann and contributors.

In my /etc/php.ini file i have

include_path="."

When i run my phpunit i get this error

[14:18:07@bhaawp]$ phpunit 
PHP Fatal error:  require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.') in /Users/pauloconnell/projects/bhaawp/wp-phpunit/bootstrap.php on line 7

The bootstrap.php file has this include

<?php
/**
 * Installs WordPress for running the tests and loads WordPress and the test libraries
 */
require_once 'PHPUnit/Autoload.php';

I think i need to add the phpunit folder to the path, but am having a mental block as to where this should be set to?

Upvotes: 1

Views: 999

Answers (2)

J.D.
J.D.

Reputation: 1843

You need to clone https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/ instead. The one you are cloning is old and is no longer updated.

You will see that that line is no longer there in the new bootstrap.php.

Upvotes: 1

Sebastian Bergmann
Sebastian Bergmann

Reputation: 8326

PHPUnit does not have a file named PHPUnit/Autoload.php (anymore).

If Wordpress' test suite and / or best practices for testing Wordpress plugins mention / use that file then this would be an indication for Wordpress relying on an outdated version of PHPUnit.

Upvotes: 2

Related Questions