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
97 changes: 78 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,114 @@ on:
- main
- '*.x'
pull_request:
schedule:
- cron: '0 0 * * *'

permissions:
contents: read

# Laravel 12 temporarily limited to <12.38.0 due to https://github.com/orchestral/canvas/issues/47
jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
laravel: [^8]
php: [8.3, 8.4]
laravel: ["^11.44.7", "^12.0 <12.38.0"]
dependency-version: [prefer-stable]
include:
- laravel: "^12.0 <12.38.0"
testbench: "10.6.*"
- laravel: "^11.44.7"
testbench: "9.15.*"

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 10
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: xdebug

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
env:
XDEBUG_MODE: coverage
run: vendor/bin/phpunit

- name: PHPStan Static Analysis
uses: php-actions/phpstan@v3
with:
path: src/

- name: Upload Scrutinizer coverage
uses: sudo-bot/action-scrutinizer@latest
phpcs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
cli-args: "--format=php-clover tests/reports/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
php-version: 8.4
tools: cs2pr, phpcs

- name: Setup phpcs config
run: |
{
echo '<?xml version="1.0"?>'
echo '<ruleset name="DD Detection Standard">'
echo '<description>Detects and fails for dd found in code.</description>'
echo '<arg name="colors"/>'
echo '<arg value="n"/>'
echo '<rule ref="Generic.PHP.ForbiddenFunctions">'
echo '<properties>'
echo '<property name="forbiddenFunctions" type="array">'
echo '<element key="dd" value="null"/>'
echo '</property>'
echo '</properties>'
echo '</rule>'
echo '</ruleset>'
} > custom_phpcs_style.xml

- name: Run PHP CS Fixer
run: |
(phpcs --standard=custom_phpcs_style.xml --report=checkstyle src | cs2pr) || true
phpcs --standard=custom_phpcs_style.xml src
pint:
uses: intouchinsight/github-workflows/.github/workflows/laravel-pint.yml@main
with:
php_version: '8.3'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Find pint version
id: find_pint_version
run: |
PINT_VERSION='v1.25.1'
echo "Attempting to load pint version from composer.lock"
if [ -f composer.lock ]; then
PINT_VERSION=$(jq '.["packages-dev"][] | select(.name == "laravel/pint") | .version' composer.lock)
fi
echo "Found pint version: $PINT_VERSION"
echo "PINT_VERSION=$PINT_VERSION" >> $GITHUB_OUTPUT

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
tools: cs2pr, pint:${{ steps.find_pint_version.outputs.PINT_VERSION }}

- name: Run pint
run: |
(pint --test --format=checkstyle | cs2pr) || true
pint --test -v --ansi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ tests/coverage
vendor
composer.lock
.phpstorm.meta.php
tests/reports
tests/reports/*
!tests/reports/.gitignore
.phpunit.result.cache
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-github]][link-github]
[![Code Coverage][ico-coverage]][link-coverage]

### Supported Versions
| Laravel Version | Package Tag | Supported |
Expand Down Expand Up @@ -93,8 +92,5 @@ which will fire your batch job at the correct time.
[ico-version]: https://img.shields.io/packagist/v/lukewaite/laravel-queue-aws-batch.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-github]: https://img.shields.io/github/workflow/status/lukewaite/laravel-queue-aws-batch/Tests/main.svg?style=flat-square
[ico-coverage]: https://img.shields.io/scrutinizer/coverage/g/lukewaite/laravel-queue-aws-batch/main.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/lukewaite/laravel-queue-aws-batch
[link-github]: https://github.com/lukewaite/laravel-queue-aws-batch/actions/workflows/tests.yml?query=branch%3Amain++
[link-coverage]: https://scrutinizer-ci.com/g/lukewaite/laravel-queue-aws-batch/?branch=main
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
}
},
"require": {
"illuminate/support": "^10.0|^11.0",
"php": "^8.3|^8.4",
"illuminate/support": "^11.44.7|^12.24.0",
"aws/aws-sdk-php": "^3.20.6"
},
"require-dev": {
"mockery/mockery": "^1.5",
"laravel/framework": "^10.0|^11.0",
"phpunit/phpunit": "^9.5",
"laravel/framework": "^11.44.7|^12.24.0",
"phpunit/phpunit": "^10.0|^11.0",
"squizlabs/php_codesniffer": "^3.5",
"scrutinizer/ocular": "^1.3",
"phpstan/phpstan": "^1.9",
"nunomaduro/larastan": "^1|^2",
"orchestra/testbench": "^8.0|^9.0",
"laravel/pint": "^1.16"
"phpstan/phpstan": "^2.1",
"larastan/larastan": "^3.0",
"orchestra/testbench": "^9.15|^10.6",
"laravel/pint": "^1.25.1"
},
"scripts": {
"test": "phpunit",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon

parameters:
paths:
Expand Down
13 changes: 7 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</include>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd">
<coverage>
<report>
<clover outputFile="tests/reports/clover.xml"/>
<text outputFile=""/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
<testsuites>
<testsuite name=":vendor Test Suite">
<directory>tests</directory>
Expand Down
1 change: 0 additions & 1 deletion src/Console/QueueWorkBatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ protected function gatherWorkerOptions()
/**
* Store a failed job event.
*
* @param \Illuminate\Queue\Events\JobFailed $event
* @return void
*/
protected function logFailedJob(JobFailed $event)
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/JobContainerOverrides.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Laravel Queue for AWS Batch.
*
Expand Down Expand Up @@ -32,7 +33,6 @@
* ]
*
* Interface JobContainerOverrides
* @package LukeWaite\LaravelQueueAwsBatch\Contracts
*/
interface JobContainerOverrides
{
Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/JobNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

namespace LukeWaite\LaravelQueueAwsBatch\Exceptions;

class JobNotFoundException extends LaravelAwsBatchQueueException
{
}
class JobNotFoundException extends LaravelAwsBatchQueueException {}
4 changes: 1 addition & 3 deletions src/Exceptions/LaravelAwsBatchQueueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

namespace LukeWaite\LaravelQueueAwsBatch\Exceptions;

class LaravelAwsBatchQueueException extends \Exception
{
}
class LaravelAwsBatchQueueException extends \Exception {}
4 changes: 1 addition & 3 deletions src/Exceptions/UnsupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

namespace LukeWaite\LaravelQueueAwsBatch\Exceptions;

class UnsupportedException extends LaravelAwsBatchQueueException
{
}
class UnsupportedException extends LaravelAwsBatchQueueException {}
7 changes: 4 additions & 3 deletions src/Queues/BatchQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function push($job, $data = '', $queue = null)
{
$payload = $this->createPayload($job, $data);

return $this->pushToBatch($queue, $payload, $this->getBatchDisplayName($job));
return $this->pushToBatch($queue, $payload, $this->getBatchDisplayName($job), $job);
}

public function pushRaw($payload, $queue = null, array $options = [])
Expand Down Expand Up @@ -79,9 +79,10 @@ protected function getBatchDisplayName($job)
* @param string|null $queue
* @param array $payload
* @param string $jobName
* @param mixed $job
* @return int
*/
protected function pushToBatch($queue, $payload, $jobName)
protected function pushToBatch($queue, $payload, $jobName, $job = null)
{
$jobId = $this->pushToDatabase($queue, $payload);

Expand All @@ -91,7 +92,7 @@ protected function pushToBatch($queue, $payload, $jobName)
'jobQueue' => $this->getQueue($queue),
'parameters' => [
'jobId' => $jobId,
]
],
];

if (isset($job) && is_object($job) && $this->implementsJobContainerOverrides($job)) {
Expand Down
29 changes: 20 additions & 9 deletions tests/BatchJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,49 @@
namespace LukeWaite\LaravelQueueAwsBatch\Tests;

use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;
use LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob;
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
use Mockery as m;
use Mockery\MockInterface;

class BatchJobTest extends TestCase
{
public function setUp(): void
protected \stdClass $job;

protected MockInterface $batchQueue;

protected BatchJob $batchJob;

protected function setUp(): void
{
$this->job = new \stdClass();
parent::setUp();

$this->job = new \stdClass;
$this->job->payload = '{"job":"foo","data":["data"]}';
$this->job->id = 4;
$this->job->queue = 'default';
$this->job->attempts = 1;

/** @var \LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob $batchJob */
$this->batchJob = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob')->setMethods(null)->setConstructorArgs([
m::mock('Illuminate\Container\Container'),
$this->batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue'),
$this->batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue');

$this->batchJob = new BatchJob(
new \Illuminate\Container\Container,
$this->batchQueue,
$this->job,
'testConnection',
'defaultQueue',
])->getMock();
);
}

public function testReleaseDoesntDeleteButDoesUpdate()
public function test_release_doesnt_delete_but_does_update()
{
$this->batchQueue->shouldReceive('release')->once();
$this->batchQueue->shouldNotReceive('deleteReserved');

$this->batchJob->release(0);
}

public function testThrowsExceptionOnReleaseWIthDelay()
public function test_throws_exception_on_release_w_ith_delay()
{
$this->expectException(UnsupportedException::class);
$this->expectExceptionMessage('The BatchJob does not support releasing back onto the queue with a delay');
Expand Down
Loading