2017 © Pedro Peláez
 

library dredd-hooks-php

PHP hooks for the Dredd testing tool

image

ddelnano/dredd-hooks-php

PHP hooks for the Dredd testing tool

  • Monday, March 5, 2018
  • by ddelnano
  • Repository
  • 1 Watchers
  • 33 Stars
  • 240,002 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 17 Versions
  • 9 % Grown

The README.md

PHP Hooks for Dredd API Testing Framework

Build Status Packagist Packagist Packagist license, (*1)

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, (*2)

Not sure what these Dredd Hooks are? Read the Dredd documentation on them, (*3)

The following are a few examples of what hooks can be used for:, (*4)

  • 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, (*5)

<?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., (*6)

composer require ddelnano/dredd-hooks-php --dev, (*7)

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., (*8)

  1. Run it with dredd

dredd apiary.apib localhost:3000 --language php --hookfiles ./hooks.php, (*9)

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, (*10)

Wildcards

Must be using version 1.1 or higher, (*11)

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., (*12)

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., (*13)

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., (*14)

Dependencies

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

The test suite can be run by following these steps:, (*15)

  1. Run the phpunit and Cucumber tests
make test

More details about the integration test can be found in the dredd-hooks-template repo, (*16)

Further Details

For examples and more information please visit the wiki, (*17)

The Versions

05/03 2018

dev-master

9999999-dev https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

27/02 2018

dev-update-txn-information

dev-update-txn-information https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

08/02 2017

dev-add-port-hooks-server-test

dev-add-port-hooks-server-test https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

15/05 2016

1.1.5

1.1.5.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

02/03 2016

1.1.4

1.1.4.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

07/01 2016

1.1.3

1.1.3.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

05/01 2016

1.1.2

1.1.2.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Domenic Del Nano

dredd

27/12 2015

1.1.1

1.1.1.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

02/10 2015

1.1.0

1.1.0.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

11/09 2015

1.0.2

1.0.2.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

08/09 2015

1.0.1

1.0.1.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

26/07 2015

1.0.0

1.0.0.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

26/07 2015

0.1.4

0.1.4.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

26/07 2015

0.1.3

0.1.3.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

26/07 2015

0.1.2

0.1.2.0 https://github.com/ddelnano/dredd-hooks-php/wiki

PHP hooks for the Dredd testing tool

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Domenic Del Nano

dredd

22/07 2015

0.1.1

0.1.1.0

PHP hooks for the Dredd testing tool

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

22/07 2015

0.1.0

0.1.0.0

PHP hooks for the dredd testing tool

  Sources   Download

The Development Requires