This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CouchDB | |
{ | |
/** | |
* @param string $id | |
* | |
* @return stdClass | |
*/ | |
public function getDocument($id) | |
{ | |
$uri = 'http://server:5984/db/' . $id; | |
$response = $this->makeRequest($uri); | |
return $this->parseResponse($response); | |
} | |
/** | |
* @param string $uri | |
*/ | |
protected function makeRequest($uri) | |
{ | |
// use an http client to do a request | |
$response = my_super_duper_client($uri); | |
} | |
/** | |
* @param string $response Most likely JSON. | |
* | |
* @return stdClass | |
* @throws RuntimeException On 404. | |
*/ | |
protected function parseResponse($response) | |
{ | |
$obj = json_decode($response); | |
if (isset($obj->error)) { | |
throw new RuntimeException("Not found: {$obj->reason}", 404); | |
} | |
return $obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
btw this works because phpunit mock builder internally creates a new class that extends the original class and then overloads the stubbed methods. So it works for public/protected methods, but f. e. not for final methods.