Closed MikeiLL closed 7 years ago
The PHPUNIT_TEST_DIR
environment variable should be the absolute system path (inside the container) to your phpunit.xml. The system path to wp-content
is /var/www/html/wp-content/
.
The example file in this repo shows /var/www/html/wp-content/plugins/my-plugin
as an example. You only need to edit it if you changed the corresponding path in the volumes
section.
The only purpose of this environment variable is when using the convenience command to run PHPUnit tests:
docker-compose exec wordpress tests
This command will chdir
to the path contained in PHPUNIT_TEST_DIR
. If you run tests via some other means, you don't need to set PHPUNIT_TEST_DIR
.
Yes. I am running docker-compose exec wordpress tests
. actually added an alias to my ~/.bashrc
:
alias tests=docker-compose exec wordpress tests
so I can just run tests
in the command line, which seems to be working with just my-plugin
set in the .env
file, and not the entire path.
This is totally outside of the scope of this wonderful little repository, but am I able to add variables to .env
and access them in the test files?
Yes, you can pull in these env vars using getenv in PHP.
I expected to be able to and tried. This getenv('DOCKER_DEV_DOMAIN');
, when called in a test within the tests directory within the plugin, returns nothing. I must be missing a step. At the moment I just added some attributes to a gitignored static class file and put an Autoloader in the tests structure, but would love to see this work, if I haven't already over-taxed you.
Also I realize I was thinking that PHPUNIT_TEST_DIR
was supposed to be inside of the .env
file.
Ah, you're right. Two things here:
Variables in .env
are specific to Docker Compose and are not passed into the container.
Variables defined in the environment
section of docker-compose.yml
are passed into the container. However the way I'm running the tests
command doesn't expose them to your test code. I'll look into fixing that.
That would be a cool feature, and if the plugin repo is next to docker-compose.yml, then those could be variables like credentials that you wouldn't want in a public repo.
Arg. Not quite there yet with having plugin in directory within the repo clone, I just discovered, that while my tests are running fine, however the literal my-plugin.php
file at the top level that is being installed and activated as my-actual-plugin
, and trying to reference the files and directories parallel to it as plugin files.
Needed to update the docker-compose.yml
:
services:
wordpress:`
...stuff...
volumes:
- "./my-actual-plugin/var/www/html/wp-content/plugins/my-actual-plugin"
Wondering if it would be best to just use this the way you originally intended it. But it seems like a lot of files to add at the top level of my plugin, which already begs cleaning up. : )
Closing this issue, feel free to reopen if you are still having trouble.
Am not clear on what the
.env
variable,PHPUNIT_TEST_DIR
is supposed to be doing. Is it supposed to be a full path that runs on the hosted docker container?Want to keep the tests within the directory of the plugin, at least for now.
If I update this repo's phpunit.xml.dist file:
Then it will run my bootstrap and tests:
When I have the
.env
set to:It still seems to be looking at the
phpunit.xml
file from this repo, in the dir above my plugin.