mercredi 10 juin 2015

What's a good way to test a user factory

I've got a pretty straight forward user factory, except it is depending on an external API call. Since the external call has be authenticated with particular user details I'm not sure if I somehow have to mock the response or the request?

My question is if there are any suggestions on what a good way would be to user test this 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;
}

Aucun commentaire:

Enregistrer un commentaire