/**
  * @test
  */
 public function it_can_get_hooks_without_names()
 {
     $transaction = new stdClass();
     $transaction->name = 'Admin > ';
     Hooks::beforeEach(function (&$transaction) {
     });
     $hooks = Hooks::getCallbacksForName('beforeEachHooks', $transaction);
     $this->assertCount(1, $hooks);
     $this->assertTrue(is_a($hooks[0], $this->className), sprintf("Expected %s received %s", $this->className, get_class($hooks[0])));
 }
<?php

use Dredd\Hooks;
Hooks::beforeEach(function (&$transaction) {
    $transaction->failed = true;
    echo 'Yay! Failed!';
});
    $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';
});
Hooks::afterEach(function ($transaction) use($key) {
    $transaction->key = [];
    $transaction->{$key}[] = 'after each modification';
});
Example #4
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';
});
 /**
  * @test
  */
 public function it_can_cause_before_each_transaction_to_fail()
 {
     $transactionName = 'transaction';
     $transaction = new stdClass();
     $transaction->name = $transactionName;
     $transaction->fail = false;
     Hooks::beforeEach(function (&$transaction) {
         $transaction->fail = true;
     });
     $this->assertFalse($transaction->fail);
     $status = $this->runner->runBeforeEachHooksForTransaction($transaction);
     $this->assertEquals(true, $status->fail);
 }