From 5d19c4659c0b8ce44de44c444858eca21a12d95a Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 19 Dec 2017 11:39:24 +0800 Subject: [PATCH] Web3 setProvider test --- test/unit/Web3ApiTest.php | 23 +++++++++++++++++++++++ test/unit/Web3Test.php | 20 ++++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/test/unit/Web3ApiTest.php b/test/unit/Web3ApiTest.php index bbd6de5..7cb6c22 100644 --- a/test/unit/Web3ApiTest.php +++ b/test/unit/Web3ApiTest.php @@ -75,6 +75,29 @@ class Web3ApiTest extends TestCase }); } + /** + * testUnallowedMethod + * + * @return void + */ + public function testUnallowedMethod() + { + $this->expectException(RuntimeException::class); + + $web3 = $this->web3; + + $web3->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); + } + }); + } + /** * testWrongParam * diff --git a/test/unit/Web3Test.php b/test/unit/Web3Test.php index acc0b8e..9edd367 100644 --- a/test/unit/Web3Test.php +++ b/test/unit/Web3Test.php @@ -9,6 +9,7 @@ use Web3\Eth; use Web3\Net; use Web3\Providers\HttpProvider; use Web3\RequestManagers\RequestManager; +use Web3\RequestManagers\HttpRequestManager; class Web3Test extends TestCase { @@ -54,25 +55,16 @@ class Web3Test extends TestCase } /** - * testUnallowedMethod + * testSetProvider * * @return void */ - public function testUnallowedMethod() + public function testSetProvider() { - $this->expectException(RuntimeException::class); - $web3 = $this->web3; + $requestManager = new HttpRequestManager('http://localhost:8545'); + $web3->provider = new HttpProvider($requestManager); - $web3->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->assertEquals($web3->provider->requestManager->host, 'http://localhost:8545'); } } \ No newline at end of file