|
2 | 2 |
|
3 | 3 | namespace NotificationChannels\AwsSns\Test; |
4 | 4 |
|
| 5 | +use Aws\Sns\SnsClient; |
| 6 | +use Aws\Credentials\Credentials; |
5 | 7 | use Aws\Sns\SnsClient as SnsService; |
6 | 8 | use Illuminate\Contracts\Foundation\Application; |
7 | 9 | use Mockery; |
@@ -77,6 +79,61 @@ public function it_gives_an_instantiated_sns_object_when_the_channel_asks_for_it |
77 | 79 |
|
78 | 80 | $this->provider->boot(); |
79 | 81 | } |
| 82 | + |
| 83 | + /** @test */ |
| 84 | + public function it_creates_the_aws_credentials_from_the_key_and_secret_options() |
| 85 | + { |
| 86 | + $this->app->shouldReceive('when') |
| 87 | + ->with(SnsChannel::class) |
| 88 | + ->once() |
| 89 | + ->andReturn($this->app); |
| 90 | + |
| 91 | + $this->app->shouldReceive('needs') |
| 92 | + ->with(Sns::class) |
| 93 | + ->once() |
| 94 | + ->andReturn($this->app); |
| 95 | + |
| 96 | + $this->app->shouldReceive('give') |
| 97 | + ->with(Mockery::on(function ($sns) { |
| 98 | + return $sns() instanceof Sns; |
| 99 | + })) |
| 100 | + ->once(); |
| 101 | + |
| 102 | + $this->app->shouldReceive('make') |
| 103 | + ->with(SnsService::class) |
| 104 | + ->andReturn(Mockery::mock(SnsService::class)); |
| 105 | + |
| 106 | + $this->app->shouldReceive('bind') |
| 107 | + ->with(SnsService::class, Mockery::on(function ($sns) { |
| 108 | + /** @var SnsClient $snsClient */ |
| 109 | + $snsClient = $sns(); |
| 110 | + $credentials = $snsClient->getCredentials()->wait(); |
| 111 | + $this->assertSame([ |
| 112 | + 'key' => 'aws-key-123', |
| 113 | + 'secret' => 'aws-secret-ashd1i26312873asw', |
| 114 | + 'token' => null, |
| 115 | + 'expires' => null, |
| 116 | + ], $credentials->toArray()); |
| 117 | + |
| 118 | + return true; |
| 119 | + })) |
| 120 | + ->once() |
| 121 | + ->andReturn($this->app); |
| 122 | + |
| 123 | + $configArray = [ |
| 124 | + 'key' => 'aws-key-123', |
| 125 | + 'secret' => 'aws-secret-ashd1i26312873asw', |
| 126 | + 'region' => 'us-east-1', |
| 127 | + ]; |
| 128 | + |
| 129 | + $this->app->shouldReceive('offsetGet') |
| 130 | + ->with('config') |
| 131 | + ->andReturn([ |
| 132 | + 'services.sns' => $configArray, |
| 133 | + ]); |
| 134 | + |
| 135 | + $this->provider->boot(); |
| 136 | + } |
80 | 137 | } |
81 | 138 |
|
82 | 139 | interface App extends Application, \ArrayAccess |
|
0 commit comments