{"id":21178806,"url":"https://github.com/valu-digital/wp-testing-tools","last_synced_at":"2025-07-09T22:31:49.993Z","repository":{"id":36468058,"uuid":"220801183","full_name":"valu-digital/wp-testing-tools","owner":"valu-digital","description":"WordPress testing for everyone! 🤗","archived":false,"fork":false,"pushed_at":"2022-07-02T11:30:31.000Z","size":154,"stargazers_count":24,"open_issues_count":2,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-16T22:41:32.768Z","etag":null,"topics":["testing","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/valu-digital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-10T14:25:47.000Z","updated_at":"2023-08-24T14:22:41.000Z","dependencies_parsed_at":"2022-08-08T15:01:17.740Z","dependency_job_id":null,"html_url":"https://github.com/valu-digital/wp-testing-tools","commit_stats":null,"previous_names":[],"tags_count":18,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valu-digital%2Fwp-testing-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valu-digital%2Fwp-testing-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valu-digital%2Fwp-testing-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valu-digital%2Fwp-testing-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valu-digital","download_url":"https://codeload.github.com/valu-digital/wp-testing-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225600216,"owners_count":17494587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["testing","wordpress"],"created_at":"2024-11-20T17:26:34.355Z","updated_at":"2024-11-20T17:26:35.200Z","avatar_url":"https://github.com/valu-digital.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Testing Tools\n\nWordPress testing for everyone! 🤗\n\nTesting WordPress plugins is PITA. The wp-browser project makes it possible\nbut it requires a working WordPress installation to be used. Unfortunately\nsetting up one is very laborious which is why many especially smaller plugins\nomit tests completely. So the humble mission of this project is make that\nbarrier go away completely so there would be no excuses to not write tests\nfor WordPress plugins! 💪\n\nThis project contains following components:\n\n- A Composer installable script (`wp-install`) for installing WordPress into\n  Docker containers, Github Actions or where ever.\n- Reuseable Docker enviroment for local testing and debugging with xdebug\n- Github Action Workflow for continuous integration\n- Example plugin on how to setup all this\n\nProjects using this setup\n\n- https://github.com/valu-digital/wp-graphql-cache\n- https://github.com/valu-digital/wp-graphql-polylang\n- https://github.com/valu-digital/wp-graphql-lock\n- https://github.com/valu-digital/wp-graphql-offset-pagination\n\n## Starting\n\nFor new projects you can just copy all files from `plugin/` and rename the\n\"example\" strings.\n\nFor existing projects you can install this using composer\n\n    composer require --dev valu/wp-testing-tools\n    # You'll want the wp-browser too\n    composer require --dev lucatume/wp-browser\n\nAfter installing you can copy the test files to your plugin with\n\n    ./vendor/bin/wptt-configure\n\n## Plugin files\n\nThe example plugin is under the `plugin/` directory. Lets go through it file\nby file and explain the purpose of each.\n\n### `composer.json`\n\nThis is the main composer file which makes your plugin installable using\nComposer. Define any library dependencies of your plugin here but do not add\nother plugins here since your plugin users might want to install those by\nother means.\n\nIn it we define this package as a dev requirement under `\"require-dev\"` with\n`\"valu/wp-testing-tools\": \"^0.4.0\"`.\n\nBut the most interesting part is the `\"wp-install\"` script under `\"scripts\"`:\n\n    wp-install --full --wp-composer-file composer.wp-install.json --env-file .env\n\nThis `wp-install` tool is provided by this package and it actually does the\nWordPress installation using wp-cli.\n\nIt takes few arguments\n\n- `--full`: Make full installation for functional and acceptance testing.\n  This can be omitted when just doing wpunit tests.\n- `--wp-composer-file`: The `composer.json` file to use when installing\n  WordPress\n- `--env-file`: The .env file to use\n- The `--wp-composer-file` and `--env-file` arguments are optional and the\n  example is just showing the defaults\n- For more information see `--help` or the [source](https://github.com/valu-digital/wp-testing-tools/blob/master/tools/wp-install).\n\n### `composer.wp-install.json`\n\nSince we cannot add WP plugin dependencies to the main `composer.json` we can\nadd them here and they get installed \u0026 activated to the testing installation\nautomatically.\n\n### `.env`\n\nThis file is copied from `.env.github` or `.env.docker` depending on the\nenvironment. It contains the database credentials and the installation\nlocation for WordPress. Checkout their content for more information.\n\n### `codeception.dist.yml`\n\nThe Codeception config. You must configure your plugin entry point (among\nwith the ones defined in `composer.wp-install.json`) to the\n`modules.config.WPLoader.plugins` and\n`modules.config.WPLoader.activatePlugins` sections to be activated during\nwpunit tests.\n\n### `tests/`\n\nThe directory containing the tests. Please refer to the Codeception and\nwp-browser documention.\n\n### `docker/`\n\nThis directory contains the Docker enviroment configuration. You as the\nplugin author are not supposed to edit anything under this directory. Any\ncustomizations you need should be doable in `.env.docker` and other\nextensions points. If you need some help customizing the Docker enviroment\nfeel free to open an issue!\n\nThis way the Docker enviroment is upgradeable. Just copy the latest version\nfrom this repository when you want to update to the latest version.\n\nThe docker directory exposes a `run` script for working with the enviroment:\n\n- `./docker/run compose`: This is a small wrapper over `docker-compose` which\n  used to starts the Docker enviroment.\n- `./docker/run shell`: Once the environment is setup you can use this script\n  to enter the testing shell to run `codecept` commands\n- `./docker/run update`: When you update the `valu/wp-testing-tools` composer\n  package this command can be used to update the Docker environment.\n\nThe plugin directory will be mounted to `/app` so you can make changes from\nthe host and they are visible immediately to the container.\n\n### `plugin.php` and `src/`\n\nThese are opinionated take on how to structure WordPress plugins with\nComposer Autoloading. If you don't care about that or are adapting existing\nplugin you can just remove these files along with the `\"autoload\"` config\nfrom `composer.json`.\n\nBut if you do it's highly recommend that you read the comments in\n[plugin.php](/plugin/plugin.php). It contains information on how to ship your\nplugin properly to both composer and non-composer users.\n\n## Customizing the WP install for Functiontal Tests\n\nYou can add a `tests/wptt-wp-config.php` which is required in the install's\n`wp-config.php` if it is readable.\n\nYou can also add `tests/wptt-mu-plugin.php` which is loaded as a mu-plugin in\nthe install if it is readable.\n\n## Using XDebug with Docker\n\n### Visual Studio Code\n\nInstall the [PHP Debug][php] extension.\n\n1. Add launch config to `.vscode/launch.json` or to the global config:\n\n```json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"name\": \"Docker: PHP Listen for XDebug\",\n      \"type\": \"php\",\n      \"request\": \"launch\",\n      \"port\": 9000,\n      \"pathMappings\": {\n        \"/app\": \"${workspaceFolder}\"\n      }\n    }\n  ]\n}\n```\n\n2. Start the container with `./docker/run compose`\n\n3. From the VSCode `DEBUG AND RUN` view start the `Docker: PHP Listen for XDebug` launch config\n\n4. Add break points\n\n5. Start testing shell `./docker/run shell` and run the tests with `codecept run wpunit`\n\nProfit!\n\n[remote]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers\n[php]: https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug\n\n### PHPStorm\n\nThe IDEKEY is \"wptt\".\n\nPlease contribute?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalu-digital%2Fwp-testing-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalu-digital%2Fwp-testing-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalu-digital%2Fwp-testing-tools/lists"}