Skip to content

Commit

Permalink
Merge pull request #32 from hhxsv5/master
Browse files Browse the repository at this point in the history
Fix tests with dataProvider
  • Loading branch information
谢彪 authored Mar 21, 2019
2 parents c2c52bc + 6ba8785 commit 0bd19f5
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 238 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ KuCoinApi::setBaseUri('https://openapi-sandbox.kucoin.com');
### Examples
> See the [test case](tests) for more examples.
- Example of API `without` authentication
#### Example of API `without` authentication

```php
use KuCoin\SDK\PublicApi\Time;
Expand All @@ -49,7 +49,7 @@ $timestamp = $api->timestamp();
var_dump($timestamp);
```

- Example of API `with` authentication
#### Example of API `with` authentication

```php
use KuCoin\SDK\Auth;
Expand All @@ -70,7 +70,7 @@ try {
}
```

- Example of WebSocket feed
#### Example of WebSocket feed

```php
use KuCoin\SDK\Auth;
Expand Down Expand Up @@ -98,7 +98,7 @@ $api->subscribePublicChannel($query, $channel, function (array $message, WebSock
});
```

- Coroutine HTTP client for asynchronous IO
#### ⚡️Coroutine HTTP client for asynchronous IO

```bash
pecl install swoole
Expand All @@ -112,7 +112,7 @@ use KuCoin\SDK\Http\SwooleHttp;
// Require PHP 7.1+ and Swoole 2.1.2+
// Require running in cli mode
go(function () {
$api = new Time(null, new SwooleHttp());
$api = new Time(null, new SwooleHttp));
$timestamp = $api->timestamp();
var_dump($timestamp);
});
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"secure-http": false
},
"scripts": {
"test": "./vendor/bin/phpunit -c phpunit.xml --filter '/::test(New|Get)\\w+$/' --coverage-text --verbose"
"test": "./vendor/bin/phpunit -c phpunit.xml --filter '/::testGet\\w+/' --coverage-text --verbose"
}
}
2 changes: 1 addition & 1 deletion examples/GoTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Require PHP 7.1+ and Swoole 2.1.2+
// Require running in cli mode
go(function () {
$api = new Time(null, new SwooleHttp());
$api = new Time(null, new SwooleHttp);
$timestamp = $api->timestamp();
var_dump($timestamp);
});
85 changes: 31 additions & 54 deletions tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,17 @@
namespace KuCoin\SDK\Tests;

use KuCoin\SDK\ApiCode;
use KuCoin\SDK\Auth;
use KuCoin\SDK\Exceptions\BusinessException;
use KuCoin\SDK\PrivateApi\Account;

class AccountTest extends TestCase
{
public function testNewAuth()
{
$auth = new Auth($this->apiKey, $this->apiSecret, $this->apiPassPhrase);
$this->assertInstanceOf(Auth::class, $auth);
return $auth;
}
protected $apiClass = Account::class;
protected $apiWithAuth = true;

/**
* @depends testNewAuth
* @param Auth $auth
* @return Account
*/
public function testNewAccount(Auth $auth)
{
$api = new Account($auth);
$this->assertInstanceOf(Account::class, $api);
return $api;
}

/**
* @depends testNewAccount
* @dataProvider apiProvider
* @param Account $api
* @return array|string
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
Expand All @@ -48,13 +30,11 @@ public function testGetMainList(Account $api)
$this->assertArrayHasKey('holds', $item);
$this->assertArrayHasKey('type', $item);
}
return $accounts;
}

/**
* @depends testNewAccount
* @dataProvider apiProvider
* @param Account $api
* @return array|string
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
Expand All @@ -71,60 +51,57 @@ public function testGetTradeList(Account $api)
$this->assertArrayHasKey('holds', $item);
$this->assertArrayHasKey('type', $item);
}
return $accounts;
}

/**
* @depends testNewAccount
* @dataProvider apiProvider
* @param Account $api
* @return array|string
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testCreateAccount(Account $api)
public function testGetDetail(Account $api)
{
try {
$data = $api->create('trade', 'ETH');
$this->assertArrayHasKey('id', $data);
} catch (BusinessException $e) {
if ($e->getResponse()->getApiCode() != ApiCode::ACCOUNT_EXISTS) { //account already exists
throw $e;
}
$accounts = $api->getList(['type' => 'main']);
if (isset($accounts[0])) {
$account = $api->getDetail($accounts[0]['id']);
$this->assertArrayHasKey('currency', $account);
$this->assertArrayHasKey('balance', $account);
$this->assertArrayHasKey('available', $account);
$this->assertArrayHasKey('holds', $account);
}
}

/**
* @depends testNewAccount
* @depends testGetMainList
* @dataProvider apiProvider
* @param Account $api
* @param array $accounts
* @return array|string
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetDetail(Account $api, array $accounts)
public function testCreateAccount(Account $api)
{
if (isset($accounts[0])) {
$account = $api->getDetail($accounts[0]['id']);
$this->assertArrayHasKey('currency', $account);
$this->assertArrayHasKey('balance', $account);
$this->assertArrayHasKey('available', $account);
$this->assertArrayHasKey('holds', $account);
try {
$data = $api->create('trade', 'ETH');
$this->assertArrayHasKey('id', $data);
} catch (BusinessException $e) {
if ($e->getResponse()->getApiCode() != ApiCode::ACCOUNT_EXISTS) { //account already exists
throw $e;
}
}
}

/**
* @depends testNewAccount
* @depends testGetTradeList
* @dataProvider apiProvider
* @param Account $api
* @param array $accounts
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetLedgers(Account $api, array $accounts)
public function testGetLedgers(Account $api)
{
$accounts = $api->getList(['type' => 'trade']);
if (isset($accounts[0])) {
$data = $api->getLedgers($accounts[0]['id'], [], ['currentPage' => 1, 'pageSize' => 10]);
$this->assertPagination($data);
Expand All @@ -142,7 +119,7 @@ public function testGetLedgers(Account $api, array $accounts)
}

/**
* @depends testNewAccount
* @dataProvider apiProvider
* @param Account $api
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand Down Expand Up @@ -175,16 +152,16 @@ public function testInnerTransfer(Account $api)
}

/**
* @depends testNewAccount
* @depends testGetMainList
* @dataProvider apiProvider
* @depends testGetMainList
* @param Account $api
* @param array $accounts
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetHolds(Account $api, array $accounts)
public function testGetHolds(Account $api)
{
$accounts = $api->getList(['type' => 'trade']);
if (isset($accounts[0])) {
$data = $api->getHolds($accounts[1]['id'], ['currentPage' => 1, 'pageSize' => 10]);
$this->assertPagination($data);
Expand Down
17 changes: 5 additions & 12 deletions tests/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@

class CurrencyTest extends TestCase
{
/**
* @return Currency
*/
public function testNewCurrency()
{
$api = new Currency();
$this->assertInstanceOf(Currency::class, $api);
return $api;
}
protected $apiClass = Currency::class;
protected $apiWithAuth = false;

/**
* @depends testNewCurrency
* @dataProvider apiProvider
* @param Currency $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand All @@ -40,7 +33,7 @@ public function testGetList(Currency $api)
}

/**
* @depends testNewCurrency
* @dataProvider apiProvider
* @param Currency $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand All @@ -61,7 +54,7 @@ public function testGetDetail(Currency $api)
}

/**
* @depends testNewCurrency
* @dataProvider apiProvider
* @param Currency $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand Down
27 changes: 5 additions & 22 deletions tests/DepositTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,16 @@

namespace KuCoin\SDK\Tests;

use KuCoin\SDK\Auth;
use KuCoin\SDK\Exceptions\BusinessException;
use KuCoin\SDK\PrivateApi\Deposit;

class DepositTest extends TestCase
{
public function testNewAuth()
{
$auth = new Auth($this->apiKey, $this->apiSecret, $this->apiPassPhrase);
$this->assertInstanceOf(Auth::class, $auth);
return $auth;
}

/**
* @depends testNewAuth
* @param Auth $auth
* @return Deposit
*/
public function testNewDeposit(Auth $auth)
{
$api = new Deposit($auth);
$this->assertInstanceOf(Deposit::class, $api);
return $api;
}
protected $apiClass = Deposit::class;
protected $apiWithAuth = true;

/**
* @depends testNewDeposit
* @dataProvider apiProvider
* @param Deposit $api
* @return array|string
* @throws \KuCoin\SDK\Exceptions\BusinessException
Expand All @@ -44,7 +27,7 @@ public function testCreateAddress(Deposit $api)
}

/**
* @depends testNewDeposit
* @dataProvider apiProvider
* @param Deposit $api
* @return array|string
* @throws \KuCoin\SDK\Exceptions\BusinessException
Expand All @@ -70,7 +53,7 @@ public function testGetAddress(Deposit $api)
}

/**
* @depends testNewDeposit
* @dataProvider apiProvider
* @param Deposit $api
* @return array|string
* @throws \KuCoin\SDK\Exceptions\BusinessException
Expand Down
25 changes: 4 additions & 21 deletions tests/FillTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,15 @@

namespace KuCoin\SDK\Tests;

use KuCoin\SDK\Auth;
use KuCoin\SDK\PrivateApi\Fill;

class FillTest extends TestCase
{
public function testNewAuth()
{
$auth = new Auth($this->apiKey, $this->apiSecret, $this->apiPassPhrase);
$this->assertInstanceOf(Auth::class, $auth);
return $auth;
}

/**
* @depends testNewAuth
* @param Auth $auth
* @return Fill
*/
public function testNewFill(Auth $auth)
{
$api = new Fill($auth);
$this->assertInstanceOf(Fill::class, $api);
return $api;
}
protected $apiClass = Fill::class;
protected $apiWithAuth = true;

/**
* @depends testNewFill
* @dataProvider apiProvider
* @param Fill $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand Down Expand Up @@ -58,7 +41,7 @@ public function testGetList(Fill $api)
}

/**
* @depends testNewFill
* @dataProvider apiProvider
* @param Fill $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand Down
Loading

0 comments on commit 0bd19f5

Please sign in to comment.