ddelnano/dredd-hooks-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ddelnano/dredd-hooks-php

Composer 安装命令:

composer require ddelnano/dredd-hooks-php

包简介

PHP hooks for the Dredd testing tool

关键字:

README 文档

README

Build Status Packagist Packagist Packagist license

About

This package contains a PHP Dredd hook handler which provides a bridge between the Dredd API Testing Framework and PHP environment to ease implementation of testing hooks provided by Dredd. Write Dredd hooks in PHP to glue together API Blueprint with your PHP project

Not sure what these Dredd Hooks are? Read the Dredd documentation on them

The following are a few examples of what hooks can be used for:

  • loading db fixtures
  • cleanup after test step or steps
  • handling authentication and sessions
  • passing data between transactions (saving state from responses to stash)
  • modifying request generated from blueprint
  • changing generated expectations
  • setting custom expectations
  • debugging via logging stuff

Example

<?php

use Dredd\Hooks;

Hooks::beforeAll(function(&$transaction) {

    // do any necessary setup
});

Installing

Composer

Requirements

  • Must have php version 7.2 or greater. Older versions of php may work but they are untested.

dredd-hooks-php can be easily installed through the use of Composer.

composer require ddelnano/dredd-hooks-php --dev

Usage

  1. Create a hook file in hooks.php
use Dredd\Hooks;

Hooks::before("/test > GET", function(&$transaction) {

    // do any before setup necessary
});

Very Important Please make sure the closure passed to any Dredd\Hooks method uses a reference for the $transaction variable!! This is necessary so that the $transaction variable does not need to be returned from the closure in order to persist changes to the variable in the closure's local scope.

  1. Run it with dredd

dredd apiary.apib localhost:3000 --language php --hookfiles ./hooks.php

API

The Dredd\Hooks class provides the following methods before, after, before_all, after_all, before_each, after_each, before_validation, and before_each_validation. These methods correspond to the events that Dredd will run as it makes requests to the API endpoints defined in the blueprint/apiary.apib file. The before, before_validation and after hooks are identified by transaction name

Wildcards

Must be using version 1.1 or higher

When writing hooks for different api endpoints its very common to need the same hook for similar endpoints. For instance when testing Admin features the 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 can be used.

Hooks::before('Admin > *', function(&$transaction) {

    // This will be executed for any transaction with name starting with 'Admin > '
});

This would execute for any transactions "nested" underneath 'Admin'. For example the following transaction names would execute the callback: 'Admin > Login', 'Admin > Test', etc.

How to Contribute

  1. Fork it
  2. Create your feature branch (git checkout -b my-newfeature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push (git push origin my-new-feature)
  5. Create a new Pull Request

Tests

When 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.

Dependencies

  • Docker. This takes care of the php and nodejs dependencies.

The test suite can be run by following these steps:

  1. Run the phpunit and Cucumber tests
make test

More details about the integration test can be found in the dredd-hooks-template repo

Further Details

For examples and more information please visit the wiki

ddelnano/dredd-hooks-php 适用场景与选型建议

ddelnano/dredd-hooks-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.28M 次下载、GitHub Stars 达 45, 最近一次更新时间为 2015 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「dredd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ddelnano/dredd-hooks-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ddelnano/dredd-hooks-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 ddelnano/dredd-hooks-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.28M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 46
  • 点击次数: 12
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 45
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-22