Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor/
tmp
examples/laravel/vendor/
.phpcomplete_extended/
node_modules
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
before_install:
- nvm install node && nvm use node
- npm install -g dredd --no-optional
- bundle install
- npm install
- composer install
php:
- "5.4"
Expand All @@ -15,4 +15,4 @@ php:
script:
- vendor/bin/phpcs --standard=psr2 -n src/
- vendor/bin/phpunit
- bundle exec cucumber
- npx cucumber-js features --require features/support --tags "not @skip"
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ FROM php
RUN apt-get update \
&& apt-get install -y \
wget \
nodejs \
npm \
git \
net-tools \
&& wget https://getcomposer.org/installer \
&& chmod +x installer \
&& php installer --install-dir=/usr/local/bin/ --filename=composer
&& php installer --install-dir=/usr/local/bin/ --filename=composer \
5 changes: 0 additions & 5 deletions Gemfile

This file was deleted.

46 changes: 0 additions & 46 deletions Gemfile.lock

This file was deleted.

21 changes: 16 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
.PHONY: lint test

test: lint
vendor/bin/phpunit
bundle exec cucumber

IMAGE := dredd-hooks-php
DOCKER_RUN := docker run -it --init -v $$(pwd):/src -w /src $(IMAGE)

build:
docker build -t $(IMAGE) .

test: build lint node_modules
$(DOCKER_RUN) bash -c \
"vendor/bin/phpunit && \
npx cucumber-js features --require features/support/ --tags 'not @skip'"

lint: vendor
vendor/bin/phpcs --standard=psr2 -n src/
$(DOCKER_RUN) vendor/bin/phpcs --standard=psr2 -n src/

vendor:
composer install
$(DOCKER_RUN) composer install

node_modules:
$(DOCKER_RUN) npm install
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,17 @@ This would execute for any transactions "nested" underneath 'Admin'. For exampl

## Tests

When making a contribution it is very important to not break existing functionality. This project uses PHPUnit for unit testing and
uses ruby based aruba.
When making a contribution it is very important to not break existing functionality. This project uses PHPUnit for unit testing and uses nodejs for Cucumber tests.

### Dependencies
- Docker. This takes care of the php and nodejs dependencies.

The test suite can be run by following these steps:

1. Install PHPUnit and cucumber locally. From the project root directory run

`composer install`

`bundle install`

2. Execute PHPUnit tests

`vendor/bin/phpunit`

3. Run aruba/cucumber tests

`bundle exec cucumber`
1. Run the phpunit and Cucumber tests
```bash
make test
```

More details about the integration test can be found in the [dredd-hooks-template repo](https://github.com/apiaryio/dredd-hooks-template)

Expand Down
4 changes: 0 additions & 4 deletions apiary.apib

This file was deleted.

20 changes: 6 additions & 14 deletions features/execution_order.feature
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
Feature: Execution order

Background:
Given I have "dredd-hooks-php" command installed
And I have "dredd" command installed
And a file named "server.rb" with:
"""
require 'sinatra'
get '/message' do
"Hello World!\n\n"
end
"""

Given I have dredd-hooks-php installed
And I have Dredd installed
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
And a file named "apiary.apib" with:
"""
# My Api
## GET /message
+ Response 200 (text/html;charset=utf-8)
Hello World!
+ Response 200 (text/html)
"""

@announce
Scenario:
Given a file named "hooks/execution_order_hookfile.php" with:
Given a file named "execution_order_hookfile.php" with:
"""
<?php

Expand Down Expand Up @@ -90,7 +82,7 @@ Feature: Execution order
| variable | value |
| TEST_DREDD_HOOKS_HANDLER_ORDER | true |

When I run `dredd ./apiary.apib http://localhost:4567 --server "ruby server.rb" --language dredd-hooks-php --hookfiles hooks/execution_order_hookfile.php`
When I run `dredd ./apiary.apib http://localhost:4567 --server "node server.js" --language php --hookfiles=./execution_order_hookfile.php`
Then the exit status should be 0
Then the output should contain:
"""
Expand Down
21 changes: 7 additions & 14 deletions features/failing_transaction.feature
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
Feature: Failing a transaction

Background:
Given I have "dredd-hooks-php" command installed
And I have "dredd" command installed
And a file named "server.rb" with:
"""
require 'sinatra'
get '/message' do
"Hello World!\n\n"
end
"""

Given I have dredd-hooks-php installed
Given I have Dredd installed
And a file named "apiary.apib" with:
"""
# My Api
## GET /message
+ Response 200 (text/html;charset=utf-8)
Hello World!
+ Response 200 (text/html)
"""
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"

@announce
Scenario:
Given a file named "hooks/failedhook.php" with:
Given a file named "failedhook.php" with:
"""
<?php

Expand All @@ -31,9 +23,10 @@ Feature: Failing a transaction

$transaction->fail = true;
echo "Yay! Failed!";
flush();
});
"""
When I run `dredd ./apiary.apib http://localhost:4567 --server "ruby server.rb" --language "dredd-hooks-php" --hookfiles hooks/failedhook.php`
When I run `dredd ./apiary.apib http://localhost:4567 --server "nodejs server.js" --language php --hookfiles failedhook.php --loglevel debug`
Then the exit status should be 1
And the output should contain:
"""
Expand Down
24 changes: 9 additions & 15 deletions features/hook_handlers.feature
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
Feature: Hook handlers

Background:
Given I have "dredd-hooks-php" command installed
And I have "dredd" command installed
And a file named "server.rb" with:
"""
require 'sinatra'
get '/message' do
"Hello World!\n\n"
end
"""

Given I have dredd-hooks-php installed
Given I have Dredd installed
And a file named "apiary.apib" with:
"""
# My Api
## GET /message
+ Response 200 (text/html;charset=utf-8)
Hello World!
+ Response 200 (text/html)
"""
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"

@announce
Scenario:
Expand All @@ -30,12 +22,14 @@ Feature: Hook handlers

Hooks::before('/message > GET', function(&$transaction) use ($key) {

var_dump("before hook handled");
fprintf(STDERR, "before hook handled");
flush();
});

Hooks::after('/message > GET', function(&$transaction) use ($key) {

echo "after hook handled";
fprintf(STDERR, "after hook handled");
flush();
});

Hooks::beforeValidation('/message > GET', function(&$transaction) use ($key) {
Expand Down Expand Up @@ -69,7 +63,7 @@ Feature: Hook handlers
});
"""

When I run `dredd ./apiary.apib http://localhost:4567 --server "ruby server.rb" --language dredd-hooks-php --hookfiles ./hookfile.php`
When I run `dredd ./apiary.apib http://localhost:4567 --server "node server.js" --language php --hookfiles ./hookfile.php --loglevel debug`
Then the exit status should be 0
Then the output should contain:
"""
Expand Down
26 changes: 9 additions & 17 deletions features/multiple_hookfiles.feature
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
Feature: Multiple hook files with a glob

Background:
Given I have "dredd-hooks-php" command installed
And I have "dredd" command installed
And a file named "server.rb" with:
"""
require 'sinatra'
get '/message' do
"Hello World!\n\n"
end
"""

Given I have dredd-hooks-php installed
Given I have Dredd installed
And a file named "apiary.apib" with:
"""
# My Api
## GET /message
+ Response 200 (text/html;charset=utf-8)
Hello World!
+ Response 200 (text/html)
"""
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"

@announce
Scenario:
Given a file named "hooks/hookfile1.php" with:
Given a file named "hookfile1.php" with:
"""
<?php

Expand All @@ -33,7 +25,7 @@ Feature: Multiple hook files with a glob
flush();
});
"""
And a file named "hooks/hookfile2.php" with:
And a file named "hookfile2.php" with:
"""
<?php

Expand All @@ -45,7 +37,7 @@ Feature: Multiple hook files with a glob
flush();
});
"""
And a file named "hooks/hookfile_to_be_globed.php" with:
And a file named "hookfile_to_be_globed.php" with:
"""
<?php

Expand All @@ -57,7 +49,7 @@ Feature: Multiple hook files with a glob
flush();
});
"""
When I run `dredd ./apiary.apib http://localhost:4567 --server "ruby server.rb" --language dredd-hooks-php --hookfiles hooks/hookfile1.php --hookfiles hooks/hookfile2.php --hookfiles hooks/hookfile_*.php`
When I run `dredd ./apiary.apib http://localhost:4567 --server "node server.js" --language php --hookfiles hookfile1.php --hookfiles hookfile2.php --hookfiles hookfile_*.php --loglevel debug`
Then the exit status should be 0
And the output should contain:
"""
Expand All @@ -70,4 +62,4 @@ Feature: Multiple hook files with a glob
And the output should contain:
"""
It's me, File3
"""
"""
10 changes: 4 additions & 6 deletions features/server_configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ Feature: Configuring the server

@announce
Scenario: Starting the server with --force flag if port is blocked
Given I run `dredd-hooks-php` interactively
When I wait for output to contain "Starting"
Then I run `dredd-hooks-php --force` interactively
Given I run "dredd-hooks-php" interactively, I wait for output to contain "Starting"
Then I run "dredd-hooks-php --force" interactively, I wait for output to contain "Starting"

@announce
Scenario: Starting the server on non standard port
Given I run `dredd-hooks-php --port 1123` interactively
When I wait for output to contain "Starting"
Then It should start listening on localhost port "1123"
Given I run "dredd-hooks-php --port 1123" interactively, I wait for output to contain "Starting"
Then It should start listening on localhost port 1123

Loading