File tree Expand file tree Collapse file tree 3 files changed +26
-17
lines changed Expand file tree Collapse file tree 3 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,15 @@ class Queue extends CliQueue
2323
2424 /**
2525 * aws access key
26- * @var string
26+ * @var string|null
2727 */
28- public $ key = '' ;
28+ public $ key ;
2929
3030 /**
3131 * aws secret
32- * @var string
32+ * @var string|null
3333 */
34- public $ secret = '' ;
34+ public $ secret ;
3535
3636 /**
3737 * region where queue is hosted.
@@ -118,26 +118,25 @@ private function getPayload($timeout = 0)
118118 */
119119 protected function getClient ()
120120 {
121- if ($ this ->key && $ this ->secret ) {
122- $ provider = [
121+ if ($ this ->_client ) {
122+ return $ this ->_client ;
123+ }
124+
125+ if ($ this ->key !== null && $ this ->secret !== null ) {
126+ $ credentials = [
123127 'key ' => $ this ->key ,
124128 'secret ' => $ this ->secret
125129 ];
126130 } else {
127131 // use default provider if no key and secret passed
128132 //see - http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html#credential-profiles
129- $ provider = CredentialProvider::defaultProvider ();
133+ $ credentials = CredentialProvider::defaultProvider ();
130134 }
131-
132- $ config = [
133- 'credentials ' => $ provider ,
135+ $ this ->_client = new SqsClient ([
136+ 'credentials ' => $ credentials ,
134137 'region ' => $ this ->region ,
135138 'version ' => $ this ->version ,
136- ];
137-
138- if (!$ this ->_client ) {
139- $ this ->_client = SqsClient::factory ($ config );
140- }
139+ ]);
141140
142141 return $ this ->_client ;
143142 }
Original file line number Diff line number Diff line change 9393 ];
9494}
9595
96- if (getenv ('AWS_SQS_URL ' ) !== false ) {
96+ if (getenv ('AWS_SQS_ENABLED ' ) ) {
9797 $ config ['bootstrap ' ][] = 'sqsQueue ' ;
9898 $ config ['components ' ]['sqsQueue ' ] = [
9999 'class ' => \yii \queue \sqs \Queue::class,
Original file line number Diff line number Diff line change @@ -43,6 +43,16 @@ public function testLater()
4343 $ this ->assertSimpleJobLaterDone ($ job , 2 );
4444 }
4545
46+ public function testClear ()
47+ {
48+ if (!getenv ('AWS_SQS_CLEAR_TEST_ENABLED ' )) {
49+ $ this ->markTestSkipped (__METHOD__ . ' is disabled ' );
50+ }
51+
52+ $ this ->getQueue ()->push ($ this ->createSimpleJob ());
53+ $ this ->runProcess ('php yii queue/clear --interactive=0 ' );
54+ }
55+
4656 /**
4757 * @return Queue
4858 */
@@ -53,7 +63,7 @@ protected function getQueue()
5363
5464 protected function setUp ()
5565 {
56- if (getenv ('AWS_SQS_URL ' ) === false ) {
66+ if (! getenv ('AWS_SQS_ENABLED ' ) ) {
5767 $ this ->markTestSkipped ('AWS SQS tests are disabled ' );
5868 }
5969
You can’t perform that action at this time.
0 commit comments