-
Notifications
You must be signed in to change notification settings - Fork 7
Use data objects that are documented for the transaction object. #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m50
wants to merge
10
commits into
ddelnano:master
Choose a base branch
from
m50:transaction-dataobjects
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8732efc
Use data objects that are documented for the transaction.
m50 4797afb
Change headers to an array.
m50 e5382c6
Install dredd into the docker container.
m50 49c317f
Add Transaction objects to tests, to validate it doesn't negatively a…
m50 d9d7b8c
Should be `node` not `nodejs`.
m50 e43050d
Add a cucumber test for Transaction objects.
m50 ccc7328
Undo Transaction objects, as these stdClass ones aren't well formed.
m50 35fee5d
Convert headers to an array of string=>string.
m50 0c2557f
Add some defaults, just in case.
m50 ef960e1
Add a test specifically for Transaction object.
m50 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| Feature: Failing a transaction | ||
|
|
||
| Background: | ||
| 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) | ||
| """ | ||
| And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!" | ||
|
|
||
| @announce | ||
| Scenario: | ||
| Given a file named "hook_transaction_object.php" with: | ||
| """ | ||
| <?php | ||
|
|
||
| use Dredd\DataObjects\Transaction; | ||
| use Dredd\Hooks; | ||
|
|
||
| Hooks::beforeEach(function(Transaction &$transaction) { | ||
|
|
||
| echo 'Transaction object'; | ||
| }); | ||
| """ | ||
| When I run `dredd ./apiary.apib http://localhost:4567 --server "node server.js" --language php --hookfiles hook_transaction_object.php --loglevel debug` | ||
| Then the output should contain: | ||
| """ | ||
| Transaction object | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| use Dredd\DataObjects\Transaction; | ||
| use Dredd\Hooks; | ||
|
|
||
| Hooks::beforeEach(function(Transaction &$transaction) { | ||
|
|
||
| echo 'Transaction object'; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| namespace Dredd\DataObjects; | ||
|
|
||
| class ExpectedResponse | ||
| { | ||
| /** @var string $statusCode */ | ||
| public $statusCode; | ||
|
|
||
| /** | ||
| * Keys are HTTP header names, values are HTTP header contents | ||
| * | ||
| * @var array<string,string> | ||
| */ | ||
| public $headers; | ||
|
|
||
| /** @var string $body */ | ||
| public $body; | ||
|
|
||
| /** | ||
| * JSON Schema of the response body | ||
| * | ||
| * @var object $bodySchema | ||
| */ | ||
| public $bodySchema; | ||
|
|
||
| public function __construct($expected) | ||
| { | ||
| $this->statusCode = $expected->statusCode; | ||
| $this->headers = (array) $expected->headers; | ||
| $this->body = $expected->body; | ||
| $this->bodySchema = $expected->bodySchema; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace Dredd\DataObjects; | ||
|
|
||
| /** | ||
| * Reference to the transaction definition in the original API description document. | ||
| * (See also {@link https://github.com/apiaryio/dredd-transactions#user-content-data-structures Dredd Transactions}) | ||
| */ | ||
| class Origin | ||
| { | ||
| /** @var string $filename */ | ||
| public $filename; | ||
|
|
||
| /** @var string $apiName */ | ||
| public $apiName; | ||
|
|
||
| /** @var string $resourceGroupName */ | ||
| public $resourceGroupName; | ||
|
|
||
| /** @var string $resourceName */ | ||
| public $resourceName; | ||
|
|
||
| /** @var string $actionName */ | ||
| public $actionName; | ||
|
|
||
| /** @var string $exampleName */ | ||
| public $exampleName; | ||
|
|
||
| public function __construct($origin) | ||
| { | ||
| $this->filename = $origin->filename; | ||
| $this->apiName = $origin->apiName; | ||
| $this->resourceGroupName = $origin->resourceGroupName; | ||
| $this->resourceName = $origin->resourceName; | ||
| $this->actionName = $origin->actionName; | ||
| $this->exampleName = $origin->exampleName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| namespace Dredd\DataObjects; | ||
|
|
||
| class RealResponse | ||
| { | ||
| /** @var string $statusCode */ | ||
| public $statusCode; | ||
|
|
||
| /** | ||
| * Keys are HTTP header names, values are HTTP header contents | ||
| * | ||
| * @var object | ||
| */ | ||
| public $headers; | ||
|
|
||
| /** @var string $body */ | ||
| public $body; | ||
|
|
||
| /** | ||
| * - `utf-8` (string) - indicates `body` contains a textual content encoded in UTF-8 | ||
| * - `base64` (string) - indicates `body` contains a binary content encoded in Base64 | ||
| * | ||
| * @var string $bodyEncoding | ||
| * @psalm-var 'utf-8'|'base64' $bodyEncoding | ||
| */ | ||
| public $bodyEncoding; | ||
|
|
||
| public function __construct($expected) | ||
| { | ||
| $this->statusCode = $expected->statusCode; | ||
| $this->headers = $expected->headers; | ||
| $this->body = $expected->body; | ||
| $this->bodyEncoding = $expected->bodyEncoding; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
| namespace Dredd\DataObjects; | ||
|
|
||
| class Request | ||
| { | ||
| /** @var string $body */ | ||
| public $body; | ||
|
|
||
| /** | ||
| * Can be manually set in {@link https://dredd.org/en/latest/hooks/index.html#hooks hooks} | ||
| * - `utf-8` (string) - indicates `body` contains a textual content encoded in UTF-8 | ||
| * - `base64` (string) - indicates `body` contains a binary content encoded in Base64 | ||
| * | ||
| * @var string $bodyEncoding | ||
| * @psalm-var 'utf-8'|'base64' $bodyEncoding | ||
| */ | ||
| public $bodyEncoding; | ||
|
|
||
| /** | ||
| * Keys are HTTP header names, values are HTTP header contents | ||
| * @var array<string,string> $headers | ||
| */ | ||
| public $headers; | ||
|
|
||
| /** | ||
| * Request URI as it was written in API description | ||
| * | ||
| * @var string $uri | ||
| */ | ||
| public $uri; | ||
|
|
||
| /** @var string $method */ | ||
| public $method; | ||
|
|
||
| public function __construct($request) | ||
| { | ||
| $this->body = $request->body; | ||
| $this->bodyEncoding = $request->bodyEncoding; | ||
| $this->headers = (array) $request->headers; | ||
| $this->uri = $request->uri; | ||
| $this->method = $request->method; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| <?php | ||
|
|
||
| namespace Dredd\DataObjects; | ||
|
|
||
| use stdClass; | ||
|
|
||
| /** | ||
| * Transaction object is passed as a first argument to | ||
| * {@link https://dredd.org/en/latest/hooks/index.html#hooks hook functions} | ||
| * and is one of the main public interfaces in Dredd. | ||
| * | ||
| * @link https://dredd.org/en/latest/data-structures.html#transaction-object | ||
| */ | ||
| class Transaction | ||
| { | ||
| /** @var string $id */ | ||
| public $id; | ||
|
|
||
| /** | ||
| * Reference to the transaction definition in the original API description document | ||
| * (See also {@link https://github.com/apiaryio/dredd-transactions#user-content-data-structures Dredd Transactions}) | ||
| * | ||
| * @var string $name | ||
| */ | ||
| public $name; | ||
|
|
||
| /** @var string $host */ | ||
| public $host; | ||
|
|
||
| /** @var int $port */ | ||
| public $port; | ||
|
|
||
| /** @var string $protocol */ | ||
| public $protocol; | ||
|
|
||
| /** | ||
| * Expanded URI Template with parameters (if any) used for the HTTP request Dredd performs to the tested server | ||
| * | ||
| * @link https://tools.ietf.org/html/rfc6570.html | ||
| * @var string $fullPath | ||
| */ | ||
| public $fullPath; | ||
|
|
||
| /** | ||
| * Can be set to `true` and the transaction will be skipped | ||
| * | ||
| * @var bool $skip | ||
| */ | ||
| public $skip; | ||
|
|
||
| /** | ||
| * Can be set to `true` or string and the transaction will fail | ||
| * - (string) - failure message with details why the transaction failed | ||
| * - (boolean) | ||
| * @var bool|string $fail | ||
| */ | ||
| public $fail; | ||
|
|
||
| /** @var Origin $origin */ | ||
| public $origin; | ||
|
|
||
| /** | ||
| * Test data passed to Dredd’s reporters | ||
| * | ||
| * @link https://dredd.org/en/latest/data-structures.html#transaction-test | ||
| * @var object | ||
| */ | ||
| public $test; | ||
|
|
||
| /** | ||
| * Transaction runtime errors | ||
| * | ||
| * Whenever an exception occurs during a test run it’s being recorded under the errors property of the test. | ||
| * | ||
| * @link https://dredd.org/en/latest/data-structures.html#test-runtime-error | ||
| * @var object | ||
| */ | ||
| public $errors; | ||
|
|
||
| /** | ||
| * Transaction result equals to the result of the | ||
| * {@link https://github.com/apiaryio/gavel.js Gavel} validation library. | ||
| * | ||
| * @link https://dredd.org/en/latest/data-structures.html#transaction-results | ||
| * @var object | ||
| */ | ||
| public $results; | ||
|
|
||
| /** | ||
| * The HTTP request Dredd performs to the tested server, taken from the API description | ||
| * @var Request $request | ||
| */ | ||
| public $request; | ||
|
|
||
| /** @var ExpectedResponse $expected */ | ||
| public $expected; | ||
|
|
||
| /** @var RealResponse $real */ | ||
| public $real; | ||
|
|
||
| public function __construct($transaction) | ||
| { | ||
| $this->id = $transaction->id; | ||
| $this->name = $transaction->name; | ||
| $this->host = $transaction->host; | ||
| $this->port = $transaction->port; | ||
| $this->protocol = $transaction->protocol; | ||
| $this->fullPath = $transaction->fullPath; | ||
| $this->skip = $transaction->skip ?? false; | ||
| $this->fail = $transaction->fail ?? false; | ||
| $this->errors = $transaction->errors ?? new stdClass(); | ||
| $this->results = $transaction->results ?? new stdClass(); | ||
| $this->origin = new Origin($transaction->origin); | ||
| $this->request = new Request($transaction->request); | ||
| $this->expected = new ExpectedResponse($transaction->expected); | ||
| $this->real = new RealResponse($transaction->real); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.