diff --git a/examples/licenses-async.php b/examples/licenses-async.php new file mode 100644 index 0000000000..e98387d68c --- /dev/null +++ b/examples/licenses-async.php @@ -0,0 +1,18 @@ +licenses()->subscribeCallback(function (LicenseInterface $license) { + resource_pretty_print($license); +}, 'display_throwable'); + +$loop->run(); diff --git a/src/AsyncClient.php b/src/AsyncClient.php index 407a62f045..f19b4d11e5 100644 --- a/src/AsyncClient.php +++ b/src/AsyncClient.php @@ -76,6 +76,11 @@ public function myOrganizations(): Observable return unwrapObservableFromPromise($this->client->handle(new Command\MyOrganizationsCommand())); } + public function licenses(): Observable + { + return unwrapObservableFromPromise($this->client->handle(new Command\LicensesCommand())); + } + /** * @return RateLimitState */ diff --git a/src/AsyncClientInterface.php b/src/AsyncClientInterface.php index 914998a871..51b20059e7 100644 --- a/src/AsyncClientInterface.php +++ b/src/AsyncClientInterface.php @@ -17,5 +17,7 @@ public function whoami(): PromiseInterface; public function myOrganizations(): Observable; + public function licenses(): Observable; + public function getRateLimitState(): RateLimitState; } diff --git a/src/CommandBus/Command/LicensesCommand.php b/src/CommandBus/Command/LicensesCommand.php new file mode 100644 index 0000000000..81f618fb4d --- /dev/null +++ b/src/CommandBus/Command/LicensesCommand.php @@ -0,0 +1,12 @@ +service = $service; + } + + /** + * @param MyOrganizationsCommand $command + * @return PromiseInterface + */ + public function handle(LicensesCommand $command): PromiseInterface + { + return resolve( + $this->service->iterate( + 'licenses', + '', + LicenseInterface::HYDRATE_CLASS + ) + ); + } +} diff --git a/tests/CommandBus/Handler/LicensesHandlerTest.php b/tests/CommandBus/Handler/LicensesHandlerTest.php new file mode 100644 index 0000000000..f66b4d5407 --- /dev/null +++ b/tests/CommandBus/Handler/LicensesHandlerTest.php @@ -0,0 +1,34 @@ +prophesize(LicenseInterface::class)->reveal(); + + $command = new LicensesCommand(); + + $service = $this->prophesize(FetchAndIterateService::class); + $service->iterate( + 'licenses', + '', + LicenseInterface::HYDRATE_CLASS + )->shouldBeCalled()->willReturn(Observable::fromArray([$license])); + + $licensesHandler = new LicensesHandler( + $service->reveal() + ); + + self::assertSame($license, $this->await(Promise::fromObservable($this->await($licensesHandler->handle($command))))); + } +}