web3.php/test/unit/NetTest.php
2018-02-07 11:45:08 +08:00

76 lines
1.5 KiB
PHP

<?php
namespace Test\Unit;
use RuntimeException;
use Test\TestCase;
use Web3\Providers\HttpProvider;
use Web3\RequestManagers\RequestManager;
use Web3\RequestManagers\HttpRequestManager;
use Web3\Net;
class NetTest extends TestCase
{
/**
* net
*
* @var Web3\Net
*/
protected $net;
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->net = $this->web3->net;
}
/**
* testInstance
*
* @return void
*/
public function testInstance()
{
$net = new Net($this->testHost);
$this->assertTrue($net->provider instanceof HttpProvider);
$this->assertTrue($net->provider->requestManager instanceof RequestManager);
}
/**
* testSetProvider
*
* @return void
*/
public function testSetProvider()
{
$net = $this->net;
$requestManager = new HttpRequestManager('http://localhost:8545');
$net->provider = new HttpProvider($requestManager);
$this->assertEquals($net->provider->requestManager->host, 'http://localhost:8545');
$net->provider = null;
$this->assertEquals($net->provider->requestManager->host, 'http://localhost:8545');
}
/**
* testCallThrowRuntimeException
*
* @return void
*/
public function testCallThrowRuntimeException()
{
$this->expectException(RuntimeException::class);
$net = new Net(null);
$net->version();
}
}