{"id":36334649,"url":"https://github.com/polylang/wp-phpunit","last_synced_at":"2026-01-11T12:04:24.340Z","repository":{"id":37905829,"uuid":"320334318","full_name":"polylang/wp-phpunit","owner":"polylang","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-18T13:28:48.000Z","size":94,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-18T22:49:30.731Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polylang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-10T16:52:46.000Z","updated_at":"2025-07-18T13:28:49.000Z","dependencies_parsed_at":"2024-11-21T10:20:38.686Z","dependency_job_id":"330af62a-0c46-4bba-bd3b-73fc084cf9c7","html_url":"https://github.com/polylang/wp-phpunit","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":"0.23684210526315785","last_synced_commit":"33b22d2e5e5d361341608f897bd7018a5ff7f5cc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/polylang/wp-phpunit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fwp-phpunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fwp-phpunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fwp-phpunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fwp-phpunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polylang","download_url":"https://codeload.github.com/polylang/wp-phpunit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fwp-phpunit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28302203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-11T12:04:23.801Z","updated_at":"2026-01-11T12:04:24.327Z","avatar_url":"https://github.com/polylang.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polylang PHPUnit\n\nA code library for WP Syntex projects, containing:\n\n- scripts to install the WordPress test suite,\n- scripts to install the required plugins and themes,\n- scripts for building and distributing the project,\n- bootstraps allowing to init unit and integration tests,\n- helpers for the tests.\n\n## How to\n\n### Install the test suite\n\nThe test suite is installed in  **your project**'s `tmp` folder.\n\nTo tell the installation script how to connect to your database, you can create a `DB-CONFIG` file at the root of your project and formatted like follow (the file is not versioned with git of course).  \nEach line is optional, the default values are:\n\n```txt\ndb_host: localhost\ndb_name: wordpress_tests\ndb_user: root\ndb_pass: '' (an empty string)\n```\n\n### Install the dependencies\n\nThe plugins and themes are installed in **your project**'s `tmp` folder.\n\nCreate a `install-plugins.sh` file that launches all the downloads. Example:\n\n```bash\n#!/usr/bin/env bash\n\n. \"$PWD/vendor/wpsyntex/wp-phpunit/bin/wp-download-tools.sh\"\n\nmkdir -p $WP_PLUGINS_DIR\nmkdir -p $WP_THEMES_DIR\n\n# Install WP All Import Pro.\ndownloadPluginFromEdd wp-all-import-pro 'WP All Import' https://www.wpallimport.com\n\n# Install Polylang Pro.\ndownloadPolylangPro\n\n# Install Polylang for WooCommerce.\ndownloadPolylangForWoocommerce\n\n# Install WooCommerce.\ndownloadWoocommerce\n\n# Install TwentyFourteen.\ndownloadThemeFromRepository twentyfourteen\n```\n\nNote: two variables are available for you to use: `$WP_PLUGINS_DIR` and `$WP_THEMES_DIR`. They contain the path to `tmp/plugins` and `tmp/themes` respectively, where the plugins and themes are installed. Those folders are not created by default so don't forget to do `mkdir -p $WP_PLUGINS_DIR` and/or `mkdir -p $WP_THEMES_DIR` like in the previous example, before using the download functions.\n\nPremium plugins installed from EDD need a bit more attention because they need a license key. You can provide it by creating a `LICENSE-CODES` file at the root of your project and formatted like follow (the file is not versioned with git of course):\n\n```txt\nlicense {PLUGIN-SLUG}:{YOUR-LICENSE}\nsite {PLUGIN-SLUG}:{YOUR-SITE}\n```\n\nDepending on EDD config, the `site` line may not be required.  \nAlso, if your plugin from EDD doesn't require a license key, do the following:\n\n```txt\nlicense {PLUGIN-SLUG}:none\n```\n\n### Composer scripts\n\nThen you can create composer scripts like these ones for example:\n\n```json\n{\n    \"scripts\": {\n        \"install-suite\": \"vendor/wpsyntex/wp-phpunit/bin/install-wp-suite.sh\",\n        \"install-suite-with-db\": \"vendor/wpsyntex/wp-phpunit/bin/install-wp-suite.sh latest true\",\n        \"install-plugins\": \"Tests/bin/install-plugins.sh\",\n        \"install-tests\": [\n            \"@install-suite\",\n            \"@install-plugins\"\n        ],\n        \"install-tests-with-db\": [\n            \"@install-suite-with-db\",\n            \"@install-plugins\"\n        ],\n        \"build\": \"vendor/wpsyntex/wp-phpunit/bin/build.sh\",\n        \"build-update\": \"vendor/wpsyntex/wp-phpunit/bin/build.sh -- -u\",\n        \"dist\": \"vendor/wpsyntex/wp-phpunit/bin/distribute.sh -- polylang-foobar\"\n    },\n    \"scripts-descriptions\": {\n        \"install-suite\": \"Installs the WordPress tests suite (without installing the database).\",\n        \"install-suite-with-db\": \"Installs the WordPress tests suite (with database creation).\",\n        \"install-plugins\": \"Installs dependencies needed for integration tests.\",\n        \"install-tests\": \"Installs both the WordPress tests suite (without installing the database) and the dependencies needed for integration tests.\",\n        \"install-tests-with-db\": \"Installs both the WordPress tests suite (with database creation) and the dependencies needed for integration tests, without creating the database.\",\n        \"build\": \"Builds the project.\",\n        \"build-update\": \"Builds the project (runs `composer update` instead of `composer install`).\",\n        \"dist\": \"Makes the zip file to distribute the project release.\"\n    }\n}\n```\n\n### Integration tests\n\n#### Bootstrap for integration tests\n\nExample for your `bootstrap.php` file:\n\n```php\n\u003c?php\n/**\n * Bootstraps the Polylang Foobar integration tests\n * php version 7.0\n *\n * @package WP_Syntex\\Polylang_Foobar\\Tests\\Integration\n */\n\nnamespace WP_Syntex\\Polylang_Foobar\\Tests\\Integration;\n\nuse function WP_Syntex\\Polylang_Phpunit\\Integration\\bootstrapSuite;\n\nrequire dirname( dirname( __DIR__ ) ) . '/vendor/wpsyntex/wp-phpunit/UnitTests/Integration/bootstrap.php';\n\nbootstrapSuite(\n    dirname( __DIR__ ), // Path to the directory containing all tests.\n    '7.0.0', // The PHP version required to run this test suite.\n    [\n        'plugins' =\u003e [\n            'polylang-pro/polylang.php'                            =\u003e true,\n            'woocommerce/woocommerce.php'                          =\u003e [\n                'group' =\u003e 'WithWoo',\n                'init'  =\u003e '\\WP_Syntex\\Polylang_Phpunit\\Integration\\WooCommerce\\Bootstrap::initWoocommerce',\n            ],\n            'polylang-wc/polylang-wc.php'                          =\u003e [\n                'group' =\u003e 'WithWoo',\n            ],\n            dirname( dirname( __DIR__ ) ) . '/polylang-foobar.php' =\u003e true,\n        ], // A list of plugins to include and activate.\n    ]\n);\n```\n\nThe previous code will:\n\n- Require `polylang.php` and `polylang-foobar.php`.\n- Require `woocommerce.php` and `polylang-wc.php` if `--group=WithWoo` is used when invoking phpunit.\n- Call `\\WP_Syntex\\Polylang_Phpunit\\Integration\\WooCommerce\\Bootstrap::initWoocommerce()` after `woocommerce.php` is required.\n\n#### Use the trait in your integration tests\n\nYou can use the trait `WP_Syntex\\Polylang_Phpunit\\Integration\\TestCaseTrait` in your integration tests.\n\nHint: if you need to create your own methods `set_up()`, `wpSetUpBeforeClass`, etc, you can't simply call the ones from the trait with `parent::` like you would with parent/child classes. In this case you can do that:\n\n```php\n\u003c?php\n/**\n * Test Case for all of the integration tests.\n * php version 7.0\n *\n * @package WP_Syntex\\Polylang_Foobar\\Tests\\Integration\n */\n\nnamespace WP_Syntex\\Polylang_Foobar\\Tests\\Integration;\n\nuse WP_Syntex\\Polylang_Phpunit\\Integration\\TestCaseTrait;\nuse WP_UnitTest_Factory;\nuse WP_UnitTestCase;\n\nabstract class AbstractTestCase extends WP_UnitTestCase {\n    use TestCaseTrait {\n        wpSetUpBeforeClass as private traitWpSetUpBeforeClass;\n        set_up as private traitSetUp;\n    }\n\n    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {\n        self::traitWpSetUpBeforeClass( $factory );\n        // Do things.\n    }\n\n    public function set_up() {\n        $this-\u003etraitSetUp();\n        // Do more things.\n    }\n}\n```\n\nIf you need to list some plugins among the \"active ones\" (`get_option( 'active_plugins' )`) for your integration tests (this may be required for some plugins that test which plugins are active), you can create a class like this one in your tests:\n\n```php\n\u003c?php\n/**\n * Test Case for all of the integration tests.\n * php version 7.0\n *\n * @package WP_Syntex\\Polylang_Foobar\\Tests\\Integration\n */\n\nnamespace WP_Syntex\\Polylang_Foobar\\Tests\\Integration;\n\nuse WP_Syntex\\Polylang_Phpunit\\Integration\\TestCaseTrait;\nuse WP_UnitTestCase;\n\n/**\n * Test Case for all of the integration tests.\n */\nabstract class AbstractTestCase extends WP_UnitTestCase {\n    use TestCaseTrait;\n\n    /**\n     * List of active plugins.\n     *\n     * @var array\u003cstring\u003e\n     */\n    protected $activePlugins = [\n        'wp-all-import-pro/wp-all-import-pro.php',\n    ];\n}\n\n```\n\nSome helpers are available in your tests, like toying with reflections or getting test data. You can find them in the `TestCaseTrait` trait.\n\n### Unit tests\n\n#### Bootstrap for unit tests\n\nExample for your `bootstrap.php` file:\n\n```php\n\u003c?php\n/**\n * Bootstraps the Polylang Foobar Unit Tests.\n * php version 7.0\n *\n * @package WP_Syntex\\Polylang_Foobar\\Tests\\Unit\n */\n\nnamespace WP_Syntex\\Polylang_Foobar\\Tests\\Unit;\n\nuse function WP_Syntex\\Polylang_Phpunit\\Unit\\bootstrapSuite;\n\nrequire dirname( dirname( __DIR__ ) ) . '/vendor/wpsyntex/wp-phpunit/UnitTests/Unit/bootstrap.php';\n\nbootstrapSuite( dirname( __DIR__ ), '7.0.0' );\n```\n\n#### Extend the abstract class in your unit tests\n\nYou can extend `WP_Syntex\\Polylang_Phpunit\\Unit\\AbstractTestCase` in your unit tests.\n\n[Brain\\Monkey](https://brain-wp.github.io/BrainMonkey/) is available in your unit tests, since it is included in [Yoast\\WPTestUtils](https://github.com/Yoast/wp-test-utils).\n\nIn your tests you can mock [WordPress' most common functions](https://github.com/Yoast/wp-test-utils/blob/develop/src/BrainMonkey/TestCase.php) by setting two custom properties. And like for integration tests, some helpers are available in your tests, from the `TestCaseTrait` trait.\n\n```php\n\u003c?php\n/**\n * Tests for `WP_Syntex\\Polylang_Foobar\\barbaz()`.\n * php version 7.0\n *\n * @package WP_Syntex\\Polylang_Foobar\\Tests\\Unit\n */\n\nnamespace WP_Syntex\\Polylang_Foobar\\Tests\\Unit;\n\nuse WP_Syntex\\Polylang_Phpunit\\Unit\\AbstractTestCase;\n\n/**\n * Tests for `WP_Syntex\\Polylang_Foobar\\barbaz()`.\n */\nclass Barbaz extends AbstractTestCase {\n\n    /**\n     * Stubs the WP native translation functions in the set_up().\n     *\n     * @var bool\n     */\n    protected static $stubTranslationFunctions = true;\n\n    /**\n     * Stubs the WP native escaping functions in the set_up().\n     *\n     * @var bool\n     */\n    protected static $stubEscapeFunctions = true;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolylang%2Fwp-phpunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolylang%2Fwp-phpunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolylang%2Fwp-phpunit/lists"}