Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Runtime/CliHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class CliHandlerFactory
*/
public static function make(array $event)
{
return isset($event['Records'][0]['messageId'])
$messageId = $event['Records'][0]['messageId'] ?? null;

$job = json_decode($event['Records'][0]['body'] ?? '')->job ?? null;

return $messageId && $job
? new QueueHandler
: new CliHandler;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Fixtures/customLambdaEventFromSQS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Records": [
{
"messageId": "ddccab4e-f6fe-4a9a-aa18-b67ca8724d01",
"receiptHandle": "AQEBq42fiVBuPsL7mSHaAX7JqRNPgx\/5a1o\/ku1DFfrowMGI32C+1IHyaF9uHXjjJiLWE7JL8aUu0tb5yZoXbY+gEP\/tyfONuOEqxqiU6UnWT8aBMtqRnuz+F4Y2BN\/0lYxEJg4Pz849zxHtjvtkDw7zoB6SMCxAgE26UbSvIxAzNBLlU6sEQX24eKVBngEktA+i3TY9sCSuFy3lQte7yO+9ccmwbndxJ\/HV9An9KOE3FtBVIoUCx6Oum4dm5MQoMcoqBUvYDbQLM8dLfAVFT72aOu3J+WbBbOfi7bMbvkPodvfQUcum9nWnpXbci0F91R4GDnyDJfzw5oCGKazeLbjUzr8zWSy8qX\/bu3b99dE3nORQyI87OK7x8b3t+iFWzWPmCZwXh\/MvWLn9CUntj0qMPw==",
"body": "{\"test\": \"123\"}",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1757361341318",
"SenderId":"AROATHDQZYADPZZTHGFLF:vapor-laravel-staging",
"ApproximateFirstReceiveTimestamp": "1757361341319"
},
"messageAttributes": [],
"md5OfBody": "9e536d7703a805854db06bdf6169656c",
"eventSource": "aws:sqs",
"eventSourceARN":"arn:aws:sqs:eu-west-3:221427384326:laravel-staging",
"awsRegion": "us-east-1"
}
]
}
19 changes: 19 additions & 0 deletions tests/Fixtures/customNonSQSLambdaEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Records": [
{
"receiptHandle": "AQEBq42fiVBuPsL7mSHaAX7JqRNPgx\/5a1o\/ku1DFfrowMGI32C+1IHyaF9uHXjjJiLWE7JL8aUu0tb5yZoXbY+gEP\/tyfONuOEqxqiU6UnWT8aBMtqRnuz+F4Y2BN\/0lYxEJg4Pz849zxHtjvtkDw7zoB6SMCxAgE26UbSvIxAzNBLlU6sEQX24eKVBngEktA+i3TY9sCSuFy3lQte7yO+9ccmwbndxJ\/HV9An9KOE3FtBVIoUCx6Oum4dm5MQoMcoqBUvYDbQLM8dLfAVFT72aOu3J+WbBbOfi7bMbvkPodvfQUcum9nWnpXbci0F91R4GDnyDJfzw5oCGKazeLbjUzr8zWSy8qX\/bu3b99dE3nORQyI87OK7x8b3t+iFWzWPmCZwXh\/MvWLn9CUntj0qMPw==",
"body": "{\"test\": \"123\"}",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1757361341318",
"SenderId":"AROATHDQZYADPZZTHGFLF:vapor-laravel-staging",
"ApproximateFirstReceiveTimestamp": "1757361341319"
},
"messageAttributes": [],
"md5OfBody": "9e536d7703a805854db06bdf6169656c",
"eventSource": "aws:s3",
"eventSourceARN":"arn:aws:s3:eu-west-3:221427384326:laravel-staging",
"awsRegion": "us-east-1"
}
]
}
2 changes: 1 addition & 1 deletion tests/Unit/LambdaEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test_array_access()
public function getEvent()
{
return new LambdaEvent(json_decode(
file_get_contents(__DIR__.'/../Fixtures/lambdaEvent.json'),
file_get_contents(__DIR__.'/../Fixtures/jobLambdaEventFromSQS.json'),
true
));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/QueueHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function getEnvironmentSetUp($app)
protected function getEvent()
{
return json_decode(
file_get_contents(__DIR__.'/../Fixtures/lambdaEvent.json'),
file_get_contents(__DIR__.'/../Fixtures/jobLambdaEventFromSQS.json'),
true
);
}
Expand Down
57 changes: 57 additions & 0 deletions tests/Unit/Runtime/CliHandlerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Laravel\Vapor\Tests\Unit\Runtime;

use Laravel\Vapor\Runtime\CliHandlerFactory;
use Laravel\Vapor\Runtime\Handlers\CliHandler;
use Laravel\Vapor\Runtime\Handlers\QueueHandler;
use Orchestra\Testbench\TestCase;

class CliHandlerFactoryTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

QueueHandler::$app = 'dummy';
}

public function test_custom_sqs_events_use_cli_handler()
{
$this->assertInstanceOf(CliHandler::class, CliHandlerFactory::make($this->getSQSCustomEvent()));
}

public function test_custom_non_sqs_lambda_events_use_cli_handler()
{
$this->assertInstanceOf(CliHandler::class, CliHandlerFactory::make($this->getCustomNonSQSLambdaEvent()));
}

public function test_laravel_jobs_use_queue_handler()
{
$this->assertInstanceOf(QueueHandler::class, CliHandlerFactory::make($this->getSQSJobEvent()));
}

protected function getCustomNonSQSLambdaEvent()
{
return json_decode(
file_get_contents(__DIR__.'/../../Fixtures/customNonSQSLambdaEvent.json'),
true
);
}

protected function getSQSJobEvent()
{
return json_decode(
file_get_contents(__DIR__.'/../../Fixtures/jobLambdaEventFromSQS.json'),
true
);
}

protected function getSQSCustomEvent()
{
return json_decode(
file_get_contents(__DIR__.'/../../Fixtures/customLambdaEventFromSQS.json'),
true
);
}
}
2 changes: 1 addition & 1 deletion tests/Unit/VaporWorkCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function getEnvironmentSetUp($app)
protected function getEvent()
{
return new LambdaEvent(json_decode(
file_get_contents(__DIR__.'/../Fixtures/lambdaEvent.json'),
file_get_contents(__DIR__.'/../Fixtures/jobLambdaEventFromSQS.json'),
true
));
}
Expand Down