From 0bb650e4a82751897a6f76108aeb59d9727574c3 Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 15:46:56 +0300 Subject: [PATCH 1/9] Add GitHub action for tests --- .github/workflows/pr-check.yml | 66 ++++++++++++++++++++++++++++++++++ composer.json | 11 +++--- 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pr-check.yml diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 0000000..e02dfda --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,66 @@ +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.1', '7.2', '7.3', '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: Install dependencies + run: | + composer install --no-interaction --no-ansi --no-progress + + - name: Run phpcs + run: | + ./vendor/bin/phpcs + + - 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 diff --git a/composer.json b/composer.json index 4d63dfd..f8b2cbf 100644 --- a/composer.json +++ b/composer.json @@ -16,13 +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", + "infection/infection": "^0.20.0", "orchestra/testbench": "~3.0", - "phpstan/phpstan": "^0.11.1", + "phpstan/phpstan": "^1.0", "phpunit/phpunit": ">=5.3 <8.0 | ^8.2", "squizlabs/php_codesniffer": "^3.4" }, @@ -40,6 +40,9 @@ "config": { "optimize-autoloader": true, "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "infection/extension-installer": true + } } } From b78f3db86d1039fd0a2bb2d93b34d5aef161c352 Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 22:18:40 +0300 Subject: [PATCH 2/9] Update test action --- .github/workflows/pr-check.yml | 2 +- phpstan.neon | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index e02dfda..9f929c6 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -51,7 +51,7 @@ jobs: - name: Run phpcs run: | - ./vendor/bin/phpcs + ./vendor/bin/phpcs src - name: Run phpstan run: | diff --git a/phpstan.neon b/phpstan.neon index c4a17db..77be9c7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ 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.#' From 42e028475e8a1cb98ff023001e7c9d4250dcda64 Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 22:22:46 +0300 Subject: [PATCH 3/9] Fix phpcs errors --- src/Job/AbstractJob.php | 3 ++- src/Queue/QlessQueue.php | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Job/AbstractJob.php b/src/Job/AbstractJob.php index 58764cd..9d62d9b 100644 --- a/src/Job/AbstractJob.php +++ b/src/Job/AbstractJob.php @@ -41,7 +41,8 @@ abstract public function perform(BaseJob $job); */ public static function dispatchNow() { - return (new static(...func_get_args()))->completeSync(); + $instance = new static(...func_get_args()); + return $instance->completeSync(); } /** diff --git a/src/Queue/QlessQueue.php b/src/Queue/QlessQueue.php index 93ace6a..2211769 100644 --- a/src/Queue/QlessQueue.php +++ b/src/Queue/QlessQueue.php @@ -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(); @@ -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; @@ -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; @@ -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( From 4a5ef80d200478a508b4da8e145d7088bd55c748 Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 22:35:34 +0300 Subject: [PATCH 4/9] Fix phpcs errors --- composer.json | 2 +- phpstan.neon | 1 + src/Job/AbstractJob.php | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f8b2cbf..21a14d5 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { "illuminate/events": "5.6.*|5.7.*|^6.20", - "infection/infection": "^0.20.0", + "infection/infection": "^0.11.1 || ^0.20.0", "orchestra/testbench": "~3.0", "phpstan/phpstan": "^1.0", "phpunit/phpunit": ">=5.3 <8.0 | ^8.2", diff --git a/phpstan.neon b/phpstan.neon index 77be9c7..78c6bcf 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,3 +4,4 @@ parameters: ignoreErrors: - '#Cannot access offset#' - '#Method LaravelQless\\Queue\\QlessQueue::makePayload\(\) should return string but returns string\|false.#' + - '#Unsafe usage of new static\(\)#' diff --git a/src/Job/AbstractJob.php b/src/Job/AbstractJob.php index 9d62d9b..58764cd 100644 --- a/src/Job/AbstractJob.php +++ b/src/Job/AbstractJob.php @@ -41,8 +41,7 @@ abstract public function perform(BaseJob $job); */ public static function dispatchNow() { - $instance = new static(...func_get_args()); - return $instance->completeSync(); + return (new static(...func_get_args()))->completeSync(); } /** From dc2ba776889071866cf024c7b846eba9784691fa Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 23:28:30 +0300 Subject: [PATCH 5/9] Check tests --- .github/workflows/pr-check.yml | 8 +++++++- composer.json | 7 +++---- tests/ServiceProviderTest.php | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 9f929c6..82cf136 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] redis-versions: ['5', '6', '7'] steps: @@ -45,6 +45,12 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- + - name: Configure Redis for CI + run: | + apk add --no-cache redis + 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 diff --git a/composer.json b/composer.json index 21a14d5..349632c 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,10 @@ "pdffiller/qless-php": "dev-upgrade-php-version" }, "require-dev": { - "illuminate/events": "5.6.*|5.7.*|^6.20", - "infection/infection": "^0.11.1 || ^0.20.0", - "orchestra/testbench": "~3.0", + "illuminate/events": "^9.0 || ^10.0 || ^11.0", + "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", "phpstan/phpstan": "^1.0", - "phpunit/phpunit": ">=5.3 <8.0 | ^8.2", + "phpunit/phpunit": "^8.5 || ^9.5 || ^10.0", "squizlabs/php_codesniffer": "^3.4" }, "autoload": { diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index c107192..c94671d 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -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; @@ -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); @@ -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(); From 1d16f7139c04f96b28da27fc02d1e6d029fe92cf Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 23:31:09 +0300 Subject: [PATCH 6/9] Check tests --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 82cf136..df12f5a 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -47,7 +47,7 @@ jobs: - name: Configure Redis for CI run: | - apk add --no-cache redis + 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 "" From d3a6a1aec979d2eed64e535a76b9c90478e672aa Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 23:33:46 +0300 Subject: [PATCH 7/9] Check tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 349632c..9356b8e 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "pdffiller/qless-php": "dev-upgrade-php-version" }, "require-dev": { - "illuminate/events": "^9.0 || ^10.0 || ^11.0", + "illuminate/events": "^8.0 || ^9.0 || ^10.0 || ^11.0", "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", "phpstan/phpstan": "^1.0", "phpunit/phpunit": "^8.5 || ^9.5 || ^10.0", From 71ff25c387136daa92b1e68fe4b1e3628b2b69b0 Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Mon, 9 Jun 2025 23:37:45 +0300 Subject: [PATCH 8/9] Check tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9356b8e..7b25efc 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { "illuminate/events": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "orchestra/testbench": "^7.0 || ^8.0 || ^9.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" From 61c59253ca6497e161f22e8bc7b509c491107aa5 Mon Sep 17 00:00:00 2001 From: OlegMuron Date: Tue, 10 Jun 2025 00:04:19 +0300 Subject: [PATCH 9/9] Check tests --- tests/Queue/QueueTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Queue/QueueTest.php b/tests/Queue/QueueTest.php index 524f6cf..4f7d9c0 100644 --- a/tests/Queue/QueueTest.php +++ b/tests/Queue/QueueTest.php @@ -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();