diff --git a/.gitignore b/.gitignore
index e34fd50..0bf1af7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
/build/dist/
/build/logs/
/docs/_build/
+/node_modules/
/vendor/
/.settings/
.project
diff --git a/.travis.yml b/.travis.yml
index 20bd5cf..d18e25d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..6e0868e
--- /dev/null
+++ b/Makefile
@@ -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 &
diff --git a/build/phpunit.xml.dist b/build/phpunit.xml.dist
index 66b3dbf..5c12fd1 100644
--- a/build/phpunit.xml.dist
+++ b/build/phpunit.xml.dist
@@ -9,8 +9,11 @@
bootstrap="../vendor/autoload.php"
colors="true">
-
- ../tests
+
+ ../tests/Bitpay
+
+
+ ../tests/integrations
diff --git a/composer.json b/composer.json
index 50d80c9..858a259 100644
--- a/composer.json
+++ b/composer.json
@@ -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",
diff --git a/docs/testing.rst b/docs/testing.rst
index 7605628..62d860f 100644
--- a/docs/testing.rst
+++ b/docs/testing.rst
@@ -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
===============
diff --git a/env.dist b/env.dist
new file mode 100644
index 0000000..146abb9
--- /dev/null
+++ b/env.dist
@@ -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=''
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..6b8f15b
--- /dev/null
+++ b/package.json
@@ -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"
+ }
+}
diff --git a/src/Bitpay/Client/Adapter/CurlAdapter.php b/src/Bitpay/Client/Adapter/CurlAdapter.php
index aa10db2..1d4f3e9 100644
--- a/src/Bitpay/Client/Adapter/CurlAdapter.php
+++ b/src/Bitpay/Client/Adapter/CurlAdapter.php
@@ -15,7 +15,6 @@ use Bitpay\Client\Response;
*
* @TODO add way to configure curl with options
*
- * @codeCoverageIgnore
* @package Bitpay
*/
class CurlAdapter implements AdapterInterface
diff --git a/tests/Bitpay/Client/ClientTest.php b/tests/Bitpay/Client/ClientTest.php
index c8e2b20..d66eee8 100644
--- a/tests/Bitpay/Client/ClientTest.php
+++ b/tests/Bitpay/Client/ClientTest.php
@@ -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();
diff --git a/tests/integrations/CreatePairingCodeTest.php b/tests/integrations/CreatePairingCodeTest.php
new file mode 100644
index 0000000..37af29b
--- /dev/null
+++ b/tests/integrations/CreatePairingCodeTest.php
@@ -0,0 +1,131 @@
+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
+ *
+ * $client->setToken($token);
+ *
+ */
+ $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,
+ );
+ }
+}
diff --git a/tests/integrations/LoginTest.php b/tests/integrations/LoginTest.php
new file mode 100644
index 0000000..81a5687
--- /dev/null
+++ b/tests/integrations/LoginTest.php
@@ -0,0 +1,53 @@
+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');
+ }
+}