Closed MikeiLL closed 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
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.
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?
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();
}
}
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).
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).
Hello again, dear Chris.
I think
/tmp
is empty.Working with this tree:
After cycling docker-compose up and down and back up, with
.env
:Seems:
No
wordpress-tests-lib
Hmmm.
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.