Skip to content

Commit 1701264

Browse files
committed
Renamed PingWebHook* to WebHook\Ping*
1 parent b095b9e commit 1701264

File tree

6 files changed

+92
-92
lines changed

6 files changed

+92
-92
lines changed

src/CommandBus/Command/PingWebHookCommand.php renamed to src/CommandBus/Command/WebHook/PingCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php declare(strict_types=1);
22

3-
namespace ApiClients\Client\Github\CommandBus\Command;
3+
namespace ApiClients\Client\Github\CommandBus\Command\WebHook;
44

55
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
66

77
/**
8-
* @Handler("ApiClients\Client\Github\CommandBus\Handler\PingWebHookHandler")
8+
* @Handler("ApiClients\Client\Github\CommandBus\Handler\WebHook\PingHandler")
99
*/
10-
final class PingWebHookCommand
10+
final class PingCommand
1111
{
1212
/**
1313
* @var string

src/CommandBus/Handler/PingWebHookHandler.php

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Handler\WebHook;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\WebHook\PingCommand;
6+
use ApiClients\Foundation\Transport\Service\RequestService;
7+
use Psr\Http\Message\ResponseInterface;
8+
use React\Promise\PromiseInterface;
9+
use RingCentral\Psr7\Request;
10+
11+
final class PingHandler
12+
{
13+
/**
14+
* @var RequestService
15+
*/
16+
private $requestService;
17+
18+
/**
19+
* @param RequestService $requestService
20+
*/
21+
public function __construct(RequestService $requestService)
22+
{
23+
$this->requestService = $requestService;
24+
}
25+
26+
/**
27+
* @param PingCommand $command
28+
* @return PromiseInterface
29+
*/
30+
public function handle(PingCommand $command): PromiseInterface
31+
{
32+
return $this->requestService->request(
33+
new Request(
34+
'POST',
35+
$command->getPingUrl()
36+
)
37+
)->then(function (ResponseInterface $response) {
38+
return $response->getStatusCode() == 204;
39+
});
40+
}
41+
}

src/Resource/Async/WebHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ApiClients\Client\Github\Resource\Async;
44

5-
use ApiClients\Client\Github\CommandBus\Command\PingWebHookCommand;
5+
use ApiClients\Client\Github\CommandBus\Command\WebHook\PingCommand;
66
use ApiClients\Client\Github\Resource\WebHook as BaseWebHook;
77
use React\Promise\PromiseInterface;
88

@@ -16,7 +16,7 @@ public function refresh(): WebHook
1616
public function ping(): PromiseInterface
1717
{
1818
return $this->handleCommand(
19-
new PingWebHookCommand($this->pingUrl())
19+
new PingCommand($this->pingUrl())
2020
);
2121
}
2222
}

tests/CommandBus/Handler/PingWebhookHandlerTest.php

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Tests\Github\CommandBus\Handler\WebHook;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\WebHook\PingCommand;
6+
use ApiClients\Client\Github\CommandBus\Handler\WebHook\PingHandler;
7+
use ApiClients\Foundation\Transport\Service\RequestService;
8+
use ApiClients\Tools\TestUtilities\TestCase;
9+
use RingCentral\Psr7\Request;
10+
use RingCentral\Psr7\Response;
11+
use function React\Promise\resolve;
12+
13+
final class PingHandlerTest extends TestCase
14+
{
15+
public function testCommand()
16+
{
17+
$url = 'url';
18+
19+
$request = new Request('POST', $url);
20+
$response = new Response(204);
21+
22+
$service = $this->prophesize(RequestService::class);
23+
$service->request($request)->shouldBeCalled()->willReturn(resolve($response));
24+
25+
$handler = new PingHandler($service->reveal());
26+
self::assertTrue($this->await($handler->handle(new PingCommand(
27+
$url
28+
))));
29+
}
30+
31+
public function testCommandError()
32+
{
33+
$url = 'url';
34+
35+
$request = new Request('POST', $url);
36+
$response = new Response(500);
37+
38+
$service = $this->prophesize(RequestService::class);
39+
$service->request($request)->shouldBeCalled()->willReturn(resolve($response));
40+
41+
$handler = new PingHandler($service->reveal());
42+
self::assertFalse($this->await($handler->handle(new PingCommand(
43+
$url
44+
))));
45+
}
46+
}

0 commit comments

Comments
 (0)