{"id":20140255,"url":"https://github.com/10quality/wpmvc-addon-testsuite","last_synced_at":"2026-05-08T06:06:07.401Z","repository":{"id":65177663,"uuid":"585717364","full_name":"10quality/wpmvc-addon-testsuite","owner":"10quality","description":"Test suite for WPMVC add-ons.","archived":false,"fork":false,"pushed_at":"2023-02-10T22:23:17.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-13T12:16:45.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/10quality.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":"2023-01-05T22:19:38.000Z","updated_at":"2023-01-05T23:29:42.000Z","dependencies_parsed_at":"2023-02-08T01:15:52.184Z","dependency_job_id":null,"html_url":"https://github.com/10quality/wpmvc-addon-testsuite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fwpmvc-addon-testsuite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fwpmvc-addon-testsuite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fwpmvc-addon-testsuite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fwpmvc-addon-testsuite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/10quality","download_url":"https://codeload.github.com/10quality/wpmvc-addon-testsuite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241583976,"owners_count":19986076,"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":[],"created_at":"2024-11-13T21:49:54.432Z","updated_at":"2026-05-08T06:06:07.361Z","avatar_url":"https://github.com/10quality.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress MVC - Addon test suite\n\n## Install\n\nComposer command to install as `required-dev`:\n```bash\ncomposer install 10quality/wpmvc-addon-testsuite --dev\n```\n\n## Test Case Class\n\nInstead of the default PHPUnit test case use the following:\n```php\nuse WPMVC\\Addons\\PHPUnit\\TestCase;\n\nclass MyTest extends TestCase\n{\n    // Your test methods\n}\n```\n\nThis classs will allow you to use the following assertiong methods:\n\n| Method | Parameters | Description |\n| --- | --- | --- |\n| `$this-\u003eassertDidAction` | `$handle` the action hook name handle. | Asserts if an action ran. |\n| `$this-\u003eassertDidNotAction` | `$handle` the action hook name handle. | Asserts if an action not ran. |\n| `$this-\u003eassertAppliedFilters` | `$handle` the filter hook name handle. | Asserts if filters have been applied to a hook. |\n| `$this-\u003eassertNotAppliedFilters` | `$handle` the filter hook name handle. | Asserts if filters have been not applied to a hook. \n| `$this-\u003eassertAddedAction` | `$handle` the action hook name handle. | Asserts if an action handler has been added for a hook. |\n| `$this-\u003eassertNotAddedAction` | `$handle` the action hook name handle. | Asserts if no action handlers has been added for a hook. |\n| `$this-\u003eassertAddedFilter` | `$handle` the filter hook name handle. | Asserts if a filter handler has been added for a hook. |\n| `$this-\u003eassertNotAddedFilter` | `$handle` the filter hook name handle. | Asserts if no filter handlers has been added for a hook. |\n| `$this-\u003eassertHasRegisterStyle` | `$handle` the style name handle. | Asserts if a style asset has been registered. |\n| `$this-\u003eassertNotHasRegisterStyle` | `$handle` the style hook name handle. | Asserts if a style asset has not been registered. |\n| `$this-\u003eassertHasRegisterScript` | `$handle` the script name handle. | Asserts if a script asset has been registered. |\n| `$this-\u003eassertNotHasRegisterScript` | `$handle` the script hook name handle. | Asserts if a script asset has not been registered. |\n| `$this-\u003eassertHasEnqueueStyle` | `$handle` the style name handle. | Asserts if a style asset has been registered. |\n| `$this-\u003eassertNotHasEnqueueStyle` | `$handle` the style hook name handle. | Asserts if a style asset has not been registered. |\n| `$this-\u003eassertHasEnqueueScript` | `$handle` the script name handle. | Asserts if a script asset has been enqueued. |\n| `$this-\u003eassertNotHasEnqueueScript` | `$handle` the script hook name handle. | Asserts if a script asset has not been enqueued. |\n| `$this-\u003eassertHasCalledWP` | `$function` the name of a WordPress core function. | Asserts if a core WordPress function has been called. |\n| `$this-\u003eassertNotHasCalledWP` | `$function` the name of a WordPress core function. | Asserts if a core WordPress function has not been called. |\n\nExample:\n```php\nuse WPMVC\\Addons\\PHPUnit\\TestCase;\n\nclass MyTest extends TestCase\n{\n    public function testAction()\n    {\n        // Run\n        do_action( 'init' );\n        // Assert\n        $this-\u003eassertDidAction( 'init' );\n    }\n}\n```\n\n### Test your addon\n\nYou addon main class needs a WordPress MVC main class (bridge) instance to work correctly. The `TestCase` class include the method `getBridgeMock()` that allows you to test your addon mocking the Bridge class.\n\nExample:\n```php\nuse WPMVC\\Addons\\PHPUnit\\TestCase;\nuse MyAddon;\n\nclass MyAddonTest extends TestCase\n{\n    public function testInit()\n    {\n        // Prepare\n        $bridge = $this-\u003egetBridgeMock();\n        $addon = new MyAddon( $bridge );\n        // Run\n        $addon-\u003einit();\n        // Assert\n        $this-\u003eassertAddedAction( 'init' );\n        $this-\u003eassertHasRegisterScript( 'my-js' );\n    }\n}\n```\n\nThe example above tests the method `init()` of the addon class `MyAddon`, which receives the `$bridge` initialized as a mock. The example asserts that an action hook has been added and a script has been registered during the method call.\n\nYou can mock the `Bridge` for your own benefit:\n```php\nuse WPMVC\\Addons\\PHPUnit\\TestCase;\nuse WPMVC\\Addons\\PHPUnit\\Mocks\\Brige;\nuse MyAddon;\n\nclass MyAddonTest extends TestCase\n{\n    public function testInit()\n    {\n        // Prepare\n        $bridge = $this-\u003egetMockBuilder( Brige::class )\n            -\u003edisableOriginalConstructor()\n            -\u003egetMock();\n        $addon = new MyAddon( $bridge );\n        // Run\n        $addon-\u003einit();\n        // Assert\n        $this-\u003eassertAddedAction( 'init' );\n        $this-\u003eassertHasRegisterScript( 'my-js' );\n    }\n}\n```\n\n### Reset test suite data\n\nYou can reset test suite data by calling the function `wpmvc_addon_phpunit_reset()` inside the `setUp` or `tearDown` methods.\n\n## WordPress core functions mocked\n\nThe following WordPress core functions are mocked and included through composer:\n\n* `__`\n* `_e`\n* `add_action`\n* `add_filter`\n* `add_query_arg`\n* `add_submenu_page`\n* `admin_url`\n* `apply_filters`\n* `do_action`\n* `esc_attr`\n* `esc_html`\n* `esc_html_e`\n* `esc_url`\n* `get_filesystem_method`\n* `get_locale`\n* `get_stylesheet_directory`\n* `home_url`\n* `request_filesystem_credentials`\n* `sanitize_text_field`\n* `site_url`\n* `submit_button`\n* `wp_enqueue_script`\n* `wp_enqueue_style`\n* `wp_register_script`\n* `wp_register_style`\n* `WP_Filesystem`\n\n## WordPress core constants mocked\n\nThe following constants are mocked through composer if they are not defined:\n\n* `ABSPATH`\n\n## WordPress core classes mocked\n\nThe following WordPress classes are mocked and included through composer:\n\n* `WP_Filesystem`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10quality%2Fwpmvc-addon-testsuite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F10quality%2Fwpmvc-addon-testsuite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10quality%2Fwpmvc-addon-testsuite/lists"}