{"id":16724781,"url":"https://github.com/ddelnano/dredd-hooks-php","last_synced_at":"2026-03-17T06:34:56.478Z","repository":{"id":42954523,"uuid":"39274637","full_name":"ddelnano/dredd-hooks-php","owner":"ddelnano","description":"Dredd hooks handler client written in php.","archived":false,"fork":false,"pushed_at":"2023-07-11T10:26:29.000Z","size":702,"stargazers_count":45,"open_issues_count":8,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-13T00:40:32.945Z","etag":null,"topics":["dredd","dredd-hooks","php"],"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/ddelnano.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","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":"2015-07-17T20:49:07.000Z","updated_at":"2025-10-16T14:18:56.000Z","dependencies_parsed_at":"2024-06-18T18:34:56.726Z","dependency_job_id":"3d06b4e1-f78e-4da8-aca5-270744faf177","html_url":"https://github.com/ddelnano/dredd-hooks-php","commit_stats":{"total_commits":97,"total_committers":9,"mean_commits":"10.777777777777779","dds":"0.17525773195876293","last_synced_commit":"13982f442d116deb9cf1bfe8c596c55e4df057ee"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/ddelnano/dredd-hooks-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddelnano%2Fdredd-hooks-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddelnano%2Fdredd-hooks-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddelnano%2Fdredd-hooks-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddelnano%2Fdredd-hooks-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddelnano","download_url":"https://codeload.github.com/ddelnano/dredd-hooks-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddelnano%2Fdredd-hooks-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30615434,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T04:46:40.957Z","status":"ssl_error","status_checked_at":"2026-03-17T04:46:32.538Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["dredd","dredd-hooks","php"],"created_at":"2024-10-12T22:46:40.660Z","updated_at":"2026-03-17T06:34:56.435Z","avatar_url":"https://github.com/ddelnano.png","language":"PHP","readme":"# PHP Hooks for Dredd API Testing Framework\n[![Build Status](https://travis-ci.org/ddelnano/dredd-hooks-php.svg?branch=master)](https://travis-ci.org/ddelnano/dredd-hooks-php)\n[![Packagist](https://img.shields.io/packagist/dt/ddelnano/dredd-hooks-php.svg?maxAge=2592000)]()\n[![Packagist](https://img.shields.io/packagist/dm/ddelnano/dredd-hooks-php.svg?maxAge=2592000)]() [![Packagist](https://img.shields.io/packagist/v/ddelnano/dredd-hooks-php.svg?maxAge=2592000)]()  [![license](https://img.shields.io/github/license/ddelnano/dredd-hooks-php.svg?maxAge=2592000)]()\n\n## About\nThis package contains a PHP Dredd hook handler which provides a bridge between the [Dredd API Testing Framework](http://dredd.readthedocs.org/en/latest/)\n and PHP environment to ease implementation of testing hooks provided by [Dredd](http://dredd.readthedocs.org/en/latest/). Write Dredd hooks in PHP to glue together [API Blueprint](https://apiblueprint.org/) with your PHP project\n\nNot sure what these Dredd Hooks are?  Read the Dredd documentation on [them](http://dredd.readthedocs.org/en/latest/hooks/)\n\nThe following are a few examples of what hooks can be used for:\n\n- loading db fixtures\n- cleanup after test step or steps\n- handling authentication and sessions\n- passing data between transactions (saving state from responses to stash)\n- modifying request generated from blueprint\n- changing generated expectations\n- setting custom expectations\n- debugging via logging stuff\n\n\nExample\n\n```php\n\u003c?php\n\nuse Dredd\\Hooks;\n\nHooks::beforeAll(function(\u0026$transaction) {\n\n    // do any necessary setup\n});\n```\n## Installing\n\n### Composer\n\n#### Requirements\n\n- Must have php version 7.2 or greater. Older versions of php may work but they are untested.\n\n`dredd-hooks-php` can be easily installed through the use of [Composer](https://getcomposer.org/).\n\n`composer require ddelnano/dredd-hooks-php --dev`\n\n## Usage\n\n1. Create a hook file in `hooks.php`\n\n```php\n\nuse Dredd\\Hooks;\n\nHooks::before(\"/test \u003e GET\", function(\u0026$transaction) {\n\n    // do any before setup necessary\n});\n```\n\n**Very Important**  Please make sure the closure passed to any `Dredd\\Hooks` method uses a reference for the `$transaction` variable!!\nThis is necessary so that the `$transaction` variable does not need to be returned from the closure in order to persist changes to the variable\nin the closure's local scope.\n\n\n2. Run it with dredd\n\n`dredd apiary.apib localhost:3000 --language php --hookfiles ./hooks.php`\n\n## API\n\nThe `Dredd\\Hooks` class provides the following methods `before`, `after`, `before_all`, `after_all`, `before_each`, `after_each`, `before_validation`, and `before_each_validation`.\nThese methods correspond to the events that Dredd will run as it makes requests to the API endpoints defined in the blueprint/apiary.apib file.\nThe `before`, `before_validation` and `after` hooks are identified by [transaction name](http://dredd.readthedocs.org/en/latest/hooks/#getting-transaction-names)\n\n### Wildcards\n\n**Must be using version 1.1 or higher**\n\nWhen writing hooks for different api endpoints its very common to need the same hook for similar endpoints. For instance when testing Admin features\nthe request must be authenticated with a user that has admin privileges.  For all hooks needing this instead of writing a hook for each one the following \ncan be used.\n\n```php\nHooks::before('Admin \u003e *', function(\u0026$transaction) {\n\n    // This will be executed for any transaction with name starting with 'Admin \u003e '\n});\n```\n\nThis would execute for any transactions \"nested\" underneath 'Admin'.  For example the following transaction names would execute the callback: 'Admin \u003e Login', 'Admin \u003e Test', etc.\n\n## How to Contribute\n\n1. Fork it\n2. Create your feature branch (git checkout -b my-newfeature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Tests\n\nWhen making a contribution it is very important to not break existing functionality.  This project uses PHPUnit for unit testing and uses nodejs for Cucumber tests.  \n\n### Dependencies\n- Docker. This takes care of the php and nodejs dependencies.\n \nThe test suite can be run by following these steps:\n \n1. Run the phpunit and Cucumber tests\n```bash\nmake test\n```\n   \nMore details about the integration test can be found in the [dredd-hooks-template repo](https://github.com/apiaryio/dredd-hooks-template)   \n\n## Further Details\n\nFor examples and more information please visit the [wiki](https://github.com/ddelnano/dredd-hooks-php/wiki)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddelnano%2Fdredd-hooks-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddelnano%2Fdredd-hooks-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddelnano%2Fdredd-hooks-php/lists"}