Skip to content

Commit 85493c0

Browse files
committed
Add support for PHP8, update the minimum tarantool/queue version to 0.9
1 parent c4b9458 commit 85493c0

File tree

7 files changed

+162
-20
lines changed

7 files changed

+162
-20
lines changed

.github/workflows/qa.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: QA
2+
on:
3+
push:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '40 2 * * *'
7+
8+
jobs:
9+
tests:
10+
strategy:
11+
matrix:
12+
operating-system: [ubuntu-latest]
13+
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0']
14+
runs-on: ${{ matrix.operating-system }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Setup PHP, with composer and extensions
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-versions }}
23+
extensions: msgpack
24+
coverage: none
25+
26+
- name: Get composer cache directory
27+
id: composer-cache
28+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
29+
30+
- name: Cache composer dependencies
31+
uses: actions/cache@v1
32+
with:
33+
path: ${{ steps.composer-cache.outputs.dir }}
34+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
35+
restore-keys: ${{ runner.os }}-composer-
36+
37+
- name: Install dependencies
38+
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
39+
40+
- name: Test with phpunit
41+
run: vendor/bin/phpunit
42+
43+
static-analysis:
44+
name: Static Analysis
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v2
49+
50+
- name: Setup PHP
51+
uses: shivammathur/setup-php@v2
52+
with:
53+
php-version: '8.0'
54+
coverage: none
55+
56+
- name: Get composer cache directory
57+
id: composer-cache
58+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
59+
60+
- name: Cache composer dependencies
61+
uses: actions/cache@v1
62+
with:
63+
path: ${{ steps.composer-cache.outputs.dir }}
64+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
65+
restore-keys: ${{ runner.os }}-composer-
66+
67+
- name: Install dependencies
68+
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
69+
70+
- name: Static Analysis using Psalm
71+
run: vendor/bin/psalm --show-info=true
72+
73+
coding-standard:
74+
name: Coding Standard
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v2
79+
80+
- name: Setup PHP
81+
uses: shivammathur/setup-php@v2
82+
with:
83+
php-version: '7.4'
84+
tools: php-cs-fixer
85+
coverage: none
86+
87+
- name: Check code style
88+
run: php-cs-fixer fix --dry-run --diff --verbose .

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019-2020 Eugene Leonovich
3+
Copyright (c) 2019-2021 Eugene Leonovich
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.1",
14-
"tarantool/queue": "^0.7.0|^0.8.0"
13+
"php": "^7.1|^8",
14+
"tarantool/queue": "^0.9"
1515
},
1616
"require-dev": {
1717
"friendsofphp/php-cs-fixer": "^2.14",
18-
"phpunit/phpunit": "^7.1|^8.0"
18+
"phpunit/phpunit": "^7.1|^8|^9",
19+
"vimeo/psalm": "^3.9|^4"
1920
},
2021
"autoload": {
2122
"psr-4": {

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="3"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/JobEmitter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static function parseCallResponse(array $response, bool $isMapResponse)
4747

4848
$tasks = [];
4949
foreach ($tuples as $key => $tuple) {
50-
$tasks[$key] = Task::createFromTuple($tuple);
50+
$tasks[$key] = Task::fromTuple($tuple);
5151
}
5252

5353
return $tasks;

tests/JobEmitterTest.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,38 @@
1515

1616
use PHPUnit\Framework\TestCase;
1717
use Tarantool\JobQueue\JobBuilder\JobBuilder;
18-
use Tarantool\JobQueue\JobBuilder\JobBuilders;
1918
use Tarantool\JobQueue\JobBuilder\JobEmitter;
2019
use Tarantool\Queue\Queue;
2120
use Tarantool\Queue\States;
2221
use Tarantool\Queue\Task;
2322

2423
final class JobEmitterTest extends TestCase
2524
{
25+
use PhpUnitCompat;
26+
2627
public function testEmitNoJobs() : void
2728
{
2829
$queue = $this->createMock(Queue::class);
2930
$queue->expects(self::never())->method('put');
3031

3132
$emitter = new JobEmitter();
32-
$tasks = $emitter->emit(new JobBuilders([]), $queue);
33+
$tasks = $emitter->emit([], $queue);
3334

3435
self::assertSame([], $tasks);
3536
}
3637

3738
public function testEmitOneJob() : void
3839
{
3940
$builder = JobBuilder::fromPayload('task_data');
40-
$task = Task::createFromTuple([42, States::READY, 'task_data']);
41+
$task = Task::fromTuple([42, States::READY, 'task_data']);
4142

4243
$queue = $this->createMock(Queue::class);
4344
$queue->expects(self::once())->method('put')
44-
->with('task_data', [])
45+
->with(['payload' => 'task_data'], [])
4546
->willReturn($task);
4647

4748
$emitter = new JobEmitter();
48-
$tasks = $emitter->emit(new JobBuilders([$builder]), $queue);
49+
$tasks = $emitter->emit([$builder], $queue);
4950

5051
self::assertSame($task, reset($tasks));
5152
}
@@ -55,19 +56,22 @@ public function testEmitMultipleJobsArray() : void
5556
$builder1 = JobBuilder::fromPayload('task_data1');
5657
$builder2 = JobBuilder::fromPayload('task_data2');
5758

58-
$task1 = Task::createFromTuple([42, States::READY, 'task_data1']);
59-
$task2 = Task::createFromTuple([43, States::READY, 'task_data2']);
59+
$task1 = Task::fromTuple([42, States::READY, 'task_data1']);
60+
$task2 = Task::fromTuple([43, States::READY, 'task_data2']);
6061

6162
$queue = $this->createMock(Queue::class);
6263
$queue->expects(self::once())->method('call')
63-
->with('put_many', [[['task_data1', []], ['task_data2', []]]])
64+
->with('put_many', [
65+
[['payload' => 'task_data1'], []],
66+
[['payload' => 'task_data2'], []],
67+
])
6468
->willReturn([[
6569
[42, States::READY, 'task_data1'],
6670
[43, States::READY, 'task_data2'],
6771
]]);
6872

6973
$emitter = new JobEmitter();
70-
$tasks = $emitter->emit(new JobBuilders([$builder1, $builder2]), $queue);
74+
$tasks = $emitter->emit([$builder1, $builder2], $queue);
7175

7276
self::assertEquals([$task1, $task2], $tasks);
7377
}
@@ -77,19 +81,22 @@ public function testEmitMultipleJobsMap() : void
7781
$builder1 = JobBuilder::fromPayload('task_data1');
7882
$builder2 = JobBuilder::fromPayload('task_data2');
7983

80-
$task1 = Task::createFromTuple([42, States::READY, 'task_data1']);
81-
$task2 = Task::createFromTuple([43, States::READY, 'task_data2']);
84+
$task1 = Task::fromTuple([42, States::READY, 'task_data1']);
85+
$task2 = Task::fromTuple([43, States::READY, 'task_data2']);
8286

8387
$queue = $this->createMock(Queue::class);
8488
$queue->expects(self::once())->method('call')
85-
->with('put_many', [[['task_data1', []], 'key' => ['task_data2', []]]])
89+
->with('put_many', [
90+
[['payload' => 'task_data1'], []],
91+
'key' => [['payload' => 'task_data2'], []],
92+
])
8693
->willReturn([[[
8794
[42, States::READY, 'task_data1'],
8895
'key' => [43, States::READY, 'task_data2'],
8996
]]]);
9097

9198
$emitter = new JobEmitter();
92-
$tasks = $emitter->emit(new JobBuilders([$builder1, 'key' => $builder2]), $queue);
99+
$tasks = $emitter->emit([$builder1, 'key' => $builder2], $queue);
93100

94101
self::assertEquals([$task1, 'key' => $task2], $tasks);
95102
}
@@ -104,9 +111,9 @@ public function testThrowOnInvalidCallResult() : void
104111
->willReturn(['invalid_response']);
105112

106113
$this->expectException(\UnexpectedValueException::class);
107-
$this->expectExceptionMessageRegExp('/Unable to parse call response as (map|array)\./');
114+
$this->expectExceptionMessageMatches('/Unable to parse call response as (map|array)\./');
108115

109116
$emitter = new JobEmitter();
110-
$emitter->emit(new JobBuilders([$builder1, $builder2]), $queue);
117+
$emitter->emit([$builder1, $builder2], $queue);
111118
}
112119
}

tests/PhpUnitCompat.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Tarantool JobBuilder package.
7+
*
8+
* (c) Eugene Leonovich <gen.work@gmail.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Tarantool\JobQueue\JobBuilder\Tests;
15+
16+
/**
17+
* A compatibility layer for the legacy PHPUnit 7.
18+
*/
19+
trait PhpUnitCompat
20+
{
21+
public function expectExceptionMessageMatches(string $regularExpression) : void
22+
{
23+
if (\is_callable('parent::expectExceptionMessageMatches')) {
24+
parent::expectExceptionMessageMatches($regularExpression);
25+
26+
return;
27+
}
28+
29+
parent::expectExceptionMessageRegExp($regularExpression);
30+
}
31+
}

0 commit comments

Comments
 (0)