• Resolved termel

    (@munger41)


    Hi,

    I am new to wp-cli and phpunit and following the tutorial in order to create first php tests for my plugin on a Ubuntu box : https://make.www.ads-software.com/cli/handbook/plugin-unit-tests/

    I made the whole tutorial but when luanching the command phpunit i get the following errors:

    root@maxiserver:/var/www/mysite.com/wp-content/plugins/my-plugin# phpunit
    Installing...
    Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
    PHP Warning:  require(/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin/.php): failed to open stream: No such file or directory in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26
    
    Warning: require(/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin/.php): failed to open stream: No such file or directory in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26
    PHP Fatal error:  require(): Failed opening required '/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin/.php' (include_path='.:/usr/share/php') in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26
    
    Fatal error: require(): Failed opening required '/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin/.php' (include_path='.:/usr/share/php') in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26

    And yes the bootstrap.php file contains a strange function :

    function _manually_load_plugin() {
            require dirname( dirname( __FILE__ ) ) . '/my-plugin/.php';
    } 

    Did the scaffold command worked properly ?

    wp scaffold plugin-tests my-plugin

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter termel

    (@munger41)

    Ok, i had to rerun wp scaffold plugin-tests my-plugin command from the root of my wordpress folder (it’s not told in the official link).
    But the problem stays the same unless the php file path is now correct:

    root@maxiserver:/var/www/mysite.com/wp-content/plugins/my-plugin# phpunit
    Installing...
    Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
    PHP Warning:  require(/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin.php): failed to open stream: No such file or directory in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26
    
    Warning: require(/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin.php): failed to open stream: No such file or directory in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26
    PHP Fatal error:  require(): Failed opening required '/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin.php' (include_path='.:/usr/share/php') in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26
    
    Fatal error: require(): Failed opening required '/var/www/mysite.com/wp-content/plugins/my-plugin/my-plugin.php' (include_path='.:/usr/share/php') in /var/www/mysite.com/wp-content/plugins/my-plugin/tests/bootstrap.php on line 26

    Any idea ?

    Thread Starter termel

    (@munger41)

    Ok, the problem was that the main plugin file was different from the plugin directory.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cannot unit test with phpunit’ is closed to new replies.