ShhBatchTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use Test\TestCase;
  5. class ShhBatchTest extends TestCase
  6. {
  7. /**
  8. * shh
  9. *
  10. * @var Web3\Shh
  11. */
  12. protected $shh;
  13. /**
  14. * setUp
  15. *
  16. * @return void
  17. */
  18. public function setUp(): void
  19. {
  20. parent::setUp();
  21. $this->shh = $this->web3->shh;
  22. }
  23. /**
  24. * testBatch
  25. *
  26. * @return void
  27. */
  28. public function testBatch()
  29. {
  30. $shh = $this->shh;
  31. $shh->batch(true);
  32. $shh->version();
  33. $shh->version();
  34. $shh->provider->execute(function ($err, $data) {
  35. if ($err !== null) {
  36. return $this->fail($err->getMessage());
  37. }
  38. $this->assertTrue(is_string($data[0]));
  39. $this->assertTrue(is_string($data[1]));
  40. $this->assertEquals($data[0], $data[1]);
  41. });
  42. }
  43. /**
  44. * testBatchAsync
  45. *
  46. * @return void
  47. */
  48. public function testBatchAsync()
  49. {
  50. $shh = $this->shh;
  51. $shh->provider = $this->asyncHttpProvider;
  52. $shh->batch(true);
  53. $shh->version();
  54. $shh->version();
  55. // should return reactphp promise
  56. $promise = $shh->provider->execute(function ($err, $data) {
  57. if ($err !== null) {
  58. return $this->fail($err->getMessage());
  59. }
  60. $this->assertTrue(is_string($data[0]));
  61. $this->assertTrue(is_string($data[1]));
  62. $this->assertEquals($data[0], $data[1]);
  63. });
  64. $this->assertTrue($promise instanceof \React\Promise\PromiseInterface);
  65. \React\Async\await($promise);
  66. }
  67. }