Example #1
1
 /**
  * @param $method
  * @param $transaction
  * @return array
  */
 private function getCallbacksFromMethodCall($method, $transaction)
 {
     $propertyName = $this->getPropertyNameFromMethodCall($method);
     return Hooks::getCallbacksForName($propertyName, $transaction);
 }
 /**
  * @test
  */
 public function it_can_get_hooks_with_wildcards()
 {
     $transaction = new stdClass();
     $transaction->name = 'Admin > Test';
     Hooks::before('Admin > *', function (&$transaction) {
     });
     $hooks = Hooks::getCallbacksForName('beforeHooks', $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!';
});
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';
});
Example #5
0
<?php

use Dredd\Hooks;
Hooks::before("/message > GET", function ($transaction) {
    fprintf(STDOUT, "It's me, File1");
    flush();
});
    $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';
});
 /**
  * @test
  */
 public function it_can_handle_multiple_levels_of_nesting_in_transaction_names()
 {
     $wildcardName = 'Admin > admin logs in > *';
     $transaction = new stdClass();
     $transactionName = 'Admin > admin logs in > another event';
     $transaction->name = $transactionName;
     Hooks::before($wildcardName, function (&$transaction) {
         echo 'yay this is also called';
     });
     $this->runner->runBeforeHooksForTransaction($transaction);
     $this->expectOutputString('yay this is also called');
 }
Example #8
0
<?php

require __DIR__ . "/../vendor/autoload.php";
use Dredd\Hooks;
Hooks::before("/message > GET", function (&$transaction) {
    echo "It's me, File2";
});
Example #9
0
<?php

use Dredd\Hooks;
Hooks::beforeAll(function (&$transaction) {
    echo "before all php debug";
});