Code Monkey home page Code Monkey logo

dredd-hooks-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dredd-hooks-php's Issues

Cannot connect to hooks server with Python.

Hi there. I can't seem to connect to the hooks server from my python hooks. Config files below. I saw this issue #3 but it doesn't appear to be an issue with start time of the hooks. I edited the installed version of dredd to make the timeout on waiting for the hooks server 10 seconds instead of 1, but still no luck. If I run the hooks command manually, it just sits there (which I would expect it's supposed to do, waiting for input?).

Error

$ ./node_modules/.bin/dredd
Configuration dredd.yml found, ignoring other arguments.
info: Using apiary reporter.
warn: Apiary reporter environment variable APIARY_API_KEY or APIARY_API_NAME not defined.
info: Beginning Dredd testing...
Spawning `python` hooks handler
Hook handler stderr: ccxcon/apiary_hooks.py:1: RuntimeWarning: Parent module 'apiary_hooks' not found while handling absolute import
  from dredd_hooks import hooks
Traceback (most recent call last):
  File "/home/jabrahms/.virtualenvs/ccxcon/bin/dredd-hooks-python", line 13, in <module>
    dredd.main(sys.argv[1:])
  File "/home/jabrahms/.virtualenvs/ccxcon/local/lib/python2.7/site-packages/dredd_hooks/dredd.py", line 222, in main
    load_hook_files(a)
  File "/home/jabrahms/.virtualenvs/ccxcon/local/lib/python2.7/site-packages/dredd_hooks/dredd.py", line 128, in load_hook_files
    module = imp.load_source(os.path.basename(path), path)
  File "ccxcon/apiary_hooks.py", line 1, in <module>
    from dredd_hooks import hooks
ImportError: cannot import name hooks

Error connecting to the hook handler. Is the handler running?
{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

dredd.yml

dry-run: false
hookfiles: 'ccxcon/apiary_hooks.py'
language: python
sandbox: false
init: false
custom: {}
names: false
only: []
reporter: apiary
output: []
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
color: true
level: info
timestamp: false
silent: false
path: []
blueprint: apiary.apib
endpoint: 'http://localhost:8000/'
# server: ./manage.py runserver   # I've been running this as a separate process
# server-wait: 3

ccxcon/apiary_hooks.py

from dredd_hooks import hooks

@hooks.before("info: Courses > Courses Collection > List All Courses")
def skip_test(transaction):
    transaction['skip'] = True

Changing the database provider when running tests

First of all, I want to thank you for the great testing tool!

I have one question regarding testing the api and most specifically the laravel example.
I saw that it uses the sqlite database by default. And when running dredd tests with hooks it migrates the database and everything is okey. But what about if I want to use mysql/mariadb for my application, and use only sqlite for dredd testing(I use in memory database for phpunit tests)

I understood that I needed to choose either migrating the database from scratch before tests or just use transactions. But as Its stated in #34 its better to use the first approach.

So my question is the following. How can I change the database when running dredd tests?

<?php

use Dredd\Hooks;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Artisan;

require __DIR__ . '/../../../vendor/autoload.php';

$app = require __DIR__ . '/../../../bootstrap/app.php';

$app->make(Kernel::class)->bootstrap();
DB::setDefaultConnection('sqlite');
DB::reconnect('sqlite');
var_dump(config('database.default'));

Hooks::beforeAll(function (&$transaction) use ($app) {
    Artisan::call('migrate:refresh', ['--force' => true, '--seed' => true, '--database' => 'sqlite']);
});

Hooks::before('/users > GET', function(&$transaction) {
    factory(\App\User::class)->create([
            'name' => 'Dom',
            'email' => '[email protected]',
        ]
    );
});

This is how my hooks file look like but it when running the tests it uses the mysql instead of sqlite? var_dump function prints sqlite by the way.

I would really appreciate any help figuring this out. Writing API specification and testing it sounds like a lot of fun!

Thank you in advance!

testing different params for testing similar response

I wish to test few errors and all these errors result in same http response code.
I'm using hooks and can't get it to run second time.
For e.g. 403 is returned for many reasons. I want to test two and dredd only runs for first test and forgets other.
Please help.

Set hook handler to php

Hey,

currently the doc says that I can run tests by running

dredd apiary.apib localhost:3000 --language php --hookfiles ./hooks.php

Whenever I do this, I get the error that the handle cannot be found and that I should run $ composer require ddelnano/dredd-hooks-php --dev

No matter how often I run this, I keep getting this message ... I think, it expects me to run this globally so composer global require ddelnano/dredd-hooks-php --dev, because it works fine, when I reference the hook-handler directly in vendor like

dredd apiary.apib localhost:3000 --language vendor/bin/dredd-hooks-php --hookfiles ./hooks.php

Is this a known issue, is the doc missing some further information or am i just doing something wrong?

Rollback test data

Hi, may i know how should i rollback the created data during dread test?

PHP Warning: stream_socket_accept(): accept failed: Operation timed out

Hi,

I am having an issue I cannot seem to figure out, related to: #26

/redacted/.bin/dredd --config=./tests/dredd/hooks/dredd.yml
warn: Error connecting to the hooks handler process. Is the handler running? Retrying.
error: Connection timeout 1.5s to hooks handler on 127.0.0.1:61321 exceeded. Try increasing the limit.
error Command failed with exit code 1.

Following steps found in different threads here, I launched the server manually:

vendor/bin/dredd-hooks-php --force
Starting server
PHP Warning:  stream_socket_accept(): accept failed: Operation timed out in /redacted/vendor/ddelnano/dredd-hooks-php/src/Server.php on line 39

Warning: stream_socket_accept(): accept failed: Operation timed out in /redacted/vendor/ddelnano/dredd-hooks-php/src/Server.php on line 39

I do not understand what is going on here, it's a pretty cryptic message, does this mean that the port is in use?

I am running in a local environment, with laravel + valet as a server.

My yml:

color: true
dry-run: null
hookfiles: ./tests/dredd/hooks/hookfile.php
language: vendor/bin/dredd-hooks-php
require: null
server: 'php -S localhost:3000 -t public/'
server-wait: 3
init: false
custom:
  apiaryApiKey: ''
names: false
only: []
reporter: []
output: []
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
loglevel: warning
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 1500
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 100
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: 127.0.0.1
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint: ./documentation/blueprint/api-description.apib
endpoint: 'http://localhost:3000/v1/'

Thanks for any help

Dredd hook not trigger when defining multiple requests within one method

Heya, so I've been stuck on this for several hours and no matter what I try, I can't seem to get this to work. I've defined a Dredd hook like this:

Hooks::before('Events > Timetable > Return Timetable Data', function () use ($app) {
    logger()->debug('Hook triggered');
});

And I've defined the following Blueprint:

# Group Events

## Timetable [/events/{event_id}/timetable{?apikey}]

### Return Timetable Data [GET]

+ Parameters
    + event_id (required, number, `1`) - A unique identifier of the event.
    + apikey (optional, string) - The API key of the event.

+ Request Success
    + Parameters
        + event_id: 2
        + apikey: secret
+ Response 200 (application/json)

        {
            "id": 2,
            "name": "Festival",
            "timezone": "UTC",
            "time_format": 24,
            "days": []
        }

+ Request Missing Api Key
+ Response 422 (application/json)

        {
            "message": "API Key is missing"
        }

+ Request Unauthorized
    + Parameters
        + apikey: invalidkey
+ Response 401 (application/json)
    + Body
        {
            "message": "Unauthorized"
        }

For some reason the Hook just won't trigger and I can't figure out why. I think it's because I'm defining multiple requests under one method call. Am I doing this right in setting up the spec like this?

The weird thing is that If I remove the last two requests like below the hook does pass.

# Group Events

## Timetable [/events/{event_id}/timetable{?apikey}]

### Return Timetable Data [GET]

+ Parameters
    + event_id (required, number, `1`) - A unique identifier of the event.
    + apikey (optional, string) - The API key of the event.

+ Request Success
    + Parameters
        + event_id: 2
        + apikey: secret
+ Response 200 (application/json)

        {
            "id": 2,
            "name": "Festival",
            "timezone": "UTC",
            "time_format": 24,
            "days": []
        }

It's exactly the same but with only one requests instead of three. Any ideas what I'm doing wrong here?

[Feature request] Support force parameter

At the moment, if there is already a process using the port, the hook process will fail. It could be nice to have a parameter to force the existing process to stop. This way, the dredd configuration file could look like:

...
language: "bin/dredd-hooks-php --force"
...

Dredd keeps failing to connect to hooks handler

Ok so, I've been pulling my hair out on this one. I keep getting the message below and have no clue what's going wrong. Tried increasing timeouts etc but I don't think that's the problem. Could it perhaps be file permissions related?

Here's the CLI output:

$ node_modules/.bin/dredd apiary.apib http://localhost:8001 --server "php -S 0.0.0.0:8001 -t public/" --language vendor/bin/dredd-hooks-php --hookfiles tests/dredd/hooks/hookfile.php
info: Starting backend server process with command: php -S 0.0.0.0:8001 -t public/
info: Waiting 3 seconds for backend server process to start.
[Sat Jan 21 07:54:39 2017] Failed to listen on 0.0.0.0:8001 (reason: Address already in use)
info: Backend server process exited.
info: Beginning Dredd testing...
info: Found Hookfiles: 0=tests/dredd/hooks/hookfile.php
info: Spawning `vendor/bin/dredd-hooks-php` hooks handler process.
warn: Error connecting to the hooks handler process. Is the handler running? Retrying.
info: Hooks handler stdout: Starting server

error: Connection timeout 1.5s to hooks handler on localhost:61321 exceeded. Try increasing the limit.
info: Sending SIGTERM to backend server process.

Here's the basic hookfile.php

<?php

use Dredd\Hooks;

require __DIR__.'/../../../vendor/autoload.php';

$app = require __DIR__.'/../../../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

Hooks::beforeEach(function (&$transaction) use ($app) {
    echo "before each";
});

Does anyone have an idea what I'm missing or what I might be doing wrong? Running PHP 5.5 with Laravel 5.2 for this specific project.

Release

Please, consider creating a new composer tag. There is no release since 2016.

Error connecting to the hook handler. Is the handler running?

I get the following on travis.

$ node_modules/dredd/bin/dredd
Configuration dredd.yml found, ignoring other arguments.
Starting server with command: app/api_v6/console server:run --docroot=web 127.0.0.1:8081
Waiting 3 seconds for server command to start...
info: Beginning Dredd testing...
Spawning `bin/dredd-hooks-php` hooks handler
Error connecting to the hook handler. Is the handler running?
{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

I have no idea why, I've ensured that the file is there and executable. So I've ran the script by itself and put it into the background. This just resulted in getting socket errors when the other tests were running.

error: Hooks handler command not found: dredd-hooks-php

Dredd version: 2.2.3
Dredd-hooks-php version: 1.1.5

Command: dredd /var/www/html/resources/docs/api-documentation.apib http://web/api/v1 --level=debug --language dredd-hooks-php --hookfiles /var/www/html/resources/dredd-hooks.php

The error error: Hooks handler command not found: dredd-hooks-php is always present. I've retracted my steps and am not able to figure out what I'm doing wrong. Is this version compatible with 2.2.3?

verbose: Compiling HTTP transactions from API description file: /var/www/html/resources/docs/api-documentation.apib
verbose: Starting reporters and waiting until all of them are ready.
info: Beginning Dredd testing...
verbose: Starting transaction runner.
verbose: Sorting HTTP transactions
verbose: Configuring HTTP transactions
verbose: Reading hook files and registering hooks
info: Found Hookfiles: 0=/var/www/html/resources/dredd-hooks.php
verbose: Looking up hooks handler implementation: dredd-hooks-php
verbose: Dredd instance run finished.
error: Hooks handler command not found: dredd-hooks-php
verbose: Exiting Dredd process with status '1'.
debug: Using configured custom exit() method to terminate the Dredd process.
verbose: Gracefully terminating backend server process.
verbose: No backend server process.

Getting error when running dredd

Hi, I often get the error below when running dredd.

dredd --language vendor/bin/dredd-hooks-php --hookfiles=./dredd-hooks-php/hooks*.php
info: Configuration dredd.yml found, ignoring other arguments.
info: Using apiary reporter.
info: Beginning Dredd testing...
info: Found Hookfiles: ./dredd-hooks-php/hooks_test.php
info: Spawning `vendor/bin/dredd-hooks-php` hooks handler
warn: Error connecting to the hook handler. Is the handler running? Retrying...
warn: Error connecting to the hook handler. Is the handler running? Retrying...
info: Hook handler stdout: Starting server

warn: Error connecting to the hook handler. Is the handler running? Retrying...
info: Connected to the hook handler, waiting 0.5s to start testing.
fail: PUT /permissions/1 duration: 383ms
warn: Hook handling timed out.
pass: POST /permissions duration: NaNms
pass: GET /permissions/1 duration: NaNms
pass: POST /permissions/search duration: NaNms
pass: DELETE /permissions/1 duration: NaNms
pass: PUT /roles/1 duration: NaNms
pass: POST /roles duration: NaNms
pass: GET /roles/1 duration: NaNms
warn: Hook handling timed out.
fail: POST /roles/search duration: 5290ms
/Users/warrence1/npm/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:287
    postData = JSON.stringify(body);
                    ^
TypeError: Converting circular structure to JSON
  at Object.stringify (native)
  at ApiaryReporter._performRequestAsync (/Users/warrence1/npm/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:287:21)
  at ApiaryReporter._performRequestAsync (/Users/warrence1/npm/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:3:57)
  at EventEmitter.<anonymous> (/Users/warrence1/npm/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:140:22)
  at EventEmitter.emit (events.js:129:20)
  at TransactionRunner.emitResult (/Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:424:38)
  at /Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:108:34
  at TransactionRunner.runHooksForData (/Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:210:14)
  at /Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:104:32
  at /Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:207:16
  at /Users/warrence1/npm/lib/node_modules/dredd/node_modules/async/lib/async.js:251:17
  at /Users/warrence1/npm/lib/node_modules/dredd/node_modules/async/lib/async.js:154:25
  at /Users/warrence1/npm/lib/node_modules/dredd/node_modules/async/lib/async.js:248:21
  at /Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:157:24
  at /Users/warrence1/npm/lib/node_modules/dredd/lib/transaction-runner.js:318:18
  at [object Object].handleTimeout [as _onTimeout] (/Users/warrence1/npm/lib/node_modules/dredd/lib/hooks-worker-client.js:325:20)
  at Timer.listOnTimeout (timers.js:119:15)

Sometimes is ok, sometimes is not, please help.

[Feature request] Support host and port parameters

At the moment, I cannot change my dredd configuration to listen to a different host or port other than the default defined by dredd.
It would be nice to be able to change that while starting the hooks. This way, the dredd configuration could look like:

# dredd.yml
...
language: "bin/dredd-hooks-php --host 0.0.0.0 --port 12345"
...
hooks-worker-handler-host: 0.0.0.0
hooks-worker-handler-port: 12345
...

Laravel example: Transactions not working

First of all, thanks for this package - it has helped me a lot.

Whats the problem?

I tried using the hooks as described in the Laravel example project. I was quickly able to get them to run, but no matter what i tried, the transactions did not work. A search in the issues revealed that this already happened to someone before, as described in #15

Proposal

What i require is a way of resetting the changes made by requests that the API tests generate. The only way i could think of was migrating the whole database before each testrun, like this:

Hooks::beforeAll(function (&$transaction) {
    \Illuminate\Support\Facades\Artisan::call('migrate:refresh', ['--seed' => true]);
});

Is there a better way? My main motivation behind this is achieving better test isolation through something like transactions. If this is the only way, maybe include the snippet above in the Laravel example - together with a short disclaimer explaining the limitations of transactions.

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.