{"id":25518288,"url":"https://github.com/pretzlaw/wp-integration-test","last_synced_at":"2025-10-13T07:04:29.085Z","repository":{"id":55033228,"uuid":"131606737","full_name":"pretzlaw/wp-integration-test","owner":"pretzlaw","description":"Mocking return value of functions/filters and more for testing WordPress with PHPUnit.","archived":false,"fork":false,"pushed_at":"2021-01-21T12:44:13.000Z","size":387,"stargazers_count":5,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"release/0.4","last_synced_at":"2025-10-13T07:04:17.314Z","etag":null,"topics":["integration-tests","phpunit","wordpress"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"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/pretzlaw.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}},"created_at":"2018-04-30T14:35:45.000Z","updated_at":"2022-08-17T22:37:38.000Z","dependencies_parsed_at":"2022-08-14T09:40:38.147Z","dependency_job_id":null,"html_url":"https://github.com/pretzlaw/wp-integration-test","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/pretzlaw/wp-integration-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretzlaw%2Fwp-integration-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretzlaw%2Fwp-integration-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretzlaw%2Fwp-integration-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretzlaw%2Fwp-integration-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pretzlaw","download_url":"https://codeload.github.com/pretzlaw/wp-integration-test/tar.gz/refs/heads/release/0.4","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretzlaw%2Fwp-integration-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014083,"owners_count":26085459,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["integration-tests","phpunit","wordpress"],"created_at":"2025-02-19T16:25:02.374Z","updated_at":"2025-10-13T07:04:29.069Z","avatar_url":"https://github.com/pretzlaw.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://img.shields.io/badge/PHP-7.0%20--%208.0-blue?style=for-the-badge\u0026logo=php)\n![](https://img.shields.io/badge/WordPress-4.6%20--%205.6-blue?style=for-the-badge\u0026logo=wordpress)\n![](https://img.shields.io/badge/PHPUnit-6.5%20--%209.5-blue?style=for-the-badge)\n\n# WordPress Integration Test Helper\n\n\u003e Mocking return value of functions/filters and more for testing WordPress with PHPUnit.\n\nWriting tests with WordPress is a pain as the very old\n[official WordPress Unit Tests](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/)\nalways require a lot of hands on for custom projects\nand other Testing-Frameworks try to mock the hell out of WordPress.\nThe solution is to have a nice integration tests package that ...\n\n- ... can be integrated into your already existing tests (using Traits).\n- ... enabled you to test your package against other Plugins or Themes.\n- ... allows testing in advanced complex projects.\n\nOverall the goal is **simplicity** and **no time wasting crap** (for me and you).\n\n## Install\n\nDownload or just\n\n    composer install --dev pretzlaw/wp-integration-test\n\nBesides PHP and WordPress we do not require that much\n([see Packagist.org for more details](https://packagist.org/packages/pretzlaw/wp-integration-test)):\n\n- phpUnit 6.5 - 9.5\n- mockery 1.3\n\n\n## Usage\n\nIf you start from scratch and do not have some bootstrapping already,\nthen you can use our bootstrapping like this:\n\n```xml\n\u003cphpunit bootstrap=\"vendor/Pretzlaw/WPInt/bootstrap.php\"\u003e\n\t\u003ctestsuites\u003e\n\t\t\u003ctestsuite name=\"default\"\u003e\n\t\t    \u003c!-- CHANGE THIS TO WHERE YOUR PHPUNIT TEST CLASSES ARE --\u003e\n\t\t\t\u003cdirectory\u003elib/tests\u003c/directory\u003e\n\t\t\u003c/testsuite\u003e\n\t\u003c/testsuites\u003e\n\u003c/phpunit\u003e\n```\n\nUsing this bootstrap.php is **not** mandatory.\nFeel free to create a custom bootstrapping file,\nwhen you need to test CLI and admin stuff too.\n\n\n### Example\n\nIf you know PHPUnit already then asserting\nand mocking shouldn't be something new.\nWith WPInt it can be for most PHPUnit Tests by adding one Trait:\n\n```php\nclass FooTest extends \\PHPUnit\\Framework\\TestCase {\n\n    use \\Pretzlaw\\WPInt\\Traits\\WordPressTests;\n    \n    function testBar() {\n\n        // Assertions (simple or with special constraints)\n        static::assertActionHasCallback( 'init', 'my_own_init' );\n        static::assertShortcodeHasCallback(\n            [ new IsInstanceOf( MyOwn::class ), 'some_method' ],\n            'my_shortcode'\n        );\n        \n        // Mock posts or meta-data\n        $this-\u003emockGetPost( 1337 )-\u003eandReturn( /* your wp post mock */ );\n        $this-\u003emockPostMeta( 'some_key' )-\u003eandReturn( 'Some value!' ); // For all posts\n        $this-\u003emockMetaData( 'my-own-cpt', 'another_key', 1337 )-\u003eandReturn( 'ec' ); // Just for ID 1337\n        \n        // Mock actions, filter, cache, ...\n        $this-\u003emockFilter( 'user_has_cap' )\n             -\u003eandReturn( true );\n        \n        $this-\u003emockCache()\n            -\u003eshouldReceive('get')\n            -\u003ewith('my_own_cache')\n            -\u003eandReturn('yeah');\n\n        // Or use one of several shortcuts and helper\n        $this-\u003edisableWpDie();\n    }\n}\n```\n\nAs you see above we are using\n[mockery/mockery:~1](https://packagist.org/packages/mockery/mockery)\nwhich is easier to use and maintain but uses\ndifferent method names (e.g. `shouldReceive`, `andReturn` as seen above).\n\n\n### List of all Assertions\n\n* assert Action Has Callback\n* assert Action Not Empty\n* assert Action Not Has Callback\n* assert Filter Empty\n* assert Filter Has Callback\n* assert Filter Not Empty\n* assert Filter Not Has Callback\n* assert Plugin Is Active\n* assert Plugin Is Not Active\n* assert Post Type Args\n* assert Post Type Labels\n* assert Post Type Registered\n* assert Shortcode Exists\n* assert Shortcode Has Callback\n* assert Shortcode Not Exists\n* assert Widget Exists\n* assert Widget Is Instance Of\n* assert Widget Is Not Instance Of\n* assert Widget Not Exists\n\n### List of WordPress Expectations / Mocks\n\n* expect Wp Post Insert Post\n* mock Cache\n* mock Current User\n* mock Filter\n* mock Get Post\n* mock Meta Data\n* mock Post Meta\n* mock Shortcode\n* mock User Meta\n\n\n### Other testing helper\n\n* backup Widgets\n* disable `wp_die()`\n* get All Shortcodes\n* get Shortcode Callback\n* get Widget Factory\n* get Wp Hooks\n* unregister All Widgets\n* unregister Widgets By Id\n\nFeel free to request for additional features\nor point out more common shortcuts by\n[opening an issue](https://github.com/pretzlaw/wp-integration-test/issues).\n\n\n## License\n\nCopyright 2021 Pretzlaw (rmp-up.de)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software\nand associated documentation files (the \"Software\"), to deal in the Software without restriction,\nincluding without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies\nor substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\nINCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE\nAND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF\nOR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpretzlaw%2Fwp-integration-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpretzlaw%2Fwp-integration-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpretzlaw%2Fwp-integration-test/lists"}