From f1aebc65a68be6c414a169a5cb3b27ce6a2c3984 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 19 Dec 2017 10:52:36 +0800 Subject: [PATCH] Split web3 tests --- test/unit/Web3ApiTest.php | 105 ++++++++++++++++++++++++++++++++++++ test/unit/Web3BatchTest.php | 62 +++++++++++++++++++++ test/unit/Web3Test.php | 87 ------------------------------ 3 files changed, 167 insertions(+), 87 deletions(-) create mode 100644 test/unit/Web3ApiTest.php create mode 100644 test/unit/Web3BatchTest.php diff --git a/test/unit/Web3ApiTest.php b/test/unit/Web3ApiTest.php new file mode 100644 index 0000000..f62105c --- /dev/null +++ b/test/unit/Web3ApiTest.php @@ -0,0 +1,105 @@ +web3; + + $web3->clientVersion(function ($err, $version) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($version->result)) { + $this->assertTrue(is_string($version->result)); + } else { + $this->fail($version->error->message); + } + }); + } + + /** + * testSha3 + * + * @return void + */ + public function testSha3() + { + $web3 = $this->web3; + + $web3->sha3($this->testHex, function ($err, $hash) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($hash->result)) { + $this->assertEquals($hash->result, $this->testHash); + } else { + $this->fail($hash->error->message); + } + }); + } + + /** + * testWrongParam + * + * @return void + */ + public function testWrongParam() + { + $this->expectException(RuntimeException::class); + + $web3 = $this->web3; + + $web3->sha3('hello world', function ($err, $hash) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($hash->result)) { + $this->assertTrue(true); + } else { + $this->fail($hash->error->message); + } + }); + } +} \ No newline at end of file diff --git a/test/unit/Web3BatchTest.php b/test/unit/Web3BatchTest.php new file mode 100644 index 0000000..0dd7e1a --- /dev/null +++ b/test/unit/Web3BatchTest.php @@ -0,0 +1,62 @@ +web3; + + $web3->batch(true); + $web3->clientVersion(); + $web3->sha3($this->testHex); + + $web3->provider->execute(function ($err, $data) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue(is_string($data[0]->result)); + $this->assertEquals($data[1]->result, $this->testHash); + }); + } +} \ No newline at end of file diff --git a/test/unit/Web3Test.php b/test/unit/Web3Test.php index 0e98e3c..acc0b8e 100644 --- a/test/unit/Web3Test.php +++ b/test/unit/Web3Test.php @@ -53,70 +53,6 @@ class Web3Test extends TestCase $this->assertTrue($web3->net instanceof Net); } - /** - * testClientVersion - * - * @return void - */ - public function testClientVersion() - { - $web3 = $this->web3; - - $web3->clientVersion(function ($err, $version) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - if (isset($version->result)) { - $this->assertTrue(is_string($version->result)); - } else { - $this->fail($version->error->message); - } - }); - } - - /** - * testSha3 - * - * @return void - */ - public function testSha3() - { - $web3 = $this->web3; - - $web3->sha3($this->testHex, function ($err, $hash) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - if (isset($hash->result)) { - $this->assertEquals($hash->result, $this->testHash); - } else { - $this->fail($hash->error->message); - } - }); - } - - /** - * testBatch - * - * @return void - */ - public function testBatch() - { - $web3 = $this->web3; - - $web3->batch(true); - $web3->clientVersion(); - $web3->sha3($this->testHex); - - $web3->provider->execute(function ($err, $data) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - $this->assertTrue(is_string($data[0]->result)); - $this->assertEquals($data[1]->result, $this->testHash); - }); - } - /** * testUnallowedMethod * @@ -139,27 +75,4 @@ class Web3Test extends TestCase } }); } - - /** - * testWrongParam - * - * @return void - */ - public function testWrongParam() - { - $this->expectException(RuntimeException::class); - - $web3 = $this->web3; - - $web3->sha3('hello world', function ($err, $hash) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - if (isset($hash->result)) { - $this->assertTrue(true); - } else { - $this->fail($hash->error->message); - } - }); - } } \ No newline at end of file