function testWrongMethodRequest() { $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/github/users/gonzalo123')); $request->expects($this->any())->method('getQueryString')->will($this->returnValue('')); $request->expects($this->any())->method('getMethod')->will($this->returnValue('POST')); $curl = $this->getMock('RestProxy\\CurlWrapper'); $curl->expects($this->any())->method('doGet')->will($this->returnValue('{"followers":40,"html_url":"https://github.com/gonzalo123","type":"User","company":null,"public_repos":51,"following":1,"blog":"http://gonzalo123.wordpress.com/","location":null,"avatar_url":"https://secure.gravatar.com/avatar/6aa6fe484173856751a24135b4dd4586?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"6aa6fe484173856751a24135b4dd4586","public_gists":7,"login":"******","name":"Gonzalo Ayuso","email":null,"hireable":false,"url":"https://api.github.com/users/gonzalo123","created_at":"2008-12-08T14:17:03Z","id":39072,"bio":null}')); $proxy = new RestProxy($request, $curl); $proxy->register('github', 'https://api.github.com'); $proxy->run(); $output = json_decode($proxy->getContent(), TRUE); $this->assertNotEquals(40, $output['followers']); $this->assertNotEquals('http://gonzalo123.wordpress.com/', $output['blog']); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; use RestProxy\RestProxy; use RestProxy\CurlWrapper; // Example for additional Curl request headers and additional curl options for all requests $requestHeaders = ['Content-Type:application/json', 'Authorization: Basic ' . base64_encode("username:password")]; $curlOptions = [CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0]; $proxy = new RestProxy(Request::createFromGlobals(), new CurlWrapper($requestHeaders, $curlOptions)); $proxy->register('github/example/With/2/destinations', 'https://api.github.com'); $proxy->register('github', 'https://api.github.com'); $proxy->run(); foreach ($proxy->getHeaders() as $header) { header($header); } echo $proxy->getContent();