diff --git a/tests/API/ApiNodesTest.php b/tests/API/ApiNodesTest.php index 6449a43..4b46de6 100644 --- a/tests/API/ApiNodesTest.php +++ b/tests/API/ApiNodesTest.php @@ -5,18 +5,9 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\ApiNodes - */ -class ApiNodesTest extends TestCase -{ - /** @test */ - public function api_nodes_calls_correct_url() - { - $this->assertResponse('GET', 'api-nodes', function (ArkClient $client) { - return $client->apiNodes()->all(); - }); - } -} +it('calls the correct url for api nodes', function () { + $this->assertResponse('GET', 'api-nodes', function (ArkClient $client) { + return $client->apiNodes()->all(); + }); +}); diff --git a/tests/API/BlockchainTest.php b/tests/API/BlockchainTest.php index 4f8f735..6b32c81 100644 --- a/tests/API/BlockchainTest.php +++ b/tests/API/BlockchainTest.php @@ -5,18 +5,9 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Blockchain - */ -class BlockchainTest extends TestCase -{ - /** @test */ - public function blockchain´_calls_correct_url() - { - $this->assertResponse('GET', 'blockchain', function (ArkClient $client) { - return $client->blockchain()->blockchain(); - }); - } -} +it('calls the correct blockchain url', function () { + $this->assertResponse('GET', 'blockchain', function (ArkClient $client) { + return $client->blockchain()->blockchain(); + }); +}); diff --git a/tests/API/BlocksTest.php b/tests/API/BlocksTest.php index 1279074..b851c8e 100644 --- a/tests/API/BlocksTest.php +++ b/tests/API/BlocksTest.php @@ -5,50 +5,33 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; - -/** - * @covers \ArkEcosystem\Client\API\Blocks - */ -class BlocksTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'blocks', function (ArkClient $client) { - return $client->blocks()->all(); - }); - } - - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'blocks/dummy', function (ArkClient $client) { - return $client->blocks()->get('dummy'); - }); - } - - /** @test */ - public function first_calls_correct_url() - { - $this->assertResponse('GET', 'blocks/first', function (ArkClient $client) { - return $client->blocks()->first(); - }); - } - - /** @test */ - public function last_calls_correct_url() - { - $this->assertResponse('GET', 'blocks/last', function (ArkClient $client) { - return $client->blocks()->last(); - }); - } - - /** @test */ - public function transactions_calls_correct_url() - { - $this->assertResponse('GET', 'blocks/dummy/transactions', function (ArkClient $client) { - return $client->blocks()->transactions('dummy'); - }); - } -} + +it('calls correct url for all', function () { + $this->assertResponse('GET', 'blocks', function (ArkClient $client) { + return $client->blocks()->all(); + }); +}); + +it('calls correct url for get', function () { + $this->assertResponse('GET', 'blocks/dummy', function (ArkClient $client) { + return $client->blocks()->get('dummy'); + }); +}); + +it('calls correct url for first', function () { + $this->assertResponse('GET', 'blocks/first', function (ArkClient $client) { + return $client->blocks()->first(); + }); +}); + +it('calls correct url for last', function () { + $this->assertResponse('GET', 'blocks/last', function (ArkClient $client) { + return $client->blocks()->last(); + }); +}); + +it('calls correct url for transactions', function () { + $this->assertResponse('GET', 'blocks/dummy/transactions', function (ArkClient $client) { + return $client->blocks()->transactions('dummy'); + }); +}); diff --git a/tests/API/CommitsTest.php b/tests/API/CommitsTest.php index 33b8e1b..aa3653d 100644 --- a/tests/API/CommitsTest.php +++ b/tests/API/CommitsTest.php @@ -5,18 +5,9 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Commits - */ -class CommitsTest extends TestCase -{ - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'commits/1', function (ArkClient $client) { - return $client->commits()->get(1); - }); - } -} +it('calls the correct URL for get', function () { + $this->assertResponse('GET', 'commits/1', function (ArkClient $client) { + return $client->commits()->get(1); + }); +}); diff --git a/tests/API/ContractsTest.php b/tests/API/ContractsTest.php index 340e9ad..bf4ad7e 100644 --- a/tests/API/ContractsTest.php +++ b/tests/API/ContractsTest.php @@ -5,26 +5,15 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Contracts - */ -class ContractsTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'contracts', function (ArkClient $client) { - return $client->contracts()->all(); - }); - } +it('calls the correct url for all contracts', function () { + $this->assertResponse('GET', 'contracts', function (ArkClient $client) { + return $client->contracts()->all(); + }); +}); - /** @test */ - public function abi_calls_correct_url() - { - $this->assertResponse('GET', 'contracts/consensus/some-wallet/abi', function (ArkClient $client) { - return $client->contracts()->abi('consensus', 'some-wallet'); - }); - } -} +it('calls the correct url for abi', function () { + $this->assertResponse('GET', 'contracts/consensus/some-wallet/abi', function (ArkClient $client) { + return $client->contracts()->abi('consensus', 'some-wallet'); + }); +}); diff --git a/tests/API/EVMTest.php b/tests/API/EVMTest.php index 9f79086..2c583b5 100644 --- a/tests/API/EVMTest.php +++ b/tests/API/EVMTest.php @@ -5,27 +5,18 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\EVM - */ -class EVMTest extends TestCase -{ - /** @test */ - public function eth_call_calls_correct_url() - { - $this->assertResponse( - method: 'POST', - path: 'api/', - callback: function (ArkClient $client) { - return $client->evm()->ethCall([ - 'from' => '0x1234567890abcdef', - 'to' => '0xfedcba0987654321', - 'data' => '0xabcdef', - ]); - }, - expectedApi: 'evm' - ); - } -} +it('calls the correct URL for eth_call', function () { + $this->assertResponse( + method: 'POST', + path: 'api/', + callback: function (ArkClient $client) { + return $client->evm()->ethCall([ + 'from' => '0x1234567890abcdef', + 'to' => '0xfedcba0987654321', + 'data' => '0xabcdef', + ]); + }, + expectedApi: 'evm' + ); +}); diff --git a/tests/API/NodeTest.php b/tests/API/NodeTest.php index 0837c88..cc06608 100644 --- a/tests/API/NodeTest.php +++ b/tests/API/NodeTest.php @@ -5,50 +5,33 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; - -/** - * @covers \ArkEcosystem\Client\API\Node - */ -class NodeTest extends TestCase -{ - /** @test */ - public function status_calls_correct_url() - { - $this->assertResponse('GET', 'node/status', function (ArkClient $client) { - return $client->node()->status(); - }); - } - - /** @test */ - public function syncing_calls_correct_url() - { - $this->assertResponse('GET', 'node/syncing', function (ArkClient $client) { - return $client->node()->syncing(); - }); - } - - /** @test */ - public function configuration_calls_correct_url() - { - $this->assertResponse('GET', 'node/configuration', function (ArkClient $client) { - return $client->node()->configuration(); - }); - } - - /** @test */ - public function crypto_calls_correct_url() - { - $this->assertResponse('GET', 'node/configuration/crypto', function (ArkClient $client) { - return $client->node()->crypto(); - }); - } - - /** @test */ - public function fees_calls_correct_url() - { - $this->assertResponse('GET', 'node/fees', function (ArkClient $client) { - return $client->node()->fees(); - }); - } -} + +it('calls the correct url for status', function () { + $this->assertResponse('GET', 'node/status', function (ArkClient $client) { + return $client->node()->status(); + }); +}); + +it('calls the correct url for syncing', function () { + $this->assertResponse('GET', 'node/syncing', function (ArkClient $client) { + return $client->node()->syncing(); + }); +}); + +it('calls the correct url for configuration', function () { + $this->assertResponse('GET', 'node/configuration', function (ArkClient $client) { + return $client->node()->configuration(); + }); +}); + +it('calls the correct url for crypto', function () { + $this->assertResponse('GET', 'node/configuration/crypto', function (ArkClient $client) { + return $client->node()->crypto(); + }); +}); + +it('calls the correct url for fees', function () { + $this->assertResponse('GET', 'node/fees', function (ArkClient $client) { + return $client->node()->fees(); + }); +}); diff --git a/tests/API/PeersTest.php b/tests/API/PeersTest.php index 6d9ffae..b9a40ab 100644 --- a/tests/API/PeersTest.php +++ b/tests/API/PeersTest.php @@ -5,26 +5,15 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Peers - */ -class PeersTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'peers', function (ArkClient $client) { - return $client->peers()->all(); - }); - } +it('calls correct url for all', function () { + $this->assertResponse('GET', 'peers', function (ArkClient $client) { + return $client->peers()->all(); + }); +}); - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'peers/dummy', function (ArkClient $client) { - return $client->peers()->get('dummy'); - }); - } -} +it('calls correct url for get', function () { + $this->assertResponse('GET', 'peers/dummy', function (ArkClient $client) { + return $client->peers()->get('dummy'); + }); +}); diff --git a/tests/API/ReceiptsTest.php b/tests/API/ReceiptsTest.php index 2ce5f79..b356c1b 100644 --- a/tests/API/ReceiptsTest.php +++ b/tests/API/ReceiptsTest.php @@ -5,48 +5,35 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; use Exception; -/** - * @covers \ArkEcosystem\Client\API\Receipts - */ -class ReceiptsTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'receipts', function (ArkClient $client) { - return $client->receipts()->all(); - }); - } +it('calls the correct url for all', function () { + $this->assertResponse('GET', 'receipts', function (ArkClient $client) { + return $client->receipts()->all(); + }); +}); - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse( - method: 'GET', - path: 'receipts/dummyTxHash', - callback: function (ArkClient $client) { - return $client->receipts()->get('dummyTxHash'); - }, - response: ['data' => [['id' => 'dummyTxHash']]], - expectedBody: ['id' => 'dummyTxHash'] - ); - } +it('calls the correct url for get', function () { + $this->assertResponse( + method: 'GET', + path: 'receipts/dummyTxHash', + callback: function (ArkClient $client) { + return $client->receipts()->get('dummyTxHash'); + }, + response: ['data' => [['id' => 'dummyTxHash']]], + expectedBody: ['id' => 'dummyTxHash'] + ); +}); - /** @test */ - public function validates_the_response() - { - $this->expectException(Exception::class); +it('validates the response', function () { + $this->expectException(Exception::class); - $this->assertResponse( - method: 'GET', - path: 'receipts/dummyTxHash', - callback: function (ArkClient $client) { - return $client->receipts()->get('dummyTxHash'); - }, - response: ['data' => []], - ); - } -} + $this->assertResponse( + method: 'GET', + path: 'receipts/dummyTxHash', + callback: function (ArkClient $client) { + return $client->receipts()->get('dummyTxHash'); + }, + response: ['data' => []], + ); +}); diff --git a/tests/API/RoundsTest.php b/tests/API/RoundsTest.php index 9d4528a..0edeb6c 100644 --- a/tests/API/RoundsTest.php +++ b/tests/API/RoundsTest.php @@ -5,34 +5,21 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Rounds - */ -class RoundsTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'rounds', function (ArkClient $client) { - return $client->rounds()->all(); - }); - } +it('calls correct url for all', function () { + $this->assertResponse('GET', 'rounds', function (ArkClient $client) { + return $client->rounds()->all(); + }); +}); - /** @test */ - public function view_calls_correct_url() - { - $this->assertResponse('GET', 'rounds/12345', function (ArkClient $client) { - return $client->rounds()->get(12345); - }); - } +it('calls correct url for view', function () { + $this->assertResponse('GET', 'rounds/12345', function (ArkClient $client) { + return $client->rounds()->get(12345); + }); +}); - /** @test */ - public function validators_calls_correct_url() - { - $this->assertResponse('GET', 'rounds/12345/validators', function (ArkClient $client) { - return $client->rounds()->validators(12345); - }); - } -} +it('calls correct url for validators', function () { + $this->assertResponse('GET', 'rounds/12345/validators', function (ArkClient $client) { + return $client->rounds()->validators(12345); + }); +}); diff --git a/tests/API/TransactionsTest.php b/tests/API/TransactionsTest.php index 617869b..761c25e 100644 --- a/tests/API/TransactionsTest.php +++ b/tests/API/TransactionsTest.php @@ -5,78 +5,59 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Transactions - */ -class TransactionsTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'transactions', function (ArkClient $client) { - return $client->transactions()->all(); - }); - } - - /** @test */ - public function create_calls_correct_url() - { - $this->assertResponse( - method: 'POST', - path: 'transactions', - callback: function (ArkClient $client) { - return $client->transactions()->create(['transactions' => []]); - }, - expectedApi: 'transactions' - ); - } - - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'transactions/dummy', function (ArkClient $client) { - return $client->transactions()->get('dummy'); - }); - } - - /** @test */ - public function all_unconfirmed_calls_correct_url() - { - $this->assertResponse( - method: 'GET', - path: 'transactions/unconfirmed', - callback: function (ArkClient $client) { - return $client->transactions()->allUnconfirmed(); - }, - expectedApi: 'transactions' - ); - } - - /** @test */ - public function get_unconfirmed_calls_correct_url() - { - $this->assertResponse( - method: 'GET', - path: 'transactions/unconfirmed/dummy', - callback: function (ArkClient $client) { - return $client->transactions()->getUnconfirmed('dummy'); - }, - expectedApi: 'transactions' - ); - } - - /** @test */ - public function configuration_calls_correct_url() - { - $this->assertResponse( - method: 'GET', - path: 'configuration', - callback: function (ArkClient $client) { - return $client->transactions()->configuration(); - }, - expectedApi: 'transactions' - ); - } -} +it('calls correct url for all', function () { + $this->assertResponse('GET', 'transactions', function (ArkClient $client) { + return $client->transactions()->all(); + }); +}); + +it('calls correct url for create', function () { + $this->assertResponse( + method: 'POST', + path: 'transactions', + callback: function (ArkClient $client) { + return $client->transactions()->create(['transactions' => []]); + }, + expectedApi: 'transactions' + ); +}); + +it('calls correct url for get', function () { + $this->assertResponse('GET', 'transactions/dummy', function (ArkClient $client) { + return $client->transactions()->get('dummy'); + }); +}); + +it('calls correct url for all unconfirmed', function () { + $this->assertResponse( + method: 'GET', + path: 'transactions/unconfirmed', + callback: function (ArkClient $client) { + return $client->transactions()->allUnconfirmed(); + }, + expectedApi: 'transactions' + ); +}); + +it('calls correct url for get unconfirmed', function () { + $this->assertResponse( + method: 'GET', + path: 'transactions/unconfirmed/dummy', + callback: function (ArkClient $client) { + return $client->transactions()->getUnconfirmed('dummy'); + }, + expectedApi: 'transactions' + ); +}); + +it('calls correct url for configuration', function () { + $this->assertResponse( + method: 'GET', + path: 'configuration', + callback: function (ArkClient $client) { + return $client->transactions()->configuration(); + }, + expectedApi: 'transactions' + ); +}); diff --git a/tests/API/ValidatorsTest.php b/tests/API/ValidatorsTest.php index dc4fafb..e1d87b4 100644 --- a/tests/API/ValidatorsTest.php +++ b/tests/API/ValidatorsTest.php @@ -5,42 +5,27 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Validators - */ -class ValidatorsTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'validators', function (ArkClient $client) { - return $client->validators()->all(); - }); - } +it('calls correct url for all', function () { + $this->assertResponse('GET', 'validators', function (ArkClient $client) { + return $client->validators()->all(); + }); +}); - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'validators/dummy', function (ArkClient $client) { - return $client->validators()->get('dummy'); - }); - } +it('calls correct url for get', function () { + $this->assertResponse('GET', 'validators/dummy', function (ArkClient $client) { + return $client->validators()->get('dummy'); + }); +}); - /** @test */ - public function blocks_calls_correct_url() - { - $this->assertResponse('GET', 'validators/dummy/blocks', function (ArkClient $client) { - return $client->validators()->blocks('dummy'); - }); - } +it('calls correct url for blocks', function () { + $this->assertResponse('GET', 'validators/dummy/blocks', function (ArkClient $client) { + return $client->validators()->blocks('dummy'); + }); +}); - /** @test */ - public function voters_calls_correct_url() - { - $this->assertResponse('GET', 'validators/dummy/voters', function (ArkClient $client) { - return $client->validators()->voters('dummy'); - }); - } -} +it('calls correct url for voters', function () { + $this->assertResponse('GET', 'validators/dummy/voters', function (ArkClient $client) { + return $client->validators()->voters('dummy'); + }); +}); diff --git a/tests/API/VotesTest.php b/tests/API/VotesTest.php index 12a3d10..d9d064d 100644 --- a/tests/API/VotesTest.php +++ b/tests/API/VotesTest.php @@ -5,34 +5,15 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Votes - */ -class VotesTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'votes', function (ArkClient $client) { - return $client->votes()->all(); - }); - } +it('calls correct url for all', function () { + $this->assertResponse('GET', 'votes', function (ArkClient $client) { + return $client->votes()->all(); + }); +}); - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'votes/dummy', function (ArkClient $client) { - return $client->votes()->get('dummy'); - }); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \ArkEcosystem\Client\API\Votes::class; - } -} +it('calls correct url for get', function () { + $this->assertResponse('GET', 'votes/dummy', function (ArkClient $client) { + return $client->votes()->get('dummy'); + }); +}); diff --git a/tests/API/WalletsTest.php b/tests/API/WalletsTest.php index 8db83b9..f2c04cd 100644 --- a/tests/API/WalletsTest.php +++ b/tests/API/WalletsTest.php @@ -5,74 +5,45 @@ namespace ArkEcosystem\Tests\Client\API; use ArkEcosystem\Client\ArkClient; -use ArkEcosystem\Tests\Client\TestCase; -/** - * @covers \ArkEcosystem\Client\API\Wallets - */ -class WalletsTest extends TestCase -{ - /** @test */ - public function all_calls_correct_url() - { - $this->assertResponse('GET', 'wallets', function (ArkClient $client) { - return $client->wallets()->all(); - }); - } - - /** @test */ - public function top_calls_correct_url() - { - $this->assertResponse('GET', 'wallets/top', function (ArkClient $client) { - return $client->wallets()->top(); - }); - } - - /** @test */ - public function get_calls_correct_url() - { - $this->assertResponse('GET', 'wallets/dummy', function (ArkClient $client) { - return $client->wallets()->get('dummy'); - }); - } - - /** @test */ - public function transactions_calls_correct_url() - { - $this->assertResponse('GET', 'wallets/dummy/transactions', function (ArkClient $client) { - return $client->wallets()->transactions('dummy'); - }); - } - - /** @test */ - public function sent_transactions_calls_correct_url() - { - $this->assertResponse('GET', 'wallets/dummy/transactions/sent', function (ArkClient $client) { - return $client->wallets()->sentTransactions('dummy'); - }); - } - - /** @test */ - public function received_transactions_calls_correct_url() - { - $this->assertResponse('GET', 'wallets/dummy/transactions/received', function (ArkClient $client) { - return $client->wallets()->receivedTransactions('dummy'); - }); - } - - /** @test */ - public function votes_calls_correct_url() - { - $this->assertResponse('GET', 'wallets/dummy/votes', function (ArkClient $client) { - return $client->wallets()->votes('dummy'); - }); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \ArkEcosystem\Client\API\Wallets::class; - } -} +it('calls correct url for all', function () { + $this->assertResponse('GET', 'wallets', function (ArkClient $client) { + return $client->wallets()->all(); + }); +}); + +it('calls correct url for top', function () { + $this->assertResponse('GET', 'wallets/top', function (ArkClient $client) { + return $client->wallets()->top(); + }); +}); + +it('calls correct url for get', function () { + $this->assertResponse('GET', 'wallets/dummy', function (ArkClient $client) { + return $client->wallets()->get('dummy'); + }); +}); + +it('calls correct url for transactions', function () { + $this->assertResponse('GET', 'wallets/dummy/transactions', function (ArkClient $client) { + return $client->wallets()->transactions('dummy'); + }); +}); + +it('calls correct url for sent transactions', function () { + $this->assertResponse('GET', 'wallets/dummy/transactions/sent', function (ArkClient $client) { + return $client->wallets()->sentTransactions('dummy'); + }); +}); + +it('calls correct url for received transactions', function () { + $this->assertResponse('GET', 'wallets/dummy/transactions/received', function (ArkClient $client) { + return $client->wallets()->receivedTransactions('dummy'); + }); +}); + +it('calls correct url for votes', function () { + $this->assertResponse('GET', 'wallets/dummy/votes', function (ArkClient $client) { + return $client->wallets()->votes('dummy'); + }); +}); diff --git a/tests/ArkClientTest.php b/tests/ArkClientTest.php index e29a0a7..8194892 100644 --- a/tests/ArkClientTest.php +++ b/tests/ArkClientTest.php @@ -8,56 +8,36 @@ use ArkEcosystem\Client\ArkClient; use GuzzleHttp\HandlerStack; -/** - * @covers \ArkEcosystem\Client\ArkClient - */ -class ArkClientTest extends TestCase -{ - /** @test */ - public function should_call_an_api_if_exists() - { - $client = new ArkClient(['api' => $this->host]); - - $actual = $client->blocks(); - - $this->assertInstanceOf(Blocks::class, $actual); - } - - /** @test */ - public function should_accept_hosts_as_an_array() - { - $hosts = [ - 'api' => 'https://dwallets-evm.mainsailhq.com/api', - 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', - 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', - ]; - - $client = new ArkClient($hosts); - - $this->assertSame($hosts, $client->connection->getHosts()); - } - - /** @test */ - public function does_not_accepts_hosts_array_without_api() - { - $hosts = [ - 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', - 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', - ]; - - $this->expectException(\InvalidArgumentException::class); - - new ArkClient($hosts); - } - - /** @test */ - public function should_accept_custom_handler() - { - $handler = HandlerStack::create(); - - $client = new ArkClient(hostOrHosts: $this->host, handler: $handler); - - // `getConfig` is deprecated but likely never removed: https://github.com/guzzle/guzzle/issues/3114#issuecomment-1627228395 - $this->assertSame($handler, $client->connection->getHttpClient()->getConfig('handler')); - } -} +beforeEach(function () { + $this->host = 'https://dwallets-evm.mainsailhq.com/api'; +}); + +it('calls an api if exists', function () { + $client = new ArkClient(['api' => $this->host]); + $actual = $client->blocks(); + expect($actual)->toBeInstanceOf(Blocks::class); +}); + +it('accepts hosts as an array', function () { + $hosts = [ + 'api' => 'https://dwallets-evm.mainsailhq.com/api', + 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', + 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', + ]; + $client = new ArkClient($hosts); + expect($client->connection->getHosts())->toBe($hosts); +}); + +it('does not accept hosts array without api', function () { + $hosts = [ + 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', + 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', + ]; + new ArkClient($hosts); +})->throws(\InvalidArgumentException::class); + +it('accepts custom handler', function () { + $handler = HandlerStack::create(); + $client = new ArkClient(hostOrHosts: $this->host, handler: $handler); + expect($client->connection->getHttpClient()->getConfig('handler'))->toBe($handler); +}); diff --git a/tests/ClientManagerTest.php b/tests/ClientManagerTest.php index c7d34e9..d332a42 100644 --- a/tests/ClientManagerTest.php +++ b/tests/ClientManagerTest.php @@ -7,89 +7,66 @@ use ArkEcosystem\Client\ClientManager; use ArkEcosystem\Client\Connection; -/** - * @covers \ArkEcosystem\Client\ClientManager - */ -class ClientManagerTest extends TestCase -{ - /** @test */ - public function it_should_create_a_connection() - { - $manager = new ClientManager(); - $manager->connect($this->host, 'dummy-client'); - - $this->assertArrayHasKey('dummy-client', $manager->getClients()); - } - - /** @test */ - public function it_should_throw_if_a_connection_already_exists() - { - $manager = new ClientManager(); - $manager->connect($this->host, 'dummy-client'); - - $this->expectException(\InvalidArgumentException::class); - - $manager->connect($this->host, 'dummy-client'); - } - - /** @test */ - public function it_should_remove_a_connection() - { - $manager = new ClientManager(); - $manager->connect($this->host, 'dummy-client'); - - $this->assertArrayHasKey('dummy-client', $manager->getClients()); - - $manager->disconnect('dummy-client'); - - $this->assertArrayNotHasKey('dummy-client', $manager->getClients()); - } - - /** @test */ - public function it_should_return_a_connection() - { - $manager = new ClientManager(); - $manager->connect($this->host, 'dummy-client'); - - $this->assertInstanceOf(Connection::class, $manager->client('dummy-client')); - } - - /** @test */ - public function it_should_throw_if_a_connection_does_not_exists() - { - $manager = new ClientManager(); - - $this->expectException(\InvalidArgumentException::class); - - $manager->client('dummy-client'); - } - - /** @test */ - public function it_should_return_the_default_connection() - { - $manager = new ClientManager(); - - $this->assertSame($manager->getDefaultClient('main'), 'main'); - } - - /** @test */ - public function it_should_set_the_default_connection() - { - $manager = new ClientManager(); - $manager->setDefaultClient('dummy-client'); - - $this->assertSame($manager->getDefaultClient(), 'dummy-client'); - } - - /** @test */ - public function it_should_return_all_connections() - { - $manager = new ClientManager(); - $manager->connect($this->host, 'dummy-client-1'); - $manager->connect($this->host, 'dummy-client-2'); - $manager->connect($this->host, 'dummy-client-3'); - - $this->assertIsArray($manager->getClients()); - $this->assertCount(3, $manager->getClients()); - } -} +beforeEach(function () { + $this->host = 'http://localhost'; +}); + +it('should create a connection', function () { + $manager = new ClientManager(); + $manager->connect($this->host, 'dummy-client'); + + expect($manager->getClients())->toHaveKey('dummy-client'); +}); + +it('should throw if a connection already exists', function () { + $manager = new ClientManager(); + $manager->connect($this->host, 'dummy-client'); + + $manager->connect($this->host, 'dummy-client'); +})->throws(\InvalidArgumentException::class); + +it('should remove a connection', function () { + $manager = new ClientManager(); + $manager->connect($this->host, 'dummy-client'); + + expect($manager->getClients())->toHaveKey('dummy-client'); + + $manager->disconnect('dummy-client'); + + expect($manager->getClients())->not->toHaveKey('dummy-client'); +}); + +it('should return a connection', function () { + $manager = new ClientManager(); + $manager->connect($this->host, 'dummy-client'); + + expect($manager->client('dummy-client'))->toBeInstanceOf(Connection::class); +}); + +it('should throw if a connection does not exist', function () { + $manager = new ClientManager(); + + $manager->client('dummy-client'); +})->throws(\InvalidArgumentException::class); + +it('should return the default connection', function () { + $manager = new ClientManager(); + + expect($manager->getDefaultClient('main'))->toBe('main'); +}); + +it('should set the default connection', function () { + $manager = new ClientManager(); + $manager->setDefaultClient('dummy-client'); + + expect($manager->getDefaultClient())->toBe('dummy-client'); +}); + +it('should return all connections', function () { + $manager = new ClientManager(); + $manager->connect($this->host, 'dummy-client-1'); + $manager->connect($this->host, 'dummy-client-2'); + $manager->connect($this->host, 'dummy-client-3'); + + expect($manager->getClients())->toBeArray()->toHaveCount(3); +}); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index abf2cd6..0002b58 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -8,76 +8,50 @@ use ArkEcosystem\Client\Connection; use GuzzleHttp\HandlerStack; -/** - * @covers \ArkEcosystem\Client\Connection - */ -class ConnectionTest extends TestCase -{ - /** @test */ - public function should_accept_hosts_as_an_array() - { - $hosts = [ - 'api' => 'https://dwallets-evm.mainsailhq.com/api', - 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', - 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', - ]; - - $client = new Connection($hosts); - - $this->assertSame($hosts, $client->getHosts()); - } - - /** @test */ - public function does_not_accepts_hosts_array_without_api() - { - $hosts = [ - 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', - 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', - ]; - - $this->expectException(\InvalidArgumentException::class); - - new Connection($hosts); - } - - /** @test */ - public function should_accept_custom_handler() - { - $handler = HandlerStack::create(); - - $connection = new Connection(hostOrHosts: $this->host, handler: $handler); - - $this->assertSame($handler, $connection->getHttpClient()->getConfig('handler')); - } - - /** @test */ - public function should_set_host() - { - $client = $this->getClient(); - - $newHost = 'https://new-host.com/api'; - $client->setHost($newHost, 'api'); - - $this->assertSame($newHost, $client->getHosts()['api']); - } - - /** @test */ - public function should_throw_exception_if_host_type_is_invalid() - { - $client = $this->getClient(); - - $this->expectException(\InvalidArgumentException::class); - - $client->setHost('https://new-host.com/api', 'other'); - } - - /** - * Get a new client instance. - * - * @return Connection - */ - private function getClient(): Connection - { - return (new ClientManager())->connect($this->host); - } -} +beforeEach(function () { + $this->host = 'https://dwallets-evm.mainsailhq.com/api'; +}); + +it('accepts hosts as an array', function () { + $hosts = [ + 'api' => 'https://dwallets-evm.mainsailhq.com/api', + 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', + 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', + ]; + + $client = new Connection($hosts); + + expect($client->getHosts())->toBe($hosts); +}); + +it('does not accept hosts array without api', function () { + $hosts = [ + 'transactions' => 'https://dwallets-evm.mainsailhq.com/tx/api', + 'evm' => 'https://dwallets-evm.mainsailhq.com/evm', + ]; + + expect(fn () => new Connection($hosts))->toThrow(\InvalidArgumentException::class); +}); + +it('accepts custom handler', function () { + $handler = HandlerStack::create(); + + $connection = new Connection(hostOrHosts: $this->host, handler: $handler); + + expect($connection->getHttpClient()->getConfig('handler'))->toBe($handler); +}); + +it('sets host', function () { + $client = (new ClientManager())->connect($this->host); + + $newHost = 'https://new-host.com/api'; + $client->setHost($newHost, 'api'); + + expect($client->getHosts()['api'])->toBe($newHost); +}); + +it('throws exception if host type is invalid', function () { + $client = (new ClientManager())->connect($this->host); + + expect(fn () => $client->setHost('https://new-host.com/api', 'other'))->toThrow(\InvalidArgumentException::class); +}); diff --git a/tests/Helpers.php b/tests/Helpers.php deleted file mode 100644 index f25183a..0000000 --- a/tests/Helpers.php +++ /dev/null @@ -1,7 +0,0 @@ -