Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
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 &
32 changes: 32 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# behat.yml

default:
context:
parameters:
user:
password:
base_url:
driver: 'selenium2'
paths:
features: tests/integrations
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~

phantomjs:
context:
parameters:
user:
password:
base_url:
driver: 'phantomjs'
paths:
features: tests/integrations
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2:
wd_host: "http://localhost:8643/wd/hub"
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
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.5.*@stable",
"behat/mink": "1.6.*-dev",
"behat/mink-extension": "1.3.*-dev",
"behat/mink-selenium2-driver": "1.2.*-dev",
"fabpot/goutte": "~1.0.4",
"behat/mink-goutte-driver": "1.*",
"phpmd/phpmd": "~2.1.3",
"phpunit/phpunit": "~4.3.1",
"fzaninotto/faker": "~1.4.0",
Expand Down
54 changes: 54 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,57 @@ please try to use phpmd. You can see the rules in ``build/rulesets/phpmd.xml``.
.. code-block:: bash

php bin/phpmd src/ text build/rulesets/phpmd.xml

Mink/Behat
=================

This will run tests verifying that the client is able to perform it's core functionality.

To run mink/behat integration tests, use the command:

.. code-block:: bash

source ./integration_tests.sh

URL, email, and password can be passed in as arguments to integration_tests.sh like so:

.. code-block::

source ./integration_tests.sh 'https://bobert.bp:8090' bobert@gmail.com 'abc123%^&@ac'

You can configure which instance of bitpay.com this will test with to by changing the url
in the behat.yml file. Make sure you replace username and password with the credentials
used to log into the bitpay site you are testing with.

You can also run specific tests from a command like so:

.. code-block:: bash

php bin/behat tests/integrations/invoice_create.feature

And you can run specific lines from these tests by:

.. code-block:: bash

php bin/behat tests/integrations/invoice_create.feature:20

.. note::

Tests run individually require you to set environment variables for your bitpay
credentials or they must be set in the behat.yml file.

Also keep in mind that rate limiters may hinder some tests and they need to be
reset every so often.

.. note::

pairing.feature's test "the client has a bad port configuration to an incorrect port"
requires ports that vary from computer to computer so you may need to manually change
these in order to avoid error.

A timing issue will occasionally occur saying:
"Notice: Undefined variable: response in
tests/integrations/bootstrap/FeatureContext.php line 368"
and there will be a message from BitPay saying:
"This endpoint does not support the `public` facade"
This is likely a timing issue and the tests will likely pass when run again.
17 changes: 0 additions & 17 deletions env.dist

This file was deleted.

89 changes: 89 additions & 0 deletions integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
set_variables ()
{
while true
do
read -p "Input Email: " EMAIL
regex="^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$";
if [[ "$EMAIL" =~ $regex ]]
then
export BITPAY_EMAIL=$EMAIL
break
else
echo "Please input a valid email"
fi
done
while true
do
read -p "Input Password: " PASSWORD
read -p "Password Confirmation: " PASSWORD2
if [ "$PASSWORD" = "$PASSWORD2" ]
then
break
else
echo "Please input a valid password"
fi
done
while true
do
read -p "Input URL: " URL
if [ -z $URL ]
then
echo "Please input a valid URL"
else
break
fi
done
}

if [ -z "$1" ]
then
echo "No parameters passed so using Environment Variables"
if [ -z "$BITPAY_EMAIL" ] || [ -z "$BITPAY_PASSWORD"]
then
echo "ERROR: No Email or password are set."
echo "set BITPAY_EMAIL and BITPAY_PASSWORD as environment variables"
echo "or pass them as arguments when running this script"
while true; do
read -p "Do you wish to set your environment variables here? " yn
case $yn in
[Yy]* ) set_variables; break;;
[Nn]* ) echo "Closing script"; exit;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "Environment Variables already exist for BITPAY."
fi
else
echo "Username $1 and Password $2 passed from command line"
URL=$1
EMAIL=$2
PASSWORD=$3
echo "Setting user and Password to new environment variables..."

fi

export BITPAY_EMAIL=$EMAIL
export BITPAY_PASSWORD=$PASSWORD
export BITPAY_URL=$URL
echo "Using Email: $EMAIL"
echo "Using URL: $URL"

echo "Removing old keys..."
if [ -e /tmp/bitpay.pub ]
then
rm -rf /tmp/bitpay.pub
rm -rf /tmp/bitpay.pri
rm -rf /tmp/token.json
fi

echo "Checking if Selenium exists..."
if [ ! -f selenium-server-standalone-2.44.0.jar ]
then
echo "Downloading Selenium"
curl -O http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar
fi

echo "Running Selenium and the tests"
php bin/behat tests/integrations
2 changes: 1 addition & 1 deletion src/Bitpay/Client/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function sendRequest(RequestInterface $request)
if (false === $raw) {
$errorMessage = curl_error($curl);
curl_close($curl);
throw new \Exception($errorMessage);
throw new \Bitpay\Client\ConnectionException($errorMessage);
}

/** @var ResponseInterface */
Expand Down
8 changes: 8 additions & 0 deletions src/Bitpay/Client/ArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bitpay\Client;

class ArgumentException extends \Exception
{

}
8 changes: 8 additions & 0 deletions src/Bitpay/Client/BitpayException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bitpay\Client;

class BitpayException extends \Exception
{

}
10 changes: 8 additions & 2 deletions src/Bitpay/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ public function getTokens()
*/
public function createToken(array $payload = array())
{
if ($payload !== array()) {
if (1 !== preg_match('/^[a-zA-Z0-9]{7}$/', $payload['pairingCode'])) {
throw new ArgumentException("pairing code is not legal");
}
}

$this->request = $this->createNewRequest();
$this->request->setMethod(Request::METHOD_POST);
$this->request->setPath('tokens');
Expand All @@ -478,7 +484,7 @@ public function createToken(array $payload = array())
$body = json_decode($this->response->getBody(), true);

if (isset($body['error'])) {
throw new \Exception($body['error']);
throw new \Bitpay\Client\BitpayException($this->response->getStatusCode().": ".$body['error']);
}

$tkn = $body['data'][0];
Expand Down Expand Up @@ -590,7 +596,7 @@ protected function addSignatureHeader(RequestInterface $request)
throw new \Exception('Please set your Private Key');
}

if (isset($this->network->isPortRequiredInUrl)) {
if (true == property_exists($this->network, 'isPortRequiredInUrl')) {
if ($this->network->isPortRequiredInUrl === true) {
$url = $request->getUriWithPort();
}
Expand Down
8 changes: 8 additions & 0 deletions src/Bitpay/Client/ConnectionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bitpay\Client;

class ConnectionException extends \Exception
{

}
4 changes: 3 additions & 1 deletion src/Bitpay/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Bitpay;

use Bitpay\Client;

/**
* For the most part this should conform to ISO 4217
*
Expand Down Expand Up @@ -114,7 +116,7 @@ public function getCode()
public function setCode($code)
{
if (null !== $code && !in_array(strtoupper($code), self::$availableCurrencies)) {
throw new \Exception(
throw new \Bitpay\Client\ArgumentException(
sprintf('The currency code "%s" is not supported.', $code)
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Bitpay/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Bitpay;

use Bitpay\Client;

/**
*
* @package Bitpay
Expand Down Expand Up @@ -99,6 +101,9 @@ public function getPrice()
*/
public function setPrice($price)
{
if (1 !== preg_match('/^[0-9]+(?:\.[0-9]{1,2})?$/', $price)) {
throw new \Bitpay\Client\ArgumentException("Price must be formatted as a float");
}
$this->price = $price;

return $this;
Expand Down
5 changes: 1 addition & 4 deletions tests/Bitpay/Client/Adapter/CurlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function testGetCurlOptions()

public function testSendRequestWithException()
{
$http = $this->getMock('HttpRequest');
$this->setExpectedException('Exception');
$this->setExpectedException('Bitpay\Client\ConnectionException');

$curl_options = array(
CURLOPT_URL => "www.example.com",
Expand All @@ -46,8 +45,6 @@ public function testSendRequestWithException()

public function testSendRequestWithoutException()
{
$http = $this->getMock('HttpRequest');

$curl_options = array(
CURLOPT_URL => "www.bitpay.com",
CURLOPT_SSL_VERIFYPEER => 1,
Expand Down
Loading