HttpProviderTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use Test\TestCase;
  5. use Web3\RequestManagers\HttpRequestManager;
  6. use Web3\Providers\HttpProvider;
  7. use Web3\Methods\Web3\ClientVersion;
  8. class HttpProviderTest extends TestCase
  9. {
  10. /**
  11. * testSend
  12. *
  13. * @return void
  14. */
  15. public function testSend()
  16. {
  17. $requestManager = new HttpRequestManager($this->testHost);
  18. $provider = new HttpProvider($requestManager);
  19. $method = new ClientVersion('web3_clientVersion', []);
  20. $provider->send($method, function ($err, $version) {
  21. if ($err !== null) {
  22. $this->fail($err->getMessage());
  23. }
  24. $this->assertTrue(is_string($version));
  25. });
  26. }
  27. /**
  28. * testBatch
  29. *
  30. * @return void
  31. */
  32. public function testBatch()
  33. {
  34. $requestManager = new HttpRequestManager($this->testHost);
  35. $provider = new HttpProvider($requestManager);
  36. $method = new ClientVersion('web3_clientVersion', []);
  37. $callback = function ($err, $data) {
  38. if ($err !== null) {
  39. $this->fail($err->getMessage());
  40. }
  41. $this->assertEquals($data[0], $data[1]);
  42. };
  43. try {
  44. $provider->execute($callback);
  45. } catch (RuntimeException $err) {
  46. $this->assertTrue($err->getMessage() !== true);
  47. }
  48. $provider->batch(true);
  49. $provider->send($method, null);
  50. $provider->send($method, null);
  51. $provider->execute($callback);
  52. }
  53. }