Пример #1
0
<?php

use Dredd\Hooks;
Hooks::before('/message > GET', function (&$transaction) {
    echo "before hook handled";
});
Hooks::after('/message > GET', function (&$transaction) {
    echo "after hook handled";
});
Hooks::beforeValidation('/message > GET', function (&$transaction) {
    echo 'before validation hook handled';
});
Hooks::beforeAll(function (&$transaction) {
    echo 'before all hook handled';
});
Hooks::afterAll(function (&$transaction) {
    echo 'after all hook handled';
});
Hooks::beforeEach(function (&$transaction) {
    echo 'before each hook handled';
});
Hooks::beforeEachValidation(function (&$transaction) {
    echo 'before each validation hook handled';
});
Hooks::afterEach(function (&$transaction) {
    echo 'after each hook handled';
});
Пример #2
0
 /**
  * @test
  */
 public function it_stores_wildcard_hooks_at_appropriate_index()
 {
     Hooks::after('Admin > *', function (&$transaction) {
     });
     $this->assertCount(1, Hooks::$afterHooks['Admin>']);
 }
<?php

use Dredd\Hooks;
$key = 'hook_modifications';
Hooks::before('/message > GET', function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'before modification';
});
Hooks::after('/message > GET', function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'after modification';
});
Hooks::beforeValidation('/message > GET', function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'before validation modification';
});
Hooks::beforeAll(function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'before all modification';
});
Hooks::afterAll(function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'after all modification';
});
Hooks::beforeEach(function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'before each modification';
});
Hooks::beforeEachValidation(function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'before each validation modification';