chriszarate / docker-compose-wordpress

An example Docker Compose setup for WordPress plugin or theme development.
162 stars 54 forks source link

Failed opening required '/tmp/wordpress-tests-lib/includes/functions.php' #2

Closed MikeiLL closed 7 years ago

MikeiLL commented 7 years ago

Hello again, dear Chris.

Fatal error: require_once(): Failed opening required '/tmp/wordpress-tests-lib/includes/functions.php' (include_path='.:/usr/local/lib/php') in /var/www/html/wp-content/plugins/mz-mindbody-api/tests/bootstrap.php on line 14

I think /tmp is empty.

Working with this tree:

├── README.md
├── bin
│   └── install-wp-tests.sh
├── docker-compose.yml
├── inc
│   ├── stuff.php
├── languages
├── lib
│   ├── stuff.php
├── my-great-plugin.php
├── package.json
├── phpcs.ruleset.xml
├── phpunit.xml.dist
├── tests
│   ├── bootstrap.php
│   └── test-sample.php

After cycling docker-compose up and down and back up, with .env:

DOCKER_DEV_DOMAIN=great.dev
DOCKER_LOCAL_IP=108.205.63.107
PHPUNIT_TEST_DIR=my-great-plugin

Seems:

docker-compose exec wordpress ls /tmp
sess_000bd338f45070de2efeb6b050b75be6  
sess_5b2da936132835ee0c05214a2fb05b62

No wordpress-tests-lib

Hmmm.

PHPUNIT_TEST_DIR: "/var/www/html/wp-content/plugins/my-great-plugin"
      VIRTUAL_HOST: "${DOCKER_DEV_DOMAIN}"
      WORDPRESS_ACTIVATE_PLUGINS: "my-great-plugin" # dot dot dot
    volumes:
      - ".:/var/www/html/wp-content/plugins/my-great-plugin"

Tried with your scaffold and running docker-compose exec wordpress wp scaffold plugin-tests my-great-plugin.

Am I missing something again?

The VIP wrapper is working at least further than I have gotten with this one so far. Thanks a lot for your help, man. I will surely pass the wisdom on.

chriszarate commented 7 years ago

I think it's likely that you are using an older version of my wordpress image. I really should be versioning. I just pushed an update to this repo. Try:

git fetch origin master
git pull origin master
docker-compose stop
docker-compose build
docker-compose up -d
MikeiLL commented 7 years ago

At first got same error. So I docker rmi the wordpress image and now works. Still getting the annoying:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /tmp/wordpress/latest/tests/phpunit/includes/bootstrap.php

Had read somewhere that maybe a newer version of phpunit would solve that. But I'm imagining that you have the latest version installed.

chriszarate commented 7 years ago

WordPress is not yet compatible with the latest version (6.0.x) of PHPUnit. I've installed the latest stable version of the 5.0.x branch.

I definitely don't get that warning. Is that with the default tests that WP-CLI provides or your own tests?

MikeiLL commented 7 years ago

Well my plugin calls session_start(); on init, so somehow that is conflicting — I am guessing — with phpunit's output. It's certainly possible that it is just ignorant coding on my part. At first I thought one of the dependencies I was loading was generating some output, 'till I realized that it's actually the bootstrap file.

class MZ_Mindbody_API {

        protected $loader;

        protected $plugin_slug;

        protected $version;

        public function __construct() {

                $this->plugin_slug = 'mz-mindbody-api';
                $this->version = '2.4.1';
                $this->load_dependencies();
                $this->define_main_hooks();
                $this->add_shortcodes();

        }

        private function load_dependencies() {

        foreach ( glob( plugin_dir_path( __FILE__ )."inc/*.php" ) as $file )
            include_once $file;

            include_once(MZ_MINDBODY_SCHEDULE_DIR . 'mindbody-php-api/MB_API.php');
            include_once(MZ_MINDBODY_SCHEDULE_DIR . 'lib/functions.php');
            include_once(MZ_MINDBODY_SCHEDULE_DIR . 'lib/html_table.class.php');
            include_once(MZ_MINDBODY_SCHEDULE_DIR . 'lib/schedule_objects.php');

                $this->loader = new MZ_Mindbody_API_Loader();
        }

        private function define_admin_hooks() {

                $admin = new MZ_Mindbody_API_Admin( $this->get_version() );
                $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_styles' );
                $this->loader->add_action( 'add_meta_boxes', $admin, 'add_meta_box' );
        }

        private function define_main_hooks() {

                $this->loader->add_action( 'init', $this, 'myStartSession' );
                $this->loader->add_action( 'wp_logout', $this, 'myStartSession' );
                $this->loader->add_action( 'wp_login', $this, 'myEndSession' );

                }

        public function myStartSession() {
            if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) {
                    session_start();
                }
        }
MikeiLL commented 7 years ago

I'm gonna go ahead and close this since the issue with the session_start() conflict has nothing to do with your (wonderful) wrapper (or whatever it's called).

chriszarate commented 7 years ago

Just catching up to this. I would try to build your class in such a way that session_start is not called in your unit tests. There is a principle of "constructors should not have side effects" that I find instructive:

http://blog.millermedeiros.com/constructors-should-not-cause-side-effects/

In your case it would mean moving your method calls from the constructor to a separate method. It means an extra method call in your code when using your class, but the benefits are well-worth it (IMO).