php - What's a good way to test a user factory that depends on an external API call -


i've got pretty straight forward user factory, except depending on external api call. since external call has authenticated particular user details i'm not sure if somehow have mock response or request?

my question if there suggestions on way user test factory?

thanks!

public static function getuser($id) {     if (!integervalidator::valid($id)) {         throw new validationexception('invalid id provided');     }      $path = "/users/{$id}";     $cache = memcachedmanager::get($path);      if ($cache) {         return $cache;     }      $client = clientfactory::getclient();     $result = $client->get($path);      $user = static::createuserfromresult($result);      memcachedmanager::set($path, $result);      return $user; } 

to make testable need refactor code. can mock dependencies in phpunit , create mock response public api method calls. want achieve, need inject clientfactory method , can use mock object in it's place unit test.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -