Added files for integration testing
This commit is contained in:
parent
3e10d10290
commit
6459deaeda
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
/build/dist/
|
||||
/build/logs/
|
||||
/docs/_build/
|
||||
/node_modules/
|
||||
/vendor/
|
||||
/.settings/
|
||||
.project
|
||||
|
||||
@ -6,7 +6,12 @@ php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
|
||||
install: composer install
|
||||
install:
|
||||
- composer install
|
||||
- npm install
|
||||
|
||||
before_script:
|
||||
- make phantomjs
|
||||
|
||||
script:
|
||||
- php bin/phpunit -c build/
|
||||
|
||||
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
setup:
|
||||
composer.phar install
|
||||
npm install
|
||||
|
||||
test:
|
||||
php ./bin/phpunit -c build/
|
||||
|
||||
phantomjs:
|
||||
./node_modules/.bin/phantomjs --webdriver=4444 --ssl-protocol=TLSv1 --ignore-ssl-errors=yes &
|
||||
@ -9,8 +9,11 @@
|
||||
bootstrap="../vendor/autoload.php"
|
||||
colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Bitpay Package">
|
||||
<directory>../tests</directory>
|
||||
<testsuite name="unit">
|
||||
<directory>../tests/Bitpay</directory>
|
||||
</testsuite>
|
||||
<testsuite name="integration">
|
||||
<directory>../tests/integrations</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
|
||||
@ -34,11 +34,13 @@
|
||||
"ext-json": "*",
|
||||
"ext-openssl": "*",
|
||||
"ext-mcrypt": "*",
|
||||
"bitpay/php-client": "~2.0@dev",
|
||||
"symfony/config": "~2.3",
|
||||
"symfony/dependency-injection": "~2.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"behat/mink": "1.6.*@stable",
|
||||
"behat/mink-selenium2-driver": "~1.1",
|
||||
"behat/mink-zombie-driver": "~1.2",
|
||||
"phpmd/phpmd": "~2.1.3",
|
||||
"phpunit/phpunit": "~4.3.1",
|
||||
"fzaninotto/faker": "~1.4.0",
|
||||
|
||||
@ -14,12 +14,19 @@ install the required development dependencies.
|
||||
.. code-block:: bash
|
||||
|
||||
composer.phar install
|
||||
npm install
|
||||
|
||||
.. note::
|
||||
|
||||
By default Composer will install the development packages. You should
|
||||
not need to run ``install`` or ``update``.
|
||||
|
||||
.. note::
|
||||
|
||||
node is used for PhantomJS and a few other tools that help out with the
|
||||
required testing to make sure that the code is able to talk to BitPay servers
|
||||
and should give us an early warning if things update or change without notice.
|
||||
|
||||
PHPUnit
|
||||
=======
|
||||
|
||||
@ -41,6 +48,18 @@ You can also run phpunit on just one file, for example:
|
||||
Running tests on just one file can be helpful since you are not running the
|
||||
entire test suite.
|
||||
|
||||
.. note::
|
||||
|
||||
You can run `unit` tests or `integration` tests by providing the testsuite
|
||||
command line option like so:
|
||||
|
||||
php bin/phpunit -c build/ --testsuite unit
|
||||
php bin/phpunit -c build/ --testsuite integration
|
||||
|
||||
Also, please be aware that to have integration tests work, you will need to
|
||||
have PhantomJS running, see `Makefile` for getting it setup or just run
|
||||
`make phantomjs` in a terminal window.
|
||||
|
||||
PHP_CodeSniffer
|
||||
===============
|
||||
|
||||
|
||||
17
env.dist
Normal file
17
env.dist
Normal file
@ -0,0 +1,17 @@
|
||||
####
|
||||
#
|
||||
# This file is for integration testing. You MUST have these environment variables
|
||||
# set or all integration tests will be skipped.
|
||||
#
|
||||
# To setup, you will need to export this variables like so:
|
||||
#
|
||||
# export BITPAY_EMAIL='josh@bitpay.com'
|
||||
# export BITPAY_PASSWORD='FluffyKitty420'
|
||||
#
|
||||
# NOTE: Running this on the command line has the potential for them to show up
|
||||
# in your history. Please make sure you do this one a secure system.
|
||||
#
|
||||
####
|
||||
|
||||
BITPAY_EMAIL=''
|
||||
BITPAY_PASSWORD=''
|
||||
35
package.json
Normal file
35
package.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "php-bitpay-client",
|
||||
"description": "PHP Client Library",
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"doc": "docs",
|
||||
"example": "examples",
|
||||
"test": "tests"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bitpay/php-bitpay-client.git"
|
||||
},
|
||||
"keywords": [
|
||||
"bitpay",
|
||||
"bitcoin",
|
||||
"php"
|
||||
],
|
||||
"author": "BitPay Inc Ecommerce Development Team",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/bitpay/php-bitpay-client/issues"
|
||||
},
|
||||
"homepage": "https://github.com/bitpay/php-bitpay-client",
|
||||
"engines": {
|
||||
"node": ">=0.10.33",
|
||||
"npm": "~2.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"phantomjs": "^1.9.12"
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,6 @@ use Bitpay\Client\Response;
|
||||
*
|
||||
* @TODO add way to configure curl with options
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package Bitpay
|
||||
*/
|
||||
class CurlAdapter implements AdapterInterface
|
||||
|
||||
@ -231,50 +231,15 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$invoice = $this->getMockBuilder('Bitpay\InvoiceInterface')
|
||||
->setMethods(
|
||||
array(
|
||||
'getPrice',
|
||||
'getCurrency',
|
||||
'getItem',
|
||||
'getBuyer',
|
||||
'getTransactionSpeed',
|
||||
'getNotificationEmail',
|
||||
'getNotificationUrl',
|
||||
'getRedirectUrl',
|
||||
'getPosData',
|
||||
'getStatus',
|
||||
'isFullNotifications',
|
||||
'getId',
|
||||
'getUrl',
|
||||
'getBtcPrice',
|
||||
'getInvoiceTime',
|
||||
'getExpirationTime',
|
||||
'getCurrentTime',
|
||||
'getOrderId',
|
||||
'getItemDesc',
|
||||
'getItemCode',
|
||||
'isPhysical',
|
||||
'getBuyerName',
|
||||
'getBuyerAddress1',
|
||||
'getBuyerAddress2',
|
||||
'getBuyerCity',
|
||||
'getBuyerState',
|
||||
'getBuyerZip',
|
||||
'getBuyerCountry',
|
||||
'getBuyerEmail',
|
||||
'getBuyerPhone',
|
||||
'getExceptionStatus',
|
||||
'getBtcPaid',
|
||||
'getRate',
|
||||
'setId',
|
||||
'setUrl',
|
||||
'setStatus',
|
||||
'setBtcPrice',
|
||||
'setPrice',
|
||||
'setInvoiceTime',
|
||||
'setExpirationTime',
|
||||
'setCurrentTime',
|
||||
'setBtcPaid',
|
||||
'setRate',
|
||||
'setExceptionStatus',
|
||||
'getPrice', 'getCurrency', 'getItem', 'getBuyer', 'getTransactionSpeed',
|
||||
'getNotificationEmail', 'getNotificationUrl', 'getRedirectUrl', 'getPosData', 'getStatus',
|
||||
'isFullNotifications', 'getId', 'getUrl', 'getBtcPrice', 'getInvoiceTime',
|
||||
'getExpirationTime', 'getCurrentTime', 'getOrderId', 'getItemDesc', 'getItemCode',
|
||||
'isPhysical', 'getBuyerName', 'getBuyerAddress1', 'getBuyerAddress2', 'getBuyerCity',
|
||||
'getBuyerState', 'getBuyerZip', 'getBuyerCountry', 'getBuyerEmail', 'getBuyerPhone',
|
||||
'getExceptionStatus', 'getBtcPaid', 'getRate', 'setId', 'setUrl',
|
||||
'setStatus', 'setBtcPrice', 'setPrice', 'setInvoiceTime', 'setExpirationTime',
|
||||
'setCurrentTime', 'setBtcPaid', 'setRate', 'setExceptionStatus',
|
||||
)
|
||||
)
|
||||
->getMock();
|
||||
|
||||
131
tests/integrations/CreatePairingCodeTest.php
Normal file
131
tests/integrations/CreatePairingCodeTest.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* @license Copyright 2011-2014 BitPay Inc., MIT License
|
||||
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Integration;
|
||||
|
||||
use Behat\Mink\Mink;
|
||||
use Behat\Mink\Session;
|
||||
use Behat\Mink\Driver\Selenium2Driver;
|
||||
|
||||
/**
|
||||
* Test to make sure that pairing codes can be created
|
||||
*/
|
||||
class CreatePairingCodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$isEmailConfigured = getenv('BITPAY_EMAIL');
|
||||
$isPasswordConfigured = getenv('BITPAY_PASSWORD');
|
||||
|
||||
if (!$isEmailConfigured || !$isPasswordConfigured) {
|
||||
$this->markTestSkipped('Environment Variables need to be set.');
|
||||
return;
|
||||
}
|
||||
|
||||
$selenium2driver = new Selenium2Driver('firefox', null, 'http://127.0.0.1:4444');
|
||||
$this->mink = new Mink(
|
||||
array(
|
||||
'selenium2' => new Session($selenium2driver),
|
||||
)
|
||||
);
|
||||
$this->mink->setDefaultSessionName('selenium2');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->mink->getSession()->reset();
|
||||
}
|
||||
|
||||
public function testPairingCode()
|
||||
{
|
||||
/**
|
||||
* Login and create a pairing code
|
||||
*/
|
||||
$this->login();
|
||||
$pairingCode = $this->createPairingCode();
|
||||
|
||||
/**
|
||||
* Generate some new keys
|
||||
*/
|
||||
list($pri, $pub, $sin) = $this->generateKeys();
|
||||
|
||||
/**
|
||||
* Make request to to pair keys and obtain a token
|
||||
*/
|
||||
$this->client = new \Bitpay\Client\Client();
|
||||
$this->client->setNetwork(new \Bitpay\Network\Testnet());
|
||||
$this->client->setPublicKey($pub);
|
||||
$this->client->setPrivateKey($pri);
|
||||
$this->client->setAdapter(new \Bitpay\Client\Adapter\CurlAdapter());
|
||||
$token = $this->client->createToken(
|
||||
array(
|
||||
'id' => (string) $sin,
|
||||
'pairingCode' => $pairingCode,
|
||||
'label' => 'Integration Test',
|
||||
)
|
||||
);
|
||||
/**
|
||||
* The token is the what will be needed for all requests in the future
|
||||
* and so to inject it into the client, you would add the code
|
||||
* <code>
|
||||
* $client->setToken($token);
|
||||
* </code>
|
||||
*/
|
||||
$this->assertInstanceOf('Bitpay\TokenInterface', $token);
|
||||
}
|
||||
|
||||
private function login()
|
||||
{
|
||||
$this->mink->getSession()->visit('https://test.bitpay.com/merchant-login');
|
||||
$this->mink->getSession()->wait(2500);
|
||||
$this->mink->getSession()->getPage()->fillField('email', getenv('BITPAY_EMAIL'));
|
||||
$this->mink->getSession()->getPage()->fillField('password', getenv('BITPAY_PASSWORD'));
|
||||
$this->mink->getSession()->getPage()->findById('loginForm')->submit();
|
||||
$this->mink->getSession()->wait(2500);
|
||||
$assert = $this->mink->assertSession();
|
||||
$assert->pageTextContains('Dashboard');
|
||||
}
|
||||
|
||||
private function createPairingCode()
|
||||
{
|
||||
$this->mink->getSession()->visit('https://test.bitpay.com/api-tokens');
|
||||
$session = $this->mink->getSession();
|
||||
$page = $session->getPage();
|
||||
// Click the `Add New Token` button
|
||||
$page->find('xpath', '//*[@id="apiTokensList"]/div/div[3]/div[2]/div')->click();
|
||||
$this->mink->getSession()->wait(500);
|
||||
$assert = $this->mink->assertSession();
|
||||
$assert->pageTextContains('Add Token');
|
||||
// Click `Add Token` button
|
||||
$page->find('xpath', '//*[@id="token-new-form"]/button')->click();
|
||||
$this->mink->getSession()->wait(2500);
|
||||
$pairingCode = $page->find('xpath', '//*[@id="my-token-access-wrapper"]/div[1]/div[2]/div/div')->getText();
|
||||
$this->assertNotNull($pairingCode);
|
||||
|
||||
return $pairingCode;
|
||||
}
|
||||
|
||||
private function generateKeys()
|
||||
{
|
||||
$privateKey = new \Bitpay\PrivateKey();
|
||||
$privateKey->generate();
|
||||
$publicKey = new \Bitpay\PublicKey();
|
||||
$publicKey
|
||||
->setPrivateKey($privateKey)
|
||||
->generate();
|
||||
$sin = new \Bitpay\SinKey();
|
||||
$sin
|
||||
->setPublicKey($publicKey)
|
||||
->generate();
|
||||
|
||||
return array(
|
||||
$privateKey,
|
||||
$publicKey,
|
||||
$sin,
|
||||
);
|
||||
}
|
||||
}
|
||||
53
tests/integrations/LoginTest.php
Normal file
53
tests/integrations/LoginTest.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @license Copyright 2011-2014 BitPay Inc., MIT License
|
||||
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Integration;
|
||||
|
||||
use Behat\Mink\Mink;
|
||||
use Behat\Mink\Session;
|
||||
use Behat\Mink\Driver\Selenium2Driver;
|
||||
|
||||
/**
|
||||
* Test to make sure that login page is working
|
||||
*/
|
||||
class LoginTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$isEmailConfigured = getenv('BITPAY_EMAIL');
|
||||
$isPasswordConfigured = getenv('BITPAY_PASSWORD');
|
||||
|
||||
if (!$isEmailConfigured || !$isPasswordConfigured) {
|
||||
$this->markTestSkipped('Environment Variables need to be set.');
|
||||
return;
|
||||
}
|
||||
|
||||
$selenium2driver = new Selenium2Driver('firefox', null, 'http://127.0.0.1:4444');
|
||||
$this->mink = new Mink(
|
||||
array(
|
||||
'selenium2' => new Session($selenium2driver),
|
||||
)
|
||||
);
|
||||
$this->mink->setDefaultSessionName('selenium2');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->mink->getSession()->reset();
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$this->mink->getSession()->visit('https://test.bitpay.com/merchant-login');
|
||||
$this->mink->getSession()->getPage()->fillField('email', getenv('BITPAY_EMAIL'));
|
||||
$this->mink->getSession()->getPage()->fillField('password', getenv('BITPAY_PASSWORD'));
|
||||
$this->mink->getSession()->getPage()->findById('loginForm')->submit();
|
||||
$this->mink->getSession()->wait(2500); // wait 2.5 seconds for page to load
|
||||
$assert = $this->mink->assertSession();
|
||||
$assert->pageTextContains('Dashboard');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user