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

Commit

Permalink
Drop Facade usage for non-Laravel users
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Nov 23, 2021
1 parent a692588 commit f6c1f5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/SolanaRpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tighten\SolanaPhpSdk;

use Illuminate\Http\Client\Factory as HttpFactory;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Tighten\SolanaPhpSdk\Exceptions\GenericException;
use Tighten\SolanaPhpSdk\Exceptions\InvalidIdResponseException;
use Tighten\SolanaPhpSdk\Exceptions\MethodNotFoundException;
Expand Down Expand Up @@ -58,7 +58,7 @@ public function __construct(string $endpoint)
*/
public function call(string $method, array $params = [])
{
$response = Http::acceptJson()->post(
$response = (new HttpFactory())->acceptJson()->post(
$this->endpoint,
$this->buildRpc($method, $params)
)->throw();
Expand Down
31 changes: 2 additions & 29 deletions tests/Unit/SolanaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,14 @@

namespace Tighten\SolanaPhpSdk\Tests\Unit;

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Tighten\SolanaPhpSdk\Exceptions\AccountNotFoundException;
use Tighten\SolanaPhpSdk\Exceptions\GenericException;
use Tighten\SolanaPhpSdk\Programs\SystemProgram;
use Tighten\SolanaPhpSdk\SolanaRpcClient;
use Tighten\SolanaPhpSdk\Tests\TestCase;

class SolanaTest extends TestCase
{
/** @test */
public function it_passes_undefined_calls_through_magically()
{
$client = new SolanaRpcClient(SolanaRpcClient::DEVNET_ENDPOINT);
$expectedIdInHttpResponse = $client->getRandomKey();
$solana = new SystemProgram($client);

Http::fake([
SolanaRpcClient::DEVNET_ENDPOINT => Http::response([
'jsonrpc' => '2.0',
'result' => [], // not important
'id' => $expectedIdInHttpResponse,
]),
]);

$solana->abcdefg([
'param1' => 123,
]);

Http::assertSent(function (Request $request) {
return $request->url() == SolanaRpcClient::DEVNET_ENDPOINT &&
$request['method'] == 'abcdefg' &&
$request['params'] == ['param1' => 123];
});
}

/** @test */
public function it_will_throw_exception_when_rpc_account_response_is_null()
{
Expand All @@ -56,7 +29,7 @@ public function it_will_throw_exception_when_rpc_account_response_is_null()
]),
]);

$this->expectException(AccountNotFoundException::class);
$this->expectException(GenericException::class);
$solana->getAccountInfo('abc123');
}
}

0 comments on commit f6c1f5d

Please sign in to comment.