Code Monkey home page Code Monkey logo

Comments (4)

thevikas avatar thevikas commented on May 24, 2024 1

For example the following hook is written twice because I want to test same 403 response for two different requests.

Hooks::before("sites > /api/sites/{id}.json > submits changes to existing site > 403 > application/json; charset=utf-8", function(&$transaction) 
{
//calls with wrong ID
$transaction->skip = false;
$transaction->fullPath = $transaction->request->uri = '/api/sites/21999.json?token=' . 'goodtoken';
    
}

Hooks::before("sites > /api/sites/{id}.json > submits changes to existing site > 403 > application/json; charset=utf-8", function(&$transaction) 
{
//calls with validation errors
$transaction->skip = false;
$transaction->fullPath = $transaction->request->uri = '/api/sites/21.json?token=' . 'goodtoken';
}

Only the first API call is made. The second one does not. Even though the hook itself is called but not the API.

from dredd-hooks-php.

ddelnano avatar ddelnano commented on May 24, 2024

Can you post some code examples. It’s very difficult for me to help without that.

from dredd-hooks-php.

lulco avatar lulco commented on May 24, 2024

Hi @thevikas for this purpose, I use this hack, hope it will help you:

use Dredd\Hooks;

Hooks::beforeAll(function(&$transactions) {
    $newTransactions = [];
    foreach ($transactions as $transaction) {
        if (strpos($transaction->name, ' > 403 > ') !== false) {
            // for all > 403 > paths create two new transactions, one skip second fail
            $newTransaction = clone $transaction;
            $newTransaction->skip = true;
            $newTransactions[] = $newTransaction;

            $newTransaction = clone $transaction;
            $newTransaction->fail = true;
            $newTransactions[] = $newTransaction;
        } else {
            // just copy other transactions
            $newTransactions[] = $transaction;
        }
    }
    $transactions = $newTransactions;
});

from dredd-hooks-php.

lulco avatar lulco commented on May 24, 2024

I found out that clone not working here, I used another hack unserialize(serialize($transaction)); and now it works (I hope :))

from dredd-hooks-php.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.