WPBP / WordPress-Plugin-Boilerplate-Powered

Wordpress Plugin Boilerplate but Powered with examples and a generator!
https://wpbp.github.io/
GNU General Public License v3.0
782 stars 116 forks source link

[Feature] Run codeception tests in a dockerized environment #199

Open LucasDemea opened 2 years ago

LucasDemea commented 2 years ago

Is your feature request related to a problem? Please describe. It would be nice if we could test our plugin right away without having to rely on a preinstalled wordpress site.

Describe the solution you'd like I'd like to use the official wordpress docker image to run the tests with a single command that would that care of building the container, launch selenium, and run the tests. It would also allow a better integration in our CI pipelines.

I'm almost ready with setting up this solution in one of my projects, and would be happy to submit a PR with a generalized solution, if you think that would be an improvement to WPBP.

Mte90 commented 2 years ago

Yes of course! I don't use docker for development (VVV) and for CI I have github/gitlab/codeship that run the codecept command. So go ahead I will add also an option to the https://github.com/WPBP/generator for it :-)

LucasDemea commented 2 years ago

Shall we discuss about the requirement then ? How do you actually use your VVV environment ? Is there any reason you need this instead of a fresh wp install (as WPLoader does) for running your acceptance & functional tests ? IMHO, in the use case of testing a plugin, we don't care about having a preconfgured site installed, we could just go with a fresh wp install at each run. What are your thoughts about this ?

Mte90 commented 2 years ago

I have no thoughts about it as I don't use docker at all and I have no bias for tests. I use VVV for development with vagrant so I run everything inside it (with another db) and for other stuff CI. So I think that the best way is do a dockerfile with everything and test it.

As you see also the CI of the boilerplate doesn't run the tests https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/.github/workflows/integrate.yml so it is complete from this side.

MikeiLL commented 1 year ago

Been using wp-env, which is dockerized and a pretty sweet package.

erikyo commented 1 year ago

@Mte90 I prepared a POC that can solve this issue, can install the codeception tests and run them inside wp-env... anyhow seems something is wrong because it returns there are 0 tests executed... am i doing something wrong?

https://github.com/erikyo/WordPress-Plugin-Boilerplate-Powered/blob/32da4b59a2896330da9a47917e08e177583f9c38/plugin-name/package.json#L34-L35

image

Mte90 commented 1 year ago

I think that isn't detecting the codeception settings. The CI is working so probably something is missing https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/.github/workflows/integrate.yml

erikyo commented 1 year ago

yeah i see... looks like some env variables were switched during the ci workflow

https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/ccd199f5e4f9e6a3897f9552fd140d3104173f12/.github/workflows/integrate.yml#L215-L216

and the original one doesn't fit the wp-env ports / domain etc.

Mte90 commented 1 year ago

If you run codecept with -vvv you get the full debug log with information like if loaded the codeception configuration file and so on.

JanKruft commented 8 months ago

@erikyo i guess if you run the bootstrap command the yml is created in root instead of plugin folder. Also on the run command. This is why no tests are found. If you want to have codecept running in plugin folder use. "wp-env:test": "npm run wp-env run tests-wordpress -- --env-cwd=wp-content/plugins/my-plugin-name vendor/bin/codecept run". But im stucking at the issue that wordpress-test container throws Db: could not find mysql driver while creating PDO connection. wp-env dosnt allow me to create a dockerfile and manipulating the docker-compose.yml created by wp-env is a bad DX.

Mte90 commented 8 months ago

As I can see on https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#customizing-the-wp-tests-config-php-file there is the file with the parameters to use the docker env to access the DB for tests so probably needs to be updated inside the plugin folder to fix the issue.

JanKruft commented 8 months ago

@Mte90 the envs are not the Problem. the missing mysql pdo inside the container the is currently my issue. May i need to swicht back to selfmade docker setup instead of @wordpress/env

Mte90 commented 8 months ago

Did you opened a ticket to the wp-env project for that?