Skip to content

Add GitHub action for tests #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
72 changes: 72 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: PR checks and tests

on:
pull_request:
branches:
- master

jobs:
run:
name: PHP ${{ matrix.php-versions }} (Redis ${{ matrix.redis-versions }})
runs-on: ubuntu-latest
container: shivammathur/node
services:
redis:
image: redis:${{ matrix.redis-versions }}-alpine
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
redis-versions: ['5', '6', '7']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Configure Redis for CI
run: |
apt-get update && apt-get install -y redis-tools
redis-cli -h redis -p 6379 CONFIG SET stop-writes-on-bgsave-error no
redis-cli -h redis -p 6379 CONFIG SET save ""

- name: Install dependencies
run: |
composer install --no-interaction --no-ansi --no-progress

- name: Run phpcs
run: |
./vendor/bin/phpcs src

- name: Run phpstan
run: |
./vendor/bin/phpstan analyse src

- name: Run phpunit tests
env:
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_TIMEOUT: 0.0
run: |
./vendor/bin/phpunit --disallow-test-output --no-coverage
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
],
"require": {
"ext-json": "*",
"pdffiller/qless-php": "^3.13"
"pdffiller/qless-php": "dev-upgrade-php-version"
},
"require-dev": {
"illuminate/events": "5.6.*|5.7.*|^6.20",
"infection/infection": "^0.12.0",
"orchestra/testbench": "~3.0",
"phpstan/phpstan": "^0.11.1",
"phpunit/phpunit": ">=5.3 <8.0 | ^8.2",
"illuminate/events": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.5 || ^10.0",
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {
Expand All @@ -40,6 +39,9 @@
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
}
}
}
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
parameters:
level: 3
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#Cannot access offset#'
- '#Method LaravelQless\\Queue\\QlessQueue::makePayload\(\) should return string but returns string|false.#'
- '#Method LaravelQless\\Queue\\QlessQueue::makePayload\(\) should return string but returns string\|false.#'
- '#Unsafe usage of new static\(\)#'
7 changes: 4 additions & 3 deletions src/Queue/QlessQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function recur(int $interval, string $job, array $data, ?string $queueNam
public function pop($queueName = null)
{
$connectionCount = $this->getClientCount();
$job = null;

for ($i = 0; $i < $connectionCount; $i++) {
$connection = $this->getNextConnection();
Expand Down Expand Up @@ -198,7 +199,7 @@ public function pop($queueName = null)
* @param string|null $queueName
* @return bool
*/
public function subscribe(string $topic, string $queueName = null): bool
public function subscribe(string $topic, ?string $queueName = null): bool
{
$queueName = $queueName ?? $this->defaultQueue;

Expand All @@ -217,7 +218,7 @@ public function subscribe(string $topic, string $queueName = null): bool
* @param string|null $queueName
* @return bool
*/
public function unSubscribe(string $topic, string $queueName = null): bool
public function unSubscribe(string $topic, ?string $queueName = null): bool
{
$queueName = $queueName ?? $this->defaultQueue;

Expand All @@ -242,7 +243,7 @@ public function pushToTopic(string $topicName, string $job, array $data = [], ar
{
$topic = new Topic($topicName, $this->getRandomConnection());

$qlessOptions = $payloadData['data'][self::JOB_OPTIONS_KEY] ?? [];
$qlessOptions = $data[self::JOB_OPTIONS_KEY] ?? [];
$options = array_merge($qlessOptions, $options);

return $topic->put(
Expand Down
3 changes: 1 addition & 2 deletions tests/Queue/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ public function testDispatchJob()

$job = new Job(['dispatch' => 'work']);

$dispatch = dispatch($job)->onQueue($queueName)->onConnection('qless');
unset($dispatch);
$this->app['queue']->connection('qless')->push($job, '', $queueName);

$queue = $this->getQueue();

Expand Down
8 changes: 4 additions & 4 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace LaravelQless\Tests;

use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use LaravelQless\LaravelQlessServiceProvider;
use LaravelQless\Queue\QlessConnector;
Expand All @@ -22,9 +22,9 @@ public function testBoot()
{
$queueMock = $this->createMock(QueueManager::class);
$queueMock
->expects($this->once())
->expects(self::once())
->method('addConnector')
->with('qless', $this->isInstanceOf(\Closure::class))
->with('qless', self::isInstanceOf(\Closure::class))
->willReturnCallback(function ($driver, \Closure $resolver) {
$connector = $resolver();
$this->assertInstanceOf(QlessConnector::class, $connector);
Expand All @@ -34,7 +34,7 @@ public function testBoot()
$app = $this->app;
$app['queue'] = $queueMock;

$app['events'] = $this->createMock(Event::class);
$app['events'] = $this->createMock(Dispatcher::class);

$providerMock = new LaravelQlessServiceProvider($app);
$providerMock->boot();
Expand Down
Loading