- it("should handle a few requests in parallel", function() {
- $this->api->users->m6w6()->then(function($m6w6) use(&$count, &$errors) {
- foreach ($m6w6 as $key => $val) {
- switch ($key) {
- case "html_url":
- case "avatar_url":
- break;
- default:
- if (substr($key, -4) === "_url") {
- $val->get()->then(function() use(&$count) {
- ++$count;
- })->otherwise(function($error) use(&$errors) {
- $errors[] = (string) $error;
- });
- }
+ describe("Cache", function() {
+ it("should cache successive calls", function() {
+ $cache = new API\Call\Cache\Service\Hollow();
+ $this->api->users->m6w6(null, null, $cache)->then(function($json) use(&$m6w6) {
+ $m6w6 = $json;
+ }, function($error) use(&$errors) {
+ $errors[] = (string) $error;
+ });
+
+ $this->api->send();
+
+ $data = $cache->getStorage();
+ $this->api->users->m6w6(null, null, $cache)->then(function($json) use(&$m6w6_) {
+ $m6w6_ = $json;
+ }, function($error) use(&$errors) {
+ $errors[] = (string) $error;
+ });
+
+ $this->api->send();
+
+ expect($errors)->to->be->empty;
+ expect($m6w6->login)->to->loosely->equal("m6w6");
+ expect($m6w6_->login)->to->loosely->equal("m6w6");
+ expect($data)->to->equal($cache->getStorage());
+ expect(count($cache->getStorage()))->to->equal(1);
+ });
+ xit("should refresh stale cache entries");
+ });
+
+ describe("Generators", function() {
+ it("should iterate over a generator of promises", function() {
+ ($this->api)(function($api) use(&$gists_count, &$files_count) {
+ $gists = yield $api->users->m6w6->gists();
+ $gists_count = count($gists);
+ foreach ($gists as $gist) {
+ $files_count += count($gist->files);