Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Write some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Sep 11, 2021
1 parent 72fe08d commit 9d6fbb1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"illuminate/http": "~8.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.5",
"tightenco/tlint": "^5.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Solana.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getTransaction(string $transactionSignature): array
return $this->client->call('getTransaction', [$transactionSignature])['result'];
}

public function __call($method, array $params = []): Response
public function __call($method, array $params = []): ?array
{
return $this->client->call($method, $params)->json();
}
Expand Down
2 changes: 1 addition & 1 deletion src/SolanaRpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function call(string $method, array $params = []): Response
return $response;
}

protected function buildRpc(string $method, array $params): array
public function buildRpc(string $method, array $params): array
{
return [
'jsonrpc' => '2.0',
Expand Down
15 changes: 14 additions & 1 deletion tests/SolanaRpcClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,37 @@
namespace Tighten\SolanaPhpSdk\Tests;

use PHPUnit\Framework\TestCase;
use Tighten\SolanaPhpSdk\SolanaRpcClient;

class SolanaRpcClientTest extends TestCase
{
/** @test */
public function it_generates_random_key()
{
$this->markTestIncomplete();
$client = new SolanaRpcClient('abc.com');
$rpc1 = $client->buildRpc('doStuff', []);
$rpc2 = $client->buildRpc('doStuff', []);

$client = new SolanaRpcClient('abc.com');
$rpc3= $client->buildRpc('doStuff', []);
$rpc4 = $client->buildRpc('doStuff', []);

$this->assertEquals($rpc1['id'], $rpc2['id']);
$this->assertEquals($rpc3['id'], $rpc4['id']);
$this->assertNotEquals($rpc1['id'], $rpc4['id']);
}

/** @test */
public function it_validates_response_id()
{
// If we get back a response that doesn't have id set to this->randomKey, throw exception
$this->markTestIncomplete();
}

/** @test */
public function it_throws_exception_for_invalid_methods()
{
// If we get an error: invalid method response back, throw the correct exception
$this->markTestIncomplete();
}
}
40 changes: 40 additions & 0 deletions tests/SolanaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Tighten\SolanaPhpSdk\Tests;

use Illuminate\Http\Client\Response;
use Mockery as M;
use PHPUnit\Framework\TestCase;
use Tighten\SolanaPhpSdk\Solana;
use Tighten\SolanaPhpSdk\SolanaRpcClient;

class SolanaTest extends TestCase
{
/** @test */
public function it_passes_undefined_calls_through_magically()
{
$client = M::mock(SolanaRpcClient::class);
$client->shouldReceive('call')
->with('abcdefg', [])
->times(1)
->andReturn($this->fakeResponse());

$solana = new Solana($client);
$solana->abcdefg();

M::close();

$this->assertTrue(true); // Keep PHPUnit from squawking; there must be a better way?
}

protected function fakeResponse(): Response
{
return new Response(new class
{
public function getBody()
{
return 'i am a body yay';
}
});
}
}

0 comments on commit 9d6fbb1

Please sign in to comment.