@@ -27,17 +27,15 @@ class SnsBrokerTest extends TestCase
2727 /** @var MessageValidator|MockObject */
2828 private $ validator ;
2929
30-
3130 public function setUp (): void
3231 {
3332 parent ::setUp ();
3433
3534 Event::fake ();
3635
37-
3836 $ this ->validator = $ this ->createMock (MessageValidator::class);
3937
40- $ this ->broker = new SnsBroker ($ this ->validator );
38+ $ this ->broker = new SnsBroker ($ this ->validator , $ this -> config );
4139 }
4240
4341 public function testMakesSnsMessageFromHttpRequest (): void
@@ -51,19 +49,6 @@ public function testMakesSnsMessageFromHttpRequest(): void
5149 $ this ->assertEquals (SnsMessage::NOTIFICATION_TYPE , $ message ->type ());
5250 }
5351
54- public function testRejectsMessageWithUnknownTopicArn (): void
55- {
56- $ this ->markTestSkipped ("Doesn't work with event faking and we think this test will go away after refactoring. " );
57- $ request = $ this ->createMock (SnsHttpRequest::class);
58- $ request ->expects ($ this ->once ())->method ('jsonContent ' )
59- ->willReturn ($ this ->makeSnsMessageJson (['TopicArn ' => 'arn:aws:sns:us-west-2:123456789012:Unknown ' ]));
60-
61- $ this ->expectException (SnsUnknownTopicArnException::class);
62- $ this ->expectExceptionMessage ('No handler registered for TopicArn arn:aws:sns:us-west-2:123456789012:Unknown ' );
63-
64- $ this ->broker ->handleRequest ($ request );
65- }
66-
6752 public function testThrowsExceptionForUnknownMessageType (): void
6853 {
6954 $ request = $ this ->createMock (SnsHttpRequest::class);
@@ -117,6 +102,12 @@ public function testValidatesSnsMessage(): void
117102
118103 public function testDispatchMappedNotificationMessage (): void
119104 {
105+ $ this ->configValues ['message-events ' ] = [
106+ SnsMessageAlphaReceived::class => ['arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ],
107+ SnsMessageBetaReceived::class => ['arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ],
108+ SnsMessageReceived::class => ['* ' ],
109+ ];
110+
120111 $ request = $ this ->createMock (SnsHttpRequest::class);
121112 $ request ->expects ($ this ->once ())->method ('jsonContent ' )
122113 ->willReturn ($ this ->makeSnsMessageJson ([
@@ -131,6 +122,12 @@ public function testDispatchMappedNotificationMessage(): void
131122
132123 public function testDispatchFirstMappedNotificationMessage (): void
133124 {
125+ $ this ->configValues ['message-events ' ] = [
126+ SnsMessageAlphaReceived::class => ['arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ],
127+ SnsMessageBetaReceived::class => ['arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ],
128+ SnsMessageReceived::class => ['* ' ],
129+ ];
130+
134131 $ request = $ this ->createMock (SnsHttpRequest::class);
135132 $ request ->expects ($ this ->once ())->method ('jsonContent ' )
136133 ->willReturn ($ this ->makeSnsMessageJson ([
@@ -143,4 +140,25 @@ public function testDispatchFirstMappedNotificationMessage(): void
143140 Event::assertNotDispatched (SnsMessageBetaReceived::class);
144141 Event::assertNotDispatched (SnsMessageReceived::class);
145142 }
143+
144+ public function testRejectsMessageWithUnhandledTopicArn (): void
145+ {
146+ $ this ->configValues ['message-events ' ] = [
147+ SnsMessageBetaReceived::class => ['arn:aws:sns:us-west-2:123456789012:BetaTopic ' ],
148+ ];
149+
150+ $ request = $ this ->createMock (SnsHttpRequest::class);
151+ $ request ->expects ($ this ->once ())->method ('jsonContent ' )
152+ ->willReturn ($ this ->makeSnsMessageJson ([
153+ 'MessageId ' => 'abc123 ' ,
154+ 'TopicArn ' => 'arn:aws:sns:us-west-2:123456789012:AlphaTopic '
155+ ]));
156+
157+ $ this ->expectException (SnsUnknownTopicArnException::class);
158+ $ this ->expectExceptionMessage ('Unmappable TopicArn: arn:aws:sns:us-west-2:123456789012:AlphaTopic ' );
159+
160+ $ this ->broker ->handleRequest ($ request );
161+
162+ Event::assertNotDispatched (SnsMessageReceived::class);
163+ }
146164}
0 commit comments