4 use React\Promise\PromiseInterface
;
6 describe("API", function() {
8 it("should return API on property access", function() {
9 expect($this->api
->users
)->to
->be
->instanceof(API
::class);
12 it("should return a clone on property access", function() {
13 expect($this->api
->users
)->to
->not
->equal($this->api
);
16 it("should return PromiseInterface on function call", function() {
17 expect($this->api
->users
->m6w6())->to
->be
->instanceof(PromiseInterface
::class);
20 it("should successfully request /users/m6w6", function() {
21 $this->api
->users
->m6w6()->then(function($json) use(&$m6w6) {
23 })->otherwise(function($error) use(&$errors) {
24 $errors[] = (string) $error;
29 expect($errors)->to
->be
->empty;
30 expect($m6w6->login
)->to
->loosely
->equal("m6w6");
33 it("should return the count of followers when accessing /users/m6w6->followers", function() {
34 $this->api
->users
->m6w6()->then(function($m6w6) use(&$followers) {
35 $followers = $m6w6->followers
;
36 })->otherwise(function($error) use(&$errors) {
37 $errors[] = (string) $error;
42 expect($errors)->to
->be
->empty();
43 expect($followers->export())->to
->be
->an("integer");
46 it("should fetch followers_url when accessing /users/m6w6->followers_url", function() {
47 $this->api
->users
->m6w6()->then(function($m6w6) use(&$followers, &$errors) {
48 $m6w6->followers_url()->then(function($json) use(&$followers) {
50 })->otherwise(function($error) use(&$errors) {
51 $errors[] = (string) $error;
53 })->otherwise(function($error) use(&$errors) {
54 $errors[] = (string) $error;
59 expect($errors)->to
->be
->empty;
60 expect($followers->export())->to
->be
->an("array");
61 expect(count($followers))->to
->be
->above(0);
64 it("should handle a few requests in parallel", function() {
65 $this->api
->users
->m6w6()->then(function($m6w6) use(&$count, &$errors) {
66 foreach ($m6w6 as $key => $val) {
72 if (substr($key, -4) === "_url") {
73 $val->get()->then(function() use(&$count) {
75 })->otherwise(function($error) use(&$errors) {
76 $errors[] = (string) $error;
81 })->otherwise(function($error) use(&$errors) {
82 $errors[] = (string) $error;
87 expect($errors)->to
->be
->empty;
88 expect($count)->to
->be
->above(2);