diff --git a/test/unit/NetApiTest.php b/test/unit/NetApiTest.php new file mode 100644 index 0000000..4111a93 --- /dev/null +++ b/test/unit/NetApiTest.php @@ -0,0 +1,114 @@ +net = $this->web3->net; + } + + /** + * testVersion + * + * @return void + */ + public function testVersion() + { + $net = $this->net; + + $net->version(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); + } + }); + } + + /** + * testPeerCount + * + * @return void + */ + public function testPeerCount() + { + $net = $this->net; + + $net->peerCount(function ($err, $count) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($count->result)) { + $this->assertTrue(is_string($count->result)); + } else { + $this->fail($count->error->message); + } + }); + } + + /** + * testListening + * + * @return void + */ + public function testListening() + { + $net = $this->net; + + $net->listening(function ($err, $net) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($net->result)) { + $this->assertTrue(is_bool($net->result)); + } else { + $this->fail($net->error->message); + } + }); + } + + /** + * testUnallowedMethod + * + * @return void + */ + public function testUnallowedMethod() + { + $this->expectException(RuntimeException::class); + + $net = $this->net; + + $net->hello(function ($err, $hello) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($hello->result)) { + $this->assertTrue(true); + } else { + $this->fail($hello->error->message); + } + }); + } +} \ No newline at end of file diff --git a/test/unit/NetBatchTest.php b/test/unit/NetBatchTest.php new file mode 100644 index 0000000..97f1d99 --- /dev/null +++ b/test/unit/NetBatchTest.php @@ -0,0 +1,50 @@ +net = $this->web3->net; + } + + /** + * testBatch + * + * @return void + */ + public function testBatch() + { + $net = $this->net; + + $net->batch(true); + $net->version(); + $net->listening(); + + $net->provider->execute(function ($err, $data) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue(is_string($data[0]->result)); + $this->assertTrue(is_bool($data[1]->result)); + }); + } +} \ No newline at end of file diff --git a/test/unit/NetTest.php b/test/unit/NetTest.php index 5b0b283..ef25306 100644 --- a/test/unit/NetTest.php +++ b/test/unit/NetTest.php @@ -4,6 +4,8 @@ namespace Test\Unit; use RuntimeException; use Test\TestCase; +use Web3\Providers\HttpProvider; +use Web3\RequestManagers\RequestManager; class NetTest extends TestCase { @@ -27,110 +29,15 @@ class NetTest extends TestCase } /** - * testVersion - * - * @return void - */ - public function testVersion() - { - $net = $this->net; - - $net->version(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); - } - }); - } - - /** - * testPeerCount - * - * @return void - */ - public function testPeerCount() - { - $net = $this->net; - - $net->peerCount(function ($err, $count) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - if (isset($count->result)) { - $this->assertTrue(is_string($count->result)); - } else { - $this->fail($count->error->message); - } - }); - } - - /** - * testListening - * - * @return void - */ - public function testListening() - { - $net = $this->net; - - $net->listening(function ($err, $net) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - if (isset($net->result)) { - $this->assertTrue(is_bool($net->result)); - } else { - $this->fail($net->error->message); - } - }); - } - - /** - * testBatch + * testInstance * * @return void */ - public function testBatch() + public function testInstance() { $net = $this->net; - $net->batch(true); - $net->version(); - $net->listening(); - - $net->provider->execute(function ($err, $data) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - $this->assertTrue(is_string($data[0]->result)); - $this->assertTrue(is_bool($data[1]->result)); - }); - } - - /** - * testUnallowedMethod - * - * @return void - */ - public function testUnallowedMethod() - { - $this->expectException(RuntimeException::class); - - $net = $this->net; - - $net->hello(function ($err, $hello) { - if ($err !== null) { - return $this->fail($err->getMessage()); - } - if (isset($hello->result)) { - $this->assertTrue(true); - } else { - $this->fail($hello->error->message); - } - }); + $this->assertTrue($net->provider instanceof HttpProvider); + $this->assertTrue($net->provider->requestManager instanceof RequestManager); } } \ No newline at end of file diff --git a/test/unit/Web3ApiTest.php b/test/unit/Web3ApiTest.php index f62105c..bbd6de5 100644 --- a/test/unit/Web3ApiTest.php +++ b/test/unit/Web3ApiTest.php @@ -4,11 +4,6 @@ namespace Test\Unit; use RuntimeException; use Test\TestCase; -use Web3\Web3; -use Web3\Eth; -use Web3\Net; -use Web3\Providers\HttpProvider; -use Web3\RequestManagers\RequestManager; class Web3ApiTest extends TestCase { diff --git a/test/unit/Web3BatchTest.php b/test/unit/Web3BatchTest.php index 0dd7e1a..56dfab8 100644 --- a/test/unit/Web3BatchTest.php +++ b/test/unit/Web3BatchTest.php @@ -4,11 +4,6 @@ namespace Test\Unit; use RuntimeException; use Test\TestCase; -use Web3\Web3; -use Web3\Eth; -use Web3\Net; -use Web3\Providers\HttpProvider; -use Web3\RequestManagers\RequestManager; class Web3BatchTest extends TestCase {