Skip to content

Commit

Permalink
Merge pull request #42 from laminas/renovate/psr-http-message-2.x
Browse files Browse the repository at this point in the history
Update dependency psr/http-message to v2
  • Loading branch information
Xerkus authored Dec 6, 2023
2 parents eb3a7d7 + 6023582 commit 7c9f049
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"psr/container": "^1.1.2 || ^2.0.2",
"psr/event-dispatcher": "^1.0",
"psr/http-factory": "^1.0.2",
"psr/http-message": "^1.1.0",
"psr/http-message": "^2.0.0",
"psr/http-server-handler": "^1.0.2",
"psr/http-server-middleware": "^1.0.2",
"psr/log": "^1.1 || ^2.0 || ^3.0"
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/GitHub/Listener/DocsBuildActionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Slack\Domain\SlashResponseMessage;
use App\Slack\Response\SlackResponse;
use App\Slack\SlackClientInterface;
use AppTest\Psr7Helper;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testLogsErrorAndReportsViaSlackIfGitHubRequestFails(int $httpSta

$response = $this->prophesize(ResponseInterface::class);
$response->getStatusCode()->willReturn($httpStatus)->shouldBeCalled();
$response->getBody()->willReturn('error message from github')->shouldBeCalled();
$response->getBody()->willReturn(Psr7Helper::stream('error message from github'))->shouldBeCalled();

$this->githubClient->send($request->reveal())->will([$response, 'reveal'])->shouldBeCalled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\GitHub\Event\GitHubRelease;
use App\GitHub\Listener\GitHubReleaseWebsiteUpdateListener;
use App\HttpClientInterface;
use AppTest\Psr7Helper;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -128,7 +129,7 @@ public function testLogsErrorUpdatingWebsite(): void

$response = $this->prophesize(ResponseInterface::class);
$response->getStatusCode()->willReturn(400);
$response->getBody()->willReturn('');
$response->getBody()->willReturn(Psr7Helper::stream(''));

$this->httpClient->send($request->reveal())->will([$response, 'reveal'])->shouldBeCalled();

Expand Down
7 changes: 4 additions & 3 deletions test/GitHub/Listener/GitHubStatusListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Slack\Domain\WebAPIMessage;
use App\Slack\Response\SlackResponseInterface;
use App\Slack\SlackClientInterface;
use AppTest\Psr7Helper;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -103,7 +104,7 @@ public function testLogsErrorAndNotifiesSlackWithGenericMessageForPullRequestWhe
$ghRequest = $this->prophesize(RequestInterface::class);
$ghResponse = $this->prophesize(ResponseInterface::class);
$ghResponse->getStatusCode()->willReturn(400)->shouldBeCalled();
$ghResponse->getBody()->willReturn('')->shouldBeCalled();
$ghResponse->getBody()->willReturn(Psr7Helper::stream(''))->shouldBeCalled();

$this->githubClient
->createRequest(
Expand Down Expand Up @@ -246,7 +247,7 @@ public function testNotifesSlackWithPullRequestBuildStatusWhenSearchHasAtLeastOn

$ghRequest = $this->prophesize(RequestInterface::class);

$ghResponsePayload = json_encode([
$ghResponsePayload = Psr7Helper::stream(json_encode([
'incomplete_results' => false,
'items' => [
[
Expand All @@ -255,7 +256,7 @@ public function testNotifesSlackWithPullRequestBuildStatusWhenSearchHasAtLeastOn
'html_url' => 'pull-request-url',
],
],
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));

$ghResponse = $this->prophesize(ResponseInterface::class);
$ghResponse->getStatusCode()->willReturn(200)->shouldBeCalled();
Expand Down
3 changes: 2 additions & 1 deletion test/GitHub/Listener/RegisterWebhookListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Slack\Response\SlackResponseInterface;
use App\Slack\SlackClientInterface;
use App\UrlHelper;
use AppTest\Psr7Helper;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -153,7 +154,7 @@ public function testLogsErrorAndNotifiesSlackWhenWebhookRegistrationFails(): voi

$response = $this->prophesize(ResponseInterface::class);
$response->getStatusCode()->willReturn(400)->shouldBeCalled();
$response->getBody()->willReturn('');
$response->getBody()->willReturn(Psr7Helper::stream(''));

$this->github
->createRequest(
Expand Down
28 changes: 28 additions & 0 deletions test/Psr7Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace AppTest;

use Laminas\Diactoros\StreamFactory;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;

class Psr7Helper
{
public static ?StreamFactoryInterface $streamFactory = null;

public static function streamFactory(): StreamFactoryInterface
{
if (self::$streamFactory === null) {
self::$streamFactory = new StreamFactory();
}

return self::$streamFactory;
}

public static function stream(string $content): StreamInterface
{
return self::streamFactory()->createStream($content);
}
}
17 changes: 9 additions & 8 deletions test/Slack/SlackClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Slack\Domain\WebAPIMessage;
use App\Slack\Response\SlackResponse;
use App\Slack\SlackClient;
use AppTest\Psr7Helper;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -59,9 +60,9 @@ public function testSendReturnsReceivedResponseOnSuccess(): void
$response = $this->prophesize(ResponseInterface::class);
$response
->getBody()
->willReturn(json_encode([
->willReturn(Psr7Helper::stream(json_encode([
'ok' => true,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)))
->shouldBeCalled();

$this->httpClient
Expand Down Expand Up @@ -89,10 +90,10 @@ public function testSendLogsResponseOnFailureBeforeReturning(): void
$response->getStatusCode()->willReturn(400)->shouldBeCalled();
$response
->getBody()
->willReturn(json_encode([
->willReturn(Psr7Helper::stream(json_encode([
'ok' => false,
'error' => 'the error message',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)))
->shouldBeCalled();

$this->httpClient
Expand Down Expand Up @@ -180,9 +181,9 @@ public function testSendWebhookMessageMarshalsRequestFromMessageAndSendsIt(): vo
$response = $this->prophesize(ResponseInterface::class);
$response
->getBody()
->willReturn(json_encode([
->willReturn(Psr7Helper::stream(json_encode([
'ok' => true,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)))
->shouldBeCalled();

$this->httpClient
Expand Down Expand Up @@ -257,9 +258,9 @@ public function testSendWebAPIMessageMarshalsRequestFromMessageAndSendsIt(): voi
$response = $this->prophesize(ResponseInterface::class);
$response
->getBody()
->willReturn(json_encode([
->willReturn(Psr7Helper::stream(json_encode([
'ok' => true,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)))
->shouldBeCalled();

$this->httpClient
Expand Down

0 comments on commit 7c9f049

Please sign in to comment.