Tests now can be applied to any server
This commit is contained in:
parent
3dea8bc41f
commit
6aabbf2b57
@ -5,7 +5,7 @@ default:
|
||||
parameters:
|
||||
user:
|
||||
password:
|
||||
base_url: 'https://test.bitpay.com'
|
||||
base_url:
|
||||
driver: 'selenium2'
|
||||
paths:
|
||||
features: tests/integrations
|
||||
@ -20,7 +20,7 @@ phantomjs:
|
||||
parameters:
|
||||
user:
|
||||
password:
|
||||
base_url: 'https://test.bitpay.com'
|
||||
base_url:
|
||||
driver: 'phantomjs'
|
||||
paths:
|
||||
features: tests/integrations
|
||||
|
||||
@ -100,7 +100,12 @@ This will run tests verifying that the client is able to perform it's core funct
|
||||
To run mink/behat integration tests, use the command:
|
||||
.. code-block:: bash
|
||||
|
||||
sh ./integration_tests user_name 'password'
|
||||
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
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
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"
|
||||
exit 1
|
||||
else
|
||||
EMAIL=$BITPAY_EMAIL
|
||||
PASSWORD=$BITPAY_PASSWORD
|
||||
fi
|
||||
else
|
||||
echo "Username $1 and Password $2 passed from command line"
|
||||
EMAIL=$1
|
||||
PASSWORD=$2
|
||||
echo "Setting user and Password to new environment variables..."
|
||||
export BITPAY_EMAIL=$EMAIL
|
||||
export BITPAY_PASSWORD=$PASSWORD
|
||||
fi
|
||||
|
||||
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"
|
||||
java -jar selenium-server-standalone-2.44.0.jar & php bin/behat tests/integrations
|
||||
89
integration_tests.sh
Executable file
89
integration_tests.sh
Executable file
@ -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
|
||||
@ -596,7 +596,7 @@ class Client implements ClientInterface
|
||||
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();
|
||||
}
|
||||
|
||||
@ -29,12 +29,20 @@ class FeatureContext extends BehatContext
|
||||
|
||||
public $reponse;
|
||||
|
||||
protected $InvoiceId;
|
||||
protected $invoiceId;
|
||||
|
||||
protected $user;
|
||||
|
||||
protected $password;
|
||||
|
||||
protected $base_url;
|
||||
|
||||
protected $port;
|
||||
|
||||
protected $port_required_in_url;
|
||||
|
||||
protected $network;
|
||||
|
||||
/**
|
||||
* Initializes context.
|
||||
* Every scenario gets it's own context object.
|
||||
@ -45,22 +53,49 @@ class FeatureContext extends BehatContext
|
||||
{
|
||||
$this->params = $parameters;
|
||||
|
||||
if (null == getenv('BITPAY_EMAIL')){
|
||||
if (null == getenv('BITPAY_EMAIL')) {
|
||||
$this->email = $this->params['user'];
|
||||
} else {
|
||||
$this->email = getenv('BITPAY_EMAIL');
|
||||
}
|
||||
if (null == getenv('BITPAY_PASSWORD')){
|
||||
if (null == getenv('BITPAY_PASSWORD')) {
|
||||
$this->password = $this->params['password'];
|
||||
} else {
|
||||
$this->password = getenv('BITPAY_PASSWORD');
|
||||
}
|
||||
|
||||
if (null == getenv('BITPAY_URL')) {
|
||||
$this->base_url = $this->params['base_url'];
|
||||
} else {
|
||||
$this->base_url = getenv('BITPAY_URL');
|
||||
}
|
||||
|
||||
$port = parse_url($this->base_url, PHP_URL_PORT);
|
||||
if (true == is_null(parse_url($this->base_url, PHP_URL_PORT))) {
|
||||
$this->port = 443;
|
||||
$this->port_required_in_url = false;
|
||||
} else {
|
||||
$this->port = parse_url($this->base_url, PHP_URL_PORT);
|
||||
$this->port_required_in_url = true;
|
||||
}
|
||||
|
||||
if (parse_url($this->base_url, PHP_URL_HOST) == 'test.bitpay.com') {
|
||||
$this->network = new \Bitpay\Network\Testnet();
|
||||
} else {
|
||||
$url = parse_url($this->base_url, PHP_URL_HOST);
|
||||
$this->network = new \Bitpay\Network\Customnet($url, $this->port, $this->port_required_in_url);
|
||||
}
|
||||
|
||||
if ((null == $this->email) || (null == $this->password)) {
|
||||
throw new Exception("Your email or password are not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (null == $this->base_url) {
|
||||
throw new Exception("Your url is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
$phantomjsDriver = new \Behat\Mink\Driver\Selenium2Driver('phantomJS', null, 'http://127.0.0.1:8643');
|
||||
$selenium2Driver = new \Behat\Mink\Driver\Selenium2Driver('firefox');
|
||||
|
||||
@ -104,7 +139,8 @@ class FeatureContext extends BehatContext
|
||||
// Load keys
|
||||
list($privateKey, $publicKey, $token_id) = loadKeys();
|
||||
|
||||
$client = createClient($privateKey, $publicKey);
|
||||
$network = $this->network;
|
||||
$client = createClient($network, $privateKey, $publicKey);
|
||||
|
||||
$token = new \Bitpay\Token();
|
||||
$token->setToken($token_id);
|
||||
@ -120,12 +156,11 @@ class FeatureContext extends BehatContext
|
||||
$invoice->setItem($item);
|
||||
|
||||
$invoice->setCurrency(new \Bitpay\Currency($currency));
|
||||
|
||||
$client->createInvoice($invoice);
|
||||
$this->response = $client->getResponse();
|
||||
$body = $this->response->getBody();
|
||||
$json = json_decode($body, true);
|
||||
$this->InvoiceId = $json['data']['id'];
|
||||
$this->invoiceId = $json['data']['id'];
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e;
|
||||
} finally {
|
||||
@ -156,7 +191,8 @@ class FeatureContext extends BehatContext
|
||||
public function theUserPairsWithBitpayWithAValidPairingCode()
|
||||
{
|
||||
// Login
|
||||
$this->mink->getSession()->visit($this->params['base_url'].'/merchant-login');
|
||||
|
||||
$this->mink->getSession()->visit($this->base_url.'/merchant-login');
|
||||
|
||||
$this->mink->getSession()->wait(1500);
|
||||
$this->mink->getSession()->getPage()->fillField('email', $this->email);
|
||||
@ -203,7 +239,8 @@ class FeatureContext extends BehatContext
|
||||
list($privateKey, $publicKey, $sinKey) = generateAndPersistKeys();
|
||||
|
||||
//Set Client
|
||||
$client = createClient($privateKey, $publicKey);
|
||||
$network = $this->network;
|
||||
$client = createClient($network, $privateKey, $publicKey);
|
||||
|
||||
$pairingCode = $this->validPairingCode;
|
||||
|
||||
@ -242,7 +279,8 @@ class FeatureContext extends BehatContext
|
||||
list($privateKey, $publicKey, $sinKey) = generateAndPersistKeys();
|
||||
|
||||
//Set Client
|
||||
$client = createClient($privateKey, $publicKey);
|
||||
$network = $this->network;
|
||||
$client = createClient($network, $privateKey, $publicKey);
|
||||
|
||||
// Pair
|
||||
$token = $client->createToken(
|
||||
@ -286,13 +324,14 @@ class FeatureContext extends BehatContext
|
||||
list($privateKey, $publicKey, $sinKey) = generateAndPersistKeys();
|
||||
|
||||
//Set Client
|
||||
$network = new \Bitpay\Network\Customnet("alex.bp", 8974, true);
|
||||
$url = parse_url($this->base_url, PHP_URL_HOST);
|
||||
$network = new \Bitpay\Network\Customnet($url, 8974234, true);
|
||||
$curl_options = array(
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_TIMEOUT => 1,
|
||||
);
|
||||
$client = createClient($privateKey, $publicKey, $network, $curl_options);
|
||||
$client = createClient($network, $privateKey, $publicKey, $curl_options);
|
||||
|
||||
// Pair
|
||||
$token = $client->createToken(
|
||||
@ -329,13 +368,14 @@ class FeatureContext extends BehatContext
|
||||
{
|
||||
try
|
||||
{
|
||||
$client = createClient();
|
||||
$response = $client->getInvoice($this->InvoiceId);
|
||||
$network = $this->network;
|
||||
$client = createClient($network);
|
||||
$response = $client->getInvoice($this->invoiceId);
|
||||
} catch (Exception $e){
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
$responseInvoiceId = $response->getId();
|
||||
if($responseInvoiceId !== $this->InvoiceId){
|
||||
if($responseInvoiceId !== $this->invoiceId){
|
||||
throw new Exception("Invoice ids don't match");
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,11 +29,8 @@ function loadKeys()
|
||||
return array($privateKey, $publicKey, $token_id);
|
||||
}
|
||||
|
||||
function createClient($privateKey = null, $publicKey = null, $network = null, $curl_options = null)
|
||||
function createClient($network, $privateKey = null, $publicKey = null, $curl_options = null)
|
||||
{
|
||||
if(true === is_null($network)) {
|
||||
$network = new \Bitpay\Network\Customnet("alex.bp", 8088, true);
|
||||
}
|
||||
if(true === is_null($curl_options)) {
|
||||
$curl_options = array(
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user