Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
Mink/Behat testing begun
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Leitner committed Dec 11, 2014
1 parent b61213d commit 451e362
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -6,4 +6,4 @@ test:
php ./bin/phpunit -c build/

phantomjs:
./node_modules/.bin/phantomjs --webdriver=4444 --ssl-protocol=TLSv1 --ignore-ssl-errors=yes &
phantomjs --webdriver=8643 --ignore-ssl-errors=yes &
15 changes: 15 additions & 0 deletions behat.yml
@@ -0,0 +1,15 @@
phantomjs:
context:
parameters:
user: ''
password: ''
features_path: %behat.paths.features%
paths:
features: tests/integrations
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
base_url: 'test.bitpay.com'
goutte: ~
selenium2:
wd_host: "http://localhost:8643/wd/hub"
8 changes: 6 additions & 2 deletions composer.json
Expand Up @@ -38,8 +38,12 @@
"symfony/dependency-injection": "~2.3"
},
"require-dev": {
"behat/mink": "1.6.*@stable",
"behat/mink-selenium2-driver": "~1.1",
"behat/behat": "2.4.*@stable",
"behat/mink": "1.4.*@stable",
"behat/mink-extension": "@stable",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"phpmd/phpmd": "~2.1.3",
"phpunit/phpunit": "~4.3.1",
"fzaninotto/faker": "~1.4.0",
Expand Down
147 changes: 147 additions & 0 deletions tests/integrations/bootstrap/FeatureContext.php
@@ -0,0 +1,147 @@
<?php

use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;

use Behat\MinkExtension\Context\MinkContext;

require __DIR__ . '/../../../vendor/autoload.php';
//
// Require 3rd-party libraries here:
//
// require_once 'PHPUnit/Autoload.php';
// require_once 'PHPUnit/Framework/Assert/Functions.php';
//

/**
* Features context.
*/
class FeatureContext extends MinkContext
{
private $params = array();
/**
* Initializes context.
* Every scenario gets it's own context object.
*
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters)
{
$this->params = $parameters;
}
/**
* @Then /^I wait for the suggestion box to appear$/
*/
public function iWaitForTheSuggestionBoxToAppear()
{
$this->getSession()->wait(5000,
"$('.suggestions-results').children().length > 0"
);
}

/**
* @Given /^that there is no token saved locally$/
*/
public function thatThereIsNoTokenSavedLocally()
{
$token_path = $this->params['features_path'].'token.txt';
if (file_exists($token_path))
unlink($token_path);
}

/**
* @Given /^that there is a local keyfile$/
*/
public function thatThereIsALocalKeyfile()
{
$token_path = $this->params['features_path'].'pri.pem';
}

/**
* @When /^the user pairs with BitPay with a valid pairing code$/
*/
public function theUserPairsWithBitpayWithAValidPairingCode()
{
throw new PendingException();
}

/**
* @Given /^tokens will be saved locally$/
*/
public function tokensWillBeSavedLocally()
{
throw new PendingException();
}

/**
* @Given /^that there is no local keyfile$/
*/
public function thatThereIsNoLocalKeyfile()
{
$key_path = $this->params['features_path'].'pri.pem';
if (file_exists($key_path))
unlink($key_path);
}

/**
* @Then /^the keyfile will be saved locally$/
*/
public function theKeyfileWillBeSavedLocally()
{
throw new PendingException();
}

/**
* @Given /^the user fails to pair with a semantically invalid code "([^"]*)"$/
*/
public function theUserFailsToPairWithASemanticallyInvalidCode($arg1)
{
throw new PendingException();
}

/**
* @Then /^they will receive a BitPay::ArgumentError matching "([^"]*)"$/
*/
public function theyWillReceiveABitpayArgumenterrorMatching($arg1)
{
throw new PendingException();
}

/**
* @When /^the fails to pair with BitPay because of an incorrect port$/
*/
public function theFailsToPairWithBitpayBecauseOfAnIncorrectPort()
{
throw new PendingException();
}

/**
* @Then /^they will receive a BitPay::ConnectionError matching "([^"]*)"$/
*/
public function theyWillReceiveABitpayConnectionerrorMatching($arg1)
{
throw new PendingException();
}

/**
* @Given /^the user fails to pair with a semantically valid code "([^"]*)"$/
*/
public function theUserFailsToPairWithASemanticallyValidCode($arg1)
{
throw new PendingException();
}

/**
* @Then /^they will receive a BitPay::BitPayError matching "([^"]*)"$/
*/
public function theyWillReceiveABitpayBitpayerrorMatching($arg1)
{
throw new PendingException();
}


}
32 changes: 32 additions & 0 deletions tests/integrations/pairing.feature
@@ -0,0 +1,32 @@
# pairing.feature
Feature: pairing with bitpay
In order to access bitpay
It is required that the library
Is able to pair successfully

Background:
Given that there is no token saved locally

Scenario: there is a local keyfile
Given that there is a local keyfile
When the user pairs with BitPay with a valid pairing code
And tokens will be saved locally

Scenario: there is no local keyfile
Given that there is no local keyfile
When the user pairs with BitPay with a valid pairing code
Then the keyfile will be saved locally
And tokens will be saved locally

Scenario: the client has a bad pairing code
Given the user fails to pair with a semantically valid code "a1b2c3d"
Then they will receive a BitPay::BitPayError matching "500: Unable to create token"

Scenario: the client has an incorrect pairing code
Given the user fails to pair with a semantically invalid code "a2b2c3d4"
Then they will receive a BitPay::ArgumentError matching "pairing code is not legal"

Scenario: the client has a bad port configuration to a closed port
Given that there is a local keyfile
When the fails to pair with BitPay because of an incorrect port
Then they will receive a BitPay::ConnectionError matching "Connection refused"

0 comments on commit 451e362

Please sign in to comment.