1010use MiamiOH \SnsHandler \SnsMessage ;
1111use MiamiOH \SnsHandler \SnsTopicMapper ;
1212use MiamiOH \SnsHandler \SnsUnknownTopicArnException ;
13- use MiamiOH \IamPortal \Util \HttpClient ;
14- use MiamiOH \IamPortal \Util \HttpResponse ;
1513use PHPUnit \Framework \MockObject \MockObject ;
1614use Tests \MiamiOH \SnsHandler \MakesSnsTests ;
1715use 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