/** * @return Blockchain */ public function testGet() { $request = $this->operation['response']['body']; $blockchain = new Blockchain($request); $result = Blockchain::get($blockchain->getName(), array(), $this->apiContext, $this->mockBlockCypherRestCall); $this->assertNotNull($result); $this->assertInstanceOf('\\BlockCypher\\Api\\Blockchain', $result); // Assert only immutable values. $this->assertEquals($blockchain->getName(), $result->getName()); return $result; }
/** * Obtain the Blockchain resource for the given identifier. * * @param string $name * @param array $params Parameters * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Blockchain */ public function get($name, $params = array(), $apiContext = null, $restCall = null) { ArgumentValidator::validate($name, 'name'); ArgumentGetParamsValidator::validate($params, 'params'); $allowedParams = array(); $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams); if (strpos($name, '.') === FALSE) { throw new \InvalidArgumentException("Invalid chain name {$name}. FORMAT: COIN.chain e.g. BTC.main"); } $payLoad = ""; if ($apiContext === null) { $apiContext = $this->getApiContext(); } $version = $apiContext->getVersion(); list($coin, $chain) = explode(".", $name); $coin = strtolower($coin); $json = $this->executeCall("/{$version}/{$coin}/{$chain}" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad, null, $apiContext, $restCall); $ret = new Blockchain(); $ret->fromJson($json); return $ret; }
/** * @dataProvider mockProviderGetParamsValidation * @param Blockchain $obj * @param $mockApiContext * @param $params * @expectedException \InvalidArgumentException */ public function testGetParamsValidationForParams($obj, $mockApiContext, $params) { $mockBlockCypherRestCall = $this->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock(); $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue(BlockchainTest::getJson())); /** @noinspection PhpUndefinedVariableInspection */ /** @noinspection PhpParamsInspection */ $obj->get("BTC.main", $params, $mockApiContext, $mockBlockCypherRestCall); }