Skip to content

Commit 4abd36a

Browse files
committed
Update tests to remove the rest of the iam-portal dependencies. Add the guzzlehttp library to require-dev. SnsException no longer extends IamPortal exceptions.
1 parent 6971c52 commit 4abd36a

File tree

4 files changed

+220
-27
lines changed

4 files changed

+220
-27
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"require-dev" : {
1313
"phpunit/phpunit": "^9.5",
14-
"roave/security-advisories": "dev-latest"
14+
"roave/security-advisories": "dev-latest",
15+
"guzzlehttp/guzzle": "^7.2"
1516
},
1617
"autoload-dev": {
1718
"psr-4": {

composer.lock

Lines changed: 210 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SnsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
namespace MiamiOH\SnsHandler;
55

6-
class SnsException extends \MiamiOH\IamPortal\IamPortalException
6+
class SnsException extends \Exception
77
{
88
}

tests/Unit/SnsBrokerTest.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use MiamiOH\SnsHandler\SnsMessage;
1111
use MiamiOH\SnsHandler\SnsTopicMapper;
1212
use MiamiOH\SnsHandler\SnsUnknownTopicArnException;
13-
use MiamiOH\IamPortal\Util\HttpClient;
14-
use MiamiOH\IamPortal\Util\HttpResponse;
1513
use PHPUnit\Framework\MockObject\MockObject;
1614
use Tests\MiamiOH\SnsHandler\MakesSnsTests;
1715
use Tests\MiamiOH\SnsHandler\TestCase;
@@ -30,8 +28,7 @@ class SnsBrokerTest extends TestCase
3028
private $topicMapper;
3129
/** @var MessageValidator|MockObject */
3230
private $validator;
33-
/** @var HttpClient|MockObject */
34-
private $httpClient;
31+
3532

3633
public function setUp(): void
3734
{
@@ -44,7 +41,6 @@ public function setUp(): void
4441
);
4542

4643
$this->validator = $this->createMock(MessageValidator::class);
47-
// $this->httpClient = $this->createMock(HttpClient::class);
4844

4945
$this->broker = new SnsBroker($this->topicMapper, $this->validator);
5046
}
@@ -92,11 +88,8 @@ public function testConfirmsSubscriptionUsingSubscribeUrl(): void
9288
'Type' => SnsMessage::SUBSCRIBE_TYPE,
9389
'SubscribeURL' => 'https://aws.amazon.com/subscribe/123',
9490
]));
95-
Http::fake();
96-
// Http::fake(['https://aws.amazon.com/subscribe/123' => Http::response([], 200)]);
97-
// $this->httpClient->expects($this->once())->method('get')
98-
// ->with($this->equalTo('https://aws.amazon.com/subscribe/123'))
99-
// ->willReturn($this->makeHttpResponseMock());
91+
92+
Http::fake(['https://aws.amazon.com/subscribe/123' => Http::response([], 200,[])]);
10093

10194
$this->broker->handleRequest($request);
10295
}
@@ -109,12 +102,10 @@ public function testThrowsExceptionIfConfirmSubscriptionFails(): void
109102
'Type' => SnsMessage::SUBSCRIBE_TYPE,
110103
'SubscribeURL' => 'https://aws.amazon.com/subscribe/123',
111104
]));
112-
113-
$response = $this->makeHttpResponseMock(404);
114-
115-
$this->httpClient->expects($this->once())->method('get')
116-
->with($this->equalTo('https://aws.amazon.com/subscribe/123'))
117-
->willReturn($response);
105+
106+
Http::fake([
107+
'https://aws.amazon.com/subscribe/123' => Http::response([], 404, [])
108+
]);
118109

119110
$this->expectException(SnsConfirmSubscriptionException::class);
120111
$this->expectExceptionMessage('Subscription confirmation for arn:aws:sns:us-west-2:123456789012:MyTopic failed with status 404');
@@ -150,12 +141,4 @@ public function testValidatesSnsMessage(): void
150141
$this->broker->handleRequest($request);
151142
}
152143

153-
private function makeHttpResponseMock(int $status = 200): HttpResponse
154-
{
155-
$response = $this->createMock(HttpResponse::class);
156-
$response->method('status')->willReturn($status);
157-
$response->method('successful')->willReturn($status >= 200 && $status < 400);
158-
159-
return $response;
160-
}
161144
}

0 commit comments

Comments
 (0)