Skip to content

Commit bdb736e

Browse files
author
Sandro Keil
committed
updated readme, added more unit tests
1 parent 0f65315 commit bdb736e

File tree

7 files changed

+270
-16
lines changed

7 files changed

+270
-16
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Coverage Status](https://coveralls.io/repos/sandrokeil/BlockchainWalletApi/badge.png)](https://coveralls.io/r/sandrokeil/BlockchainWalletApi)
66
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a9184d9a-95bf-41c1-82e1-3d6d745602a2/mini.png)](https://insight.sensiolabs.com/projects/a9184d9a-95bf-41c1-82e1-3d6d745602a2)
77
[![Latest Stable Version](https://poser.pugx.org/sandrokeil/blockchain-wallet-api/v/stable.png)](https://packagist.org/packages/sandrokeil/blockchain-wallet-api)
8-
[![Dependency Status](https://www.versioneye.com/user/projects/53615c9cfe0d07b45c000082/badge.png)](https://www.versioneye.com/user/projects/53615c9cfe0d07b45c000082)
8+
[![Dependency Status](https://www.versioneye.com/user/projects/53615c9cfe0d07b45c000082/badge.svg)](https://www.versioneye.com/user/projects/53615c9cfe0d07b45c000082)
99
[![Total Downloads](https://poser.pugx.org/sandrokeil/blockchain-wallet-api/downloads.png)](https://packagist.org/packages/sandrokeil/blockchain-wallet-api)
1010
[![License](https://poser.pugx.org/sandrokeil/blockchain-wallet-api/license.png)](https://packagist.org/packages/sandrokeil/blockchain-wallet-api)
1111

@@ -59,7 +59,8 @@ use Sake\BlockchainWalletApi;
5959
// $sl is the service locator
6060
$blockchain = $sl->get('sake_bwa.service.default');
6161

62-
$request = $sl->get('sake_bwa.service.request')->get('send');
62+
/* @var $request BlockchainWalletApi\Request\Send */
63+
$request = $sl->get('sake_bwa.service.request')->get('payment');
6364
// or
6465
$request = new BlockchainWalletApi\Request\Send();
6566

@@ -86,8 +87,10 @@ Here is an example how to retrieve wallet balance:
8687
use Sake\BlockchainWalletApi;
8788

8889
// $sl is the service locator
90+
/* @var $blockchain BlockchainWalletApi\Service\BlockchainWallet */
8991
$blockchain = $sl->get('sake_bwa.service.default');
9092

93+
/* @var $request BlockchainWalletApi\Request\WalletBalance */
9194
$request = $sl->get('sake_bwa.service.request')->get('balance');
9295
// or
9396
$request = new BlockchainWalletApi\Request\WalletBalance();
@@ -111,7 +114,7 @@ Here is an example how to use satoshi view helper to convert satoshi to other un
111114
<?php
112115
// assume we are in a template
113116

114-
/* @var $response BlockchainWalletApi\Response\WalletBalance */
117+
/* @var $response \Sake\BlockchainWalletApi\Response\WalletBalance */
115118
echo $this->satoshi($response->getBalanace(), 'BTC'); // Bitcoin
116119
// or
117120
echo $this->satoshi($response->getBalanace(), 'mBTC'); // Milli Bits
@@ -151,4 +154,7 @@ return array(
151154
* `sake_bwa.service.hydrator`: a \Zend\Stdlib\Hydrator\ClassMethods instance with strategies and filters for requests/responses
152155

153156
## Registered view helper
157+
To use this view helper you must add `zendframework/zend-view` to your composer dependencies.
158+
154159
* `satoshi`: a \Zend\View\Helper\AbstractHelper instance which converts satoshi to other unit e.g. bitcoin
160+

src/Service/BlockchainWalletFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Sake\BlockchainWalletApi\Exception\RuntimeException;
1313
use Sake\EasyConfig\Service\AbstractConfigurableFactory;
14-
use Zend\Http\Client;
1514
use Zend\ServiceManager\FactoryInterface;
1615
use Zend\ServiceManager\ServiceLocatorInterface;
1716

@@ -115,7 +114,7 @@ protected function getClient(ServiceLocatorInterface $serviceLocator, array $con
115114
$client = $serviceLocator->get($config['client']);
116115
}
117116

118-
if (!$client instanceof Client) {
117+
if (!$client instanceof \Zend\Http\Client) {
119118
throw new RuntimeException(
120119
sprintf('Class "%s" is not an instance of \Zend\Http\Client', get_class($client))
121120
);

test/ModuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ public function testGetServiceConfig()
3333
'Service manager configuration could not be read'
3434
);
3535
}
36+
37+
/**
38+
* Tests getViewHelperConfig() should should return view helper configuration
39+
*
40+
* @covers \Sake\BlockchainWalletApi\Module::getViewHelperConfig
41+
*/
42+
public function testGetViewHelperConfig()
43+
{
44+
$cut = new Module();
45+
$config = $cut->getViewHelperConfig();
46+
$this->assertSame(
47+
@include 'config/view_helper.config.php',
48+
$config,
49+
'View helper configuration could not be read'
50+
);
51+
}
3652
}

test/Service/BlockchainWalletFactoryTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace SakeTest\BlockchainWalletApi\Service;
1111

1212
use Zend\Http;
13-
use Zend\Test\Util\ModuleLoader;
13+
use Zend\ServiceManager\ServiceManager;
1414
use SakeTest\BlockchainWalletApi\Service\AbstractFactoryTestCase as TestCase;
1515

1616
/**
@@ -87,4 +87,45 @@ public function testCreateServiceThrowsRuntimeExceptionIfNoOptionsAvailable()
8787

8888
$stub->createService($this->serviceManager);
8989
}
90+
91+
/**
92+
* Tests getClient() returns default zend http client
93+
*
94+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletFactory::getClient
95+
* @group factory
96+
*/
97+
public function testGetClientShouldReturnZendHttpClient()
98+
{
99+
$reflection = new \ReflectionClass('\Sake\BlockchainWalletApi\Service\BlockchainWalletFactory');
100+
$method = $reflection->getMethod('getClient');
101+
$method->setAccessible(true);
102+
103+
$cut = new \Sake\BlockchainWalletApi\Service\BlockchainWalletFactory();
104+
105+
$this->assertInstanceOf('Zend\Http\Client', $method->invoke($cut, new ServiceManager(), array()));
106+
}
107+
108+
/**
109+
* Tests getClient() throws runtime exception if no zend http client was returned from service manager
110+
*
111+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletFactory::getClient
112+
* @group factory
113+
*/
114+
public function testGetClientShouldThrowRuntimeExceptionIfClientWrong()
115+
{
116+
$reflection = new \ReflectionClass('\Sake\BlockchainWalletApi\Service\BlockchainWalletFactory');
117+
$method = $reflection->getMethod('getClient');
118+
$method->setAccessible(true);
119+
120+
$cut = new \Sake\BlockchainWalletApi\Service\BlockchainWalletFactory();
121+
122+
$sl = new ServiceManager(new \Zend\ServiceManager\Config(array(
123+
'services' => array(
124+
'testclient' => new \stdClass()
125+
)
126+
)));
127+
128+
$this->setExpectedException('\Sake\BlockchainWalletApi\Exception\RuntimeException', 'Class');
129+
$method->invoke($cut, $sl, array('client' => 'testclient'));
130+
}
90131
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
/**
3+
* Sake
4+
*
5+
* @link http://github.com/sandrokeil/BlockchainWalletApi for the canonical source repository
6+
* @copyright Copyright (c) 2014 Sandro Keil
7+
* @license http://github.com/sandrokeil/BlockchainWalletApi/blob/master/LICENSE.txt New BSD License
8+
*/
9+
10+
namespace SakeTest\BlockchainWalletApi\Service;
11+
12+
use Sake\BlockchainWalletApi\Service\BlockchainWalletOptions;
13+
use PHPUnit_Framework_TestCase as TestCase;
14+
15+
/**
16+
* Class BlockChainWalletTest
17+
*
18+
* Tests integrity of \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions
19+
*/
20+
class BlockchainWalletOptionsTest extends TestCase
21+
{
22+
/**
23+
* Tests setGuid() and getGuid() should work as expected
24+
*
25+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::setGuid
26+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getGuid
27+
* @group service
28+
*/
29+
public function testSetGuid()
30+
{
31+
$cut = new BlockchainWalletOptions();
32+
$value = '123123123';
33+
34+
$cut->setGuid($value);
35+
36+
$this->assertEquals($value, $cut->getGuid());
37+
}
38+
39+
/**
40+
* Tests setHttpMethod() and getHttpMethod() should work as expected
41+
*
42+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::setHttpMethod
43+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getHttpMethod
44+
* @group service
45+
*/
46+
public function testSetHttpMethod()
47+
{
48+
$cut = new BlockchainWalletOptions();
49+
$value = \Zend\Http\Request::METHOD_POST;
50+
51+
$this->assertEquals(\Zend\Http\Request::METHOD_GET, $cut->getHttpMethod());
52+
53+
$cut->setHttpMethod($value);
54+
55+
$this->assertEquals($value, $cut->getHttpMethod());
56+
}
57+
58+
/**
59+
* Tests setMainPassword() and getMainPassword() should work as expected
60+
*
61+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::setMainPassword
62+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getMainPassword
63+
* @group service
64+
*/
65+
public function testSetMainPassword()
66+
{
67+
$cut = new BlockchainWalletOptions();
68+
$value = 'secure';
69+
70+
$cut->setMainPassword($value);
71+
72+
$this->assertEquals($value, $cut->getMainPassword());
73+
}
74+
75+
/**
76+
* Tests setSecondPassword() and getSecondPassword() should work as expected
77+
*
78+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::setSecondPassword
79+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getSecondPassword
80+
* @group service
81+
*/
82+
public function testSetSecondPassword()
83+
{
84+
$cut = new BlockchainWalletOptions();
85+
$value = 'secure second';
86+
87+
$cut->setSecondPassword($value);
88+
89+
$this->assertEquals($value, $cut->getSecondPassword());
90+
}
91+
92+
/**
93+
* Tests setUrl() and getUrl() should work as expected
94+
*
95+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::setUrl
96+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getUrl
97+
* @group service
98+
*/
99+
public function testSetUrl()
100+
{
101+
$cut = new BlockchainWalletOptions();
102+
$value = 'https://blockchain.info/de/merchant/';
103+
104+
$cut->setUrl($value);
105+
106+
$this->assertEquals($value, $cut->getUrl());
107+
}
108+
109+
/**
110+
* Tests getResponsePluginManager() return default response plugin manager if no one provided
111+
*
112+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getResponsePluginManager
113+
* @group service
114+
*/
115+
public function testGetResponsePluginManagerShouldReturnDefaultResponsePluginManager()
116+
{
117+
$cut = new BlockchainWalletOptions();
118+
119+
$this->assertInstanceOf(
120+
'\Sake\BlockchainWalletApi\Service\ResponsePluginManager',
121+
$cut->getResponsePluginManager()
122+
);
123+
}
124+
125+
/**
126+
* Tests getInputFilterPluginManager() return default input filter manager if no one provided
127+
*
128+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getInputFilterPluginManager
129+
* @group service
130+
*/
131+
public function testGetInputFilterPluginManagerShouldReturnDefaultFilterPluginManager()
132+
{
133+
$cut = new BlockchainWalletOptions();
134+
135+
$this->assertInstanceOf(
136+
'\Sake\BlockchainWalletApi\Service\InputFilterPluginManager',
137+
$cut->getInputFilterPluginManager()
138+
);
139+
}
140+
141+
/**
142+
* Tests getHydrator() return class methods hydrator if no one provided
143+
*
144+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::getHydrator
145+
* @group service
146+
*/
147+
public function testGetHydratorShouldReturnDefaultClassMethods()
148+
{
149+
$cut = new BlockchainWalletOptions();
150+
151+
$this->assertInstanceOf(
152+
'\Zend\Stdlib\Hydrator\ClassMethods',
153+
$cut->getHydrator()
154+
);
155+
}
156+
157+
/**
158+
* Tests setHydrator()
159+
*
160+
* @covers \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions::setHydrator
161+
* @group service
162+
*/
163+
public function testsetHydrator()
164+
{
165+
$cut = new BlockchainWalletOptions();
166+
167+
$cut->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
168+
169+
$this->assertInstanceOf(
170+
'\Zend\Stdlib\Hydrator\ObjectProperty',
171+
$cut->getHydrator()
172+
);
173+
}
174+
}

test/Service/ResponsePluginManagerTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@
2121
class ResponsePluginManagerTest extends TestCase
2222
{
2323
/**
24-
* Tests validatePlugin() throws no exception for available response classes
25-
*
26-
* @dataProvider dataProviderForTestValidatePlugin
24+
* Tests validatePlugin() should throw runtime exception if response interface is missing
2725
*
2826
* @covers \Sake\BlockchainWalletApi\Service\ResponsePluginManager::validatePlugin
2927
* @group service
3028
*/
31-
public function testValidatePlugin($plugin, $expected)
29+
public function testValidatePluginThrowsRuntimeExceptionIfInterfaceIsMissong()
3230
{
3331
$manager = new ResponsePluginManager();
3432

35-
$this->assertInstanceOf($expected, $manager->get($plugin));
33+
$this->setExpectedException('\Sake\BlockchainWalletApi\Exception\RuntimeException', 'Plugin of type');
34+
$manager->validatePlugin(new \stdClass());
3635
}
3736

3837
/**
39-
* Tests validatePlugin() should throw runtime exception if response interface is missing
38+
* Tests validatePlugin() throws no exception for available response classes
39+
*
40+
* @dataProvider dataProviderForTestValidatePlugin
4041
*
4142
* @covers \Sake\BlockchainWalletApi\Service\ResponsePluginManager::validatePlugin
4243
* @group service
4344
*/
44-
public function testValidatePluginThrowsRuntimeExceptionIfInterfaceIsMissong()
45+
public function testValidatePlugin($plugin, $expected)
4546
{
4647
$manager = new ResponsePluginManager();
4748

48-
$this->setExpectedException('\Sake\BlockchainWalletApi\Exception\RuntimeException', 'Plugin of type');
49-
$manager->validatePlugin(new \stdClass());
49+
$this->assertInstanceOf($expected, $manager->get($plugin));
5050
}
5151

5252
/**

test/Validator/BitcoinAddressTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class BitcoinAddressTest extends TestCase
2222
{
2323
/**
24-
* Tests if getMethod returns the correct api method
24+
* Tests if isValid checks bitcoin address format
2525
*
2626
* @dataProvider dataProviderForTestIsValid
2727
* @group validator
@@ -45,6 +45,24 @@ public function testIsValid($address, $expected)
4545
}
4646
}
4747

48+
/**
49+
* Tests if isValid returns false
50+
*
51+
* @group validator
52+
*
53+
* @covers \Sake\BlockchainWalletApi\Validator\BitcoinAddress::isValid
54+
*/
55+
public function testIsValidWithWrongChecksum()
56+
{
57+
$cut = $this->getMock('\Sake\BlockchainWalletApi\Validator\BitcoinAddress', array('decode'));
58+
59+
$cut->expects($this->once())
60+
->method('decode')
61+
->will($this->returnValue('0006F1B66FFE49DF7FCE684DF16C62F59DC9ADBD3F4FEC479B'));
62+
63+
$this->assertFalse($cut->isValid('ThisAddressIsIgnored'));
64+
}
65+
4866
/**
4967
* data provider for the test method testIsValid()
5068
*

0 commit comments

Comments
 (0)