Repository: nbobtc/bitcoind-php
Branch: 2.x
Commit: 6985d44d5c9a
Files: 27
Total size: 36.0 KB
Directory structure:
gitextract_6fwc20wd/
├── .gitattributes
├── .gitignore
├── .travis.yml
├── Berksfile
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── Vagrantfile
├── composer.json
├── docs/
│ └── .gitkeep
├── phpdoc.dist.xml
├── phpunit.xml.dist
├── src/
│ ├── Command/
│ │ ├── Command.php
│ │ └── CommandInterface.php
│ └── Http/
│ ├── Client.php
│ ├── ClientInterface.php
│ ├── Driver/
│ │ ├── CurlDriver.php
│ │ └── DriverInterface.php
│ └── Message/
│ ├── Message.php
│ ├── Request.php
│ ├── Response.php
│ ├── Streamable.php
│ └── Uri.php
└── tests/
├── Command/
│ └── CommandTest.php
└── Http/
├── ClientTest.php
└── Driver/
└── CurlDriverTest.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
test/ export-ignore
phpunit.xml.dist export-ignore
================================================
FILE: .gitignore
================================================
bin/
build/logs/
docs/api/
docs/code-coverage/
vendor/
composer.lock
phpdoc.xml
================================================
FILE: .travis.yml
================================================
language: php
php:
- 7
- 5.6
- 5.5
- 5.4
branches:
only:
- 1.x
- 2.x
- master
notifications:
email: false
irc: "chat.freenode.net#dspacelabs"
install:
- composer require "codeclimate/php-test-reporter:*" -n
- composer install
script:
- php bin/phpunit
after_script:
- bin/test-reporter --stdout > codeclimate.json
- "curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports"
================================================
FILE: Berksfile
================================================
source "https://supermarket.chef.io"
cookbook "bitcoind"
================================================
FILE: CHANGELOG.md
================================================
Change log
==========
## [Unreleased]
### Added
### Updated
### Fixed
### Changed
## [2.1.0] - 2017-12-22
### Added
- travis notifies irc channel #dspacelabs
### Updated
- [#18] Avoid reliance on own PSR-7 implementation
- [#29] Added Test Case for CurlDriver
## [2.0.2] - 2015-05-27
### Fixed
- [#16] incompatible with psr/http-message current version
## [2.0.1] - 2015-03-27
### Added
- Added Vagrant file to setup and configure nodes
### Fixed
- Small issue with the CurlDriver
## [2.0.0] - 2015-03-22
Initial release of 2.x
### Added
- Message
- Streamable
- Request
- Response
- Command
### Changed
- Complete Rewrite of Library
### Deprecated
- 1.x Releases
[unreleased]: https://github.com/nbobtc/bitcoind-php/compare/2.1.0...2.x
[2.1.0]: https://github.com/nbobtc/bitcoind-php/compare/2.0.2...2.1.0
[2.0.2]: https://github.com/nbobtc/bitcoind-php/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/nbobtc/bitcoind-php/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/nbobtc/bitcoind-php/compare/2d30e2f9ee617f44336581386cd0734613c7353d...2.0.0
[#16]: https://github.com/nbobtc/bitcoind-php/issues/16
[#18]: https://github.com/nbobtc/bitcoind-php/pull/18
[#29]: https://github.com/nbobtc/bitcoind-php/pull/29
================================================
FILE: CONTRIBUTING.md
================================================
Contributing Guidelines
=======================
This project uses some standards such as [PSR-1], [PSR-2], [PSR-3], and [PSR-4]
along with some standards that are being purposed.
## Getting Started
* Fork repository
* Pull requests should be on the develop branch.
* Code must conform to [PSR-1] and [PSR-2] standards.
## Finding Something to Work on
- Check out the [CodeClimate] issues page for this project.
- Check out the [GitHub Issues] page for this project.
- Check out [SensioLabs Insight] page for this project.
## Documentation
Feel free to add your own examples or usage to the documentation. If something
isn't clear, go head and submit a PR with your updated paragraph.
## Donate
Consider donating some [16yRSB46xMeWKfWtqcuqSVV7B2eSjkd92D]
[PSR-1]: http://www.php-fig.org/psr/psr-1/
[PSR-2]: http://www.php-fig.org/psr/psr-2/
[PSR-3]: http://www.php-fig.org/psr/psr-3/
[PSR-4]: http://www.php-fig.org/psr/psr-4/
[CodeClimate]: https://codeclimate.com/github/nbobtc/bitcoind-php/issues
[GitHub Issues]: https://github.com/nbobtc/bitcoind-php/issues
[SensioLabs Insight]: https://insight.sensiolabs.com/projects/c7af9182-f53b-4164-820d-46e7499252f3
[16yRSB46xMeWKfWtqcuqSVV7B2eSjkd92D]: bitcoin://16yRSB46xMeWKfWtqcuqSVV7B2eSjkd92D
================================================
FILE: LICENSE
================================================
Copyright (C) 2012-2015 Joshua Estes
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
nbobtc/bitcoind-php [](https://travis-ci.org/nbobtc/bitcoind-php) [](https://packagist.org/packages/nbobtc/bitcoind-php) [](https://packagist.org/packages/nbobtc/bitcoind-php)
===================
[](https://codeclimate.com/github/nbobtc/bitcoind-php) [](https://codeclimate.com/github/nbobtc/bitcoind-php) [](https://insight.sensiolabs.com/projects/c7af9182-f53b-4164-820d-46e7499252f3)
This project is used to interact with a headless bitcoin program called
bitcoind. It also contains various utility classes for working with Bitcoin as a
PHP Developer.
## Installation
You can install this library by using [Composer]. You can also view more info
about this on [Packagist].
```bash
composer require nbobtc/bitcoind-php
```
## Usage
To use the project you need to just create a new instance of the class.
```php
sendCommand($command);
/** @var string */
$contents = $response->getBody()->getContents();
echo $contents;
```
You are able to get the [Request] and [Response] objects back from
the client with the correct getters: `getRequest()` and `getResponse()`.
You can also parse the response however you wish to do so since the result is
returned to you as a string. See below for some ideas!
## Commands
Commands are created in such a way that this will support any future updates the
[Bitcoin API] by providing you with an easy class that sets all the required
information.
You are able to pass into the object the `method` and the `parameters` that are
required. Here are a few examples:
```php
// No Parameters
$command = new Command('getinfo');
// One Parameter
$command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');
// Multiple Parameters
$command = new Command('sendfrom', array('fromaccount', 'tobitcoinaddress', 'amount'));
```
The second argument MUST be in the same order as on the [Bitcoin API] wiki page.
There is no need to assign the values any keys.
### Parameters
Parameters are the second argument when creating a new Command. This argument
can either be a string OR an array. For example, both of these are valid.
```php
$command = new Command('getblock', array('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'));
$command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');
```
Most commands in the [Bitcoin API] take one parameter. If it takes MORE than
one, you must pass the parameters in as an array in the ORDER you find them on
that page.
### Extending Commands
If, for any reason, you need to extend a command, it MUST implement
[CommandInterface]. You can find documentation within the interface on how to
implement this.
## Drivers
Drivers are used by the ClientInterface for connecting to a bitcoind service and
sending Requests. The return a Response. If you need to implement a new driver
take a look at the [DriverInterface].
### cURL Driver
This is used by default and allows you a lot of options for customizing it to
your needs.
You can set various [cURL Options] by passing them into the function
`addCurlOption($option, $value)`.
Here's an example of how to configure and use the driver.
```php
$driver = new \Nbobtc\Http\Driver\CurlDriver();
$driver
->addCurlOption(CURLOPT_VERBOSE, true)
->addCurlOption(CURLOPT_STDERR, '/var/logs/curl.err');
$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
$client->withDriver($driver);
```
Feel free to take a look at the `CurlDriver` source code.
## Cookbook
### How to enable a Keep-Alive ie Persistent Connection
This example shows how you are able to set the client up to [Persistent
Connection].
```php
$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
$client->getRequest()->withHeader('Connection', 'Keep-Alive');
```
### How to set a CA Cert
This library provides some wonderful flexibility that will allow you to
configure the client to use your own CA Cert.
```php
$driver = new \Nbobtc\Http\Driver\CurlDriver();
$driver->addCurlOption(CURLOPT_CAINFO, '/path/to/cert');
$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
$client->withDriver($driver);
```
### How to Convert Output to an Array
Some like the arrays
```php
$response = $client->sendCommand($command);
$output = json_decode($response->getBody()->getContents(), true);
```
### How to Convert Output to a stdClass object
Some like the objects
```php
$response = $client->sendCommand($command);
$output = json_decode($response->getBody()->getContents());
```
## Testing
All testing is done using PHPUnit. You should be able to run `phpunit` in the
root directory of this project (the directory where phpunit.xml.dist is located)
and the tests will run.
If submitting a pull request or working on this library, please make sure that
the tests will pass.
## Change log
See [CHANGELOG.md].
Contains information on releases such as what was added, changed, etc. It's good
to look at to see what has changed from release to release.
## Contributing
See [CONTRIBUTING.md].
Various ways on contributing to this project.
## Branching
### master
This is the latest and greatest, it should not be used an is considered
development for testing new features and functionality. This should NOT be used
in a production environment.
### 2.x
Current production branch. All 2.x tags come off of this branch.
### 1.x
Deprecated, only used for bug fixes and for historical records.
## License (MIT) [](https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE)
Copyright (C) 2012-2018 Joshua Estes
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[Composer]: https://getcomposer.org/
[Packagist]: https://packagist.org/packages/nbobtc/bitcoind-php
[CHANGELOG.md]: https://github.com/nbobtc/bitcoind-php/blob/2.x/CHANGELOG.md
[CONTRIBUTING.md]: https://github.com/nbobtc/bitcoind-php/blob/2.x/CONTRIBUTING.md
[Bitcoin API]: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
[Persistent Connection]: http://en.wikipedia.org/wiki/HTTP_persistent_connection
[cURL Options]: http://php.net/manual/en/function.curl-setopt.php
[Releases]: https://github.com/nbobtc/bitcoind-php/releases
[CommandInterface]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Command/CommandInterface.php
[Request]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Http/Message/Request.php
[Response]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Http/Message/Response.php
[DriverInterface]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Http/Driver/DriverInterface.php
================================================
FILE: Vagrantfile
================================================
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.berkshelf.enabled = true
config.vm.box = "ubuntu/trusty64"
config.vm.define "node01" do |node01|
node01.vm.network "private_network", ip: "192.168.33.10"
node01.vm.network "forwarded_port", guest: 19332, host: 18332
node01.vm.provision "chef_solo" do |chef|
chef.add_recipe "bitcoind"
chef.json = {
"bitcoind" => {
"config" => {
"options" => {
"regtest" => 1,
"gen" => 1,
"dnsseed" => 0,
"unpnp" => 0,
"port" => 19000,
"server" => 1,
"rpcuser" => "username",
"rpcpassword" => "password",
"rpcallowip" => ["0.0.0.0/0"],
"rpcport" => 19332
}
}
}
}
end
end
config.vm.define "node02" do |node02|
node02.vm.network "private_network", ip: "192.168.33.20"
node02.vm.network "forwarded_port", guest: 19332, host: 18333
node02.vm.provision "chef_solo" do |chef|
chef.add_recipe "bitcoind"
chef.json = {
"bitcoind" => {
"config" => {
"options" => {
"regtest" => 1,
"dnsseed" => 0,
"unpnp" => 0,
"port" => 19000,
"server" => 1,
"listen" => 0,
"connect" => "192.168.33.10:19000",
"rpcuser" => "username",
"rpcpassword" => "password",
"rpcallowip" => ["0.0.0.0/0"],
"rpcport" => 19332
}
}
}
}
end
end
end
================================================
FILE: composer.json
================================================
{
"name": "nbobtc/bitcoind-php",
"homepage": "https://github.com/nbobtc/bitcoind-php",
"type": "library",
"description": "PHP Wrapper for a bitcoind daemon",
"keywords": ["bitcoin", "bitcoind", "bitcoins"],
"license": "MIT",
"authors": [
{
"name": "Joshua Estes"
}
],
"support": {
"issues": "https://github.com/nbobtc/bitcoind-php/issues",
"source": "https://github.com/nbobtc/bitcoind-php"
},
"autoload": {
"psr-4": { "Nbobtc\\": "src/" }
},
"autoload-dev": {
"psr-4": { "Tests\\Nbobtc\\": "tests/" }
},
"extra": {
"branch-alias": {
"1.x-dev": "1.3.x-dev",
"2.x-dev": "2.1.x-dev"
}
},
"require": {
"php": ">=5.4",
"ext-curl": "*",
"ext-json": "*",
"psr/log": "~1.0",
"psr/http-message": "~1.0",
"zendframework/zend-diactoros": "^1.3"
},
"require-dev": {
"phpunit/phpunit": "~4.5.0",
"mockery/mockery": "~0.9.0",
"fzaninotto/faker": "~1.4.0"
},
"config": {
"bin-dir": "bin"
},
"non-feature-branches": ["master"]
}
================================================
FILE: docs/.gitkeep
================================================
================================================
FILE: phpdoc.dist.xml
================================================
API Documentation
docs/api/
docs/api/
src/
build/logs/phpdoc.log
build/logs/phpdoc.err
================================================
FILE: phpunit.xml.dist
================================================
tests/
src/
================================================
FILE: src/Command/Command.php
================================================
withMethod($method);
}
if (null !== $parameters) {
$this->withParameters($parameters);
}
if (null !== $id) {
$this->withId($id);
}
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function getMethod()
{
return $this->method;
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function getParameters()
{
return $this->parameters;
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function withMethod($method)
{
$this->method = $method;
return $this;
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function withParameters($parameters)
{
if (is_array($parameters)) {
$this->parameters = $parameters;
} else {
$this->parameters = array($parameters);
}
return $this;
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function withId($id)
{
$this->id = $id;
return $this;
}
}
================================================
FILE: src/Command/CommandInterface.php
================================================
driver = new CurlDriver();
$this->request = (new Request($dsn))->withHeader('Content-Type', 'application/json');
}
/**
* @since 2.0.0
* {@inheritdoc}
*/
public function sendCommand(CommandInterface $command)
{
$body = new \Zend\Diactoros\Stream('php://temp', 'w+');
$body->write(json_encode(
array(
'method' => $command->getMethod(),
'params' => $command->getParameters(),
'id' => $command->getId(),
)
));
$request = $this->request->withBody($body);
/** @var \Psr\Http\Message\ResponseInterface */
$this->response = $this->driver->execute($request);
return $this->response;
}
/**
* Configures the Client to use a specific driver
*
* @since 2.0.0
* @param \Nbobtc\Http\Driver\DriverInterface $driver
* @return self
*/
public function withDriver(DriverInterface $driver)
{
$this->driver = $driver;
return $this;
}
/**
* Return the current Request object
*
* @since 2.0.0
* @return \Psr\Http\Message\RequestInterface
*/
public function getRequest()
{
return $this->request;
}
/**
* Returns the current Response object
*
* @since 2.0.0
* @return \Psr\Http\Message\ResponseInterface
*/
public function getResponse()
{
return $this->response;
}
}
================================================
FILE: src/Http/ClientInterface.php
================================================
getUri();
if (null === self::$ch || gettype(self::$ch) != 'curl') {
self::$ch = curl_init();
}
curl_setopt_array(self::$ch, $this->getDefaultCurlOptions());
curl_setopt(self::$ch, CURLOPT_URL, sprintf('%s://%s@%s', $uri->getScheme(), $uri->getUserInfo(), $uri->getHost()));
curl_setopt(self::$ch, CURLOPT_PORT, $uri->getPort());
$headers = array();
foreach ($request->getHeaders() as $header => $values) {
$headers[] = $header.': '.implode(', ', $values);
}
curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt(self::$ch, CURLOPT_POSTFIELDS, (string) $request->getBody());
// Allows user to override any option, may cause errors
curl_setopt_array(self::$ch, $this->curlOptions);
/** @var string|false */
$result = curl_exec(self::$ch);
/** @var array|false */
$info = curl_getinfo(self::$ch);
/** @var string */
$error = curl_error(self::$ch);
if (!empty($error)) {
throw new \Exception($error);
}
$response = new Response();
$response = $response->withStatus($info['http_code']);
$response->getBody()->write($result);
$response->getBody()->rewind(); // empty getContents() without rewind()
return $response;
}
/**
* Add options to use for cURL requests
*
* @since 2.0.0
* @param integer $option
* @param mixed $value
*/
public function addCurlOption($option, $value)
{
$this->curlOptions[$option] = $value;
return $this;
}
/**
* Returns an array of cURL options
*
* @since 2.0.0
* @return array
*/
protected function getDefaultCurlOptions()
{
return array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 10,
);
}
}
================================================
FILE: src/Http/Driver/DriverInterface.php
================================================
version;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function withProtocolVersion($version)
{
$this->version = (string) $version;
return $this;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function getHeaders()
{
return $this->headers;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function hasHeader($name)
{
foreach ($this->headers as $header => $values) {
if (0 === strcasecmp($header, $name)) {
return true;
}
}
return false;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function getHeader($name)
{
foreach ($this->headers as $header => $values) {
if (0 === strcasecmp($header, $name)) {
return $this->headers[$header];
}
}
return null;
}
/**
* @todo
* @since 2.0.2
* {@inheritDoc}
*/
public function getHeaderLine($name)
{
return '';
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function getHeaderLines($name)
{
if ($lines = $this->getHeader($name)) {
return $lines;
}
return array();
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function withHeader($name, $value)
{
if (is_array($value)) {
$this->headers[$name] = $value;
} else {
$this->headers[$name] = array($value);
}
return $this;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function withAddedHeader($name, $value)
{
$this->headers[$name] = $value;
return $this;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function withoutHeader($name)
{
foreach ($this->headers as $header => $values) {
if (0 === strcasecmp($header, $name)) {
unset($this->headers[$header]);
}
}
return $this;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function getBody()
{
if (null === $this->body) {
$this->body = new Streamable();
}
return $this->body;
}
/**
* @since 2.0.0
* {@inheritDoc}
*/
public function withBody(StreamInterface $body)
{
$this->body = $body;
return $this;
}
}
================================================
FILE: src/Http/Message/Request.php
================================================
assertEquals($method, $command->getMethod());
$this->assertEquals($parameters, $command->getParameters());
$this->assertEquals($id, $command->getId());
$command = new Command();
$this->assertNull($command->getMethod());
$this->assertEmpty($command->getParameters());
$this->assertNull($command->getId());
$this->assertInstanceOf('Nbobtc\Command\CommandInterface', $command->withMethod($method));
$this->assertEquals($method, $command->getMethod());
$this->assertInstanceOf('Nbobtc\Command\CommandInterface', $command->withParameters($parameters));
$this->assertEquals($parameters, $command->getParameters());
$this->assertInstanceOf('Nbobtc\Command\CommandInterface', $command->withId($id));
$this->assertEquals($id, $command->getId());
}
public function commandDataProvider()
{
return array(
array('getinfo', array('one'), 1),
);
}
public function testCommandWithParameters()
{
$command = new Command();
$this->assertEmpty($command->getParameters());
$command->withParameters('a');
$this->assertEquals(array('a'), $command->getParameters());
$command = new Command();
$this->assertEmpty($command->getParameters());
$command->withParameters(array('a'));
$this->assertEquals(array('a'), $command->getParameters());
}
}
================================================
FILE: tests/Http/ClientTest.php
================================================
assertNull($client->getResponse());
$request = $client->getRequest();
$this->assertInstanceOf('Psr\Http\Message\RequestInterface', $request);
$uri = $request->getUri();
$this->assertInstanceOf('Psr\Http\Message\UriInterface', $uri);
$this->assertEquals('https', $uri->getScheme());
$this->assertEquals('username:password', $uri->getUserInfo());
$this->assertEquals('localhost', $uri->getHost());
$this->assertEquals(18332, $uri->getPort());
}
public function testWithKeepAlive()
{
$client = new Client('https://username:password@localhost:18332');
$client->getRequest()->withHeader('Connection', 'Keep-Alive');
}
public function testSendCommand()
{
$response = \Mockery::mock('\Psr\Http\Message\ResponseInterface');
$driver = \Mockery::mock('\Nbobtc\Http\Driver\DriverInterface');
$driver
->shouldReceive('execute')
->andReturn($response);
$client = new Client('https://username:password@localhost:18332');
$client->withDriver($driver);
$command = new Command('gettransaction', array('transactionId'));
$response = $client->sendCommand($command);
}
}
================================================
FILE: tests/Http/Driver/CurlDriverTest.php
================================================
write("test");
$request = (new Request("https://google.com"));
$request = $request->withBody($body);
$driver = new CurlDriver();
/** @var \Psr\Http\Message\ResponseInterface */
$response = $driver->execute($request);
$this->assertInstanceOf("Psr\Http\Message\ResponseInterface", $response);
$driver = new CurlDriver();
/** @var \Psr\Http\Message\ResponseInterface */
$response = $driver->execute($request);
$this->assertInstanceOf("Psr\Http\Message\ResponseInterface", $response);
}
}