Example #1
0
 /**
  * @group unit
  */
 public function testFunction__ftven_sdk_api__for_method_unknown__throw_exception()
 {
     $apiMock = $this->getMock('Ftven\\Sdk\\ApiInterface', ['getName', 'setSdk', 'getSdk'], [], '', false);
     $apiMock->expects($this->any())->method('getName')->will($this->returnValue('api-mock'));
     ftven_sdk()->addApi($apiMock);
     $this->setExpectedException('RuntimeException', "Method 'unknownMethod' does not exist in API 'api-mock'", 404);
     ftven_sdk_api('api-mock', 'unknownMethod');
 }
Example #2
0
/**
 * @param string|null $name
 * @param string|null $method
 *
 * @return ApiInterface|mixed
 *
 * @throws \RuntimeException
 */
function ftven_sdk_api($name = null, $method = null)
{
    if (null === $name) {
        return ftven_sdk()->getAvailableApis();
    }
    $args = func_get_args();
    $name = array_shift($args);
    $api = ftven_sdk()->getApi($name);
    if (0 === count($args)) {
        return $api;
    }
    $method = array_shift($args);
    if (false === method_exists($api, $method)) {
        throw new \RuntimeException(sprintf("Method '%s' does not exist in API '%s'", $method, $name), 404);
    }
    return call_user_func_array([$api, $method], $args);
}