Skip to content

Commit c2f1207

Browse files
authored
Bump minimum PHP version requirement to 7.1 (#14)
* Bump php version to 7.1 * Temporary skip the test for the pecl connector until this PR is merged: tarantool/tarantool-php#134 * Use variadic args in Queue::call() * Use float type hint for timestamp and interval arguments * Declare strict types * Fix scrutinizer fails to parse a coverage file * Add .php_cs.dist * Update README.md
1 parent 5c81c61 commit c2f1207

20 files changed

+440
-341
lines changed

.php_cs.dist

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tarantool\Queue;
6+
7+
use PhpCsFixer\Config;
8+
use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer;
9+
use PhpCsFixer\Fixer\FixerInterface;
10+
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
11+
use PhpCsFixer\Tokenizer\Tokens;
12+
13+
final class FilterableFixer implements FixerInterface
14+
{
15+
private $fixer;
16+
private $pathRegex;
17+
18+
public function __construct(FixerInterface $fixer, string $pathRegex)
19+
{
20+
$this->fixer = $fixer;
21+
$this->pathRegex = $pathRegex;
22+
}
23+
24+
public function isCandidate(Tokens $tokens) : bool
25+
{
26+
return $this->fixer->isCandidate($tokens);
27+
}
28+
29+
public function isRisky() : bool
30+
{
31+
return $this->fixer->isRisky();
32+
}
33+
34+
public function fix(\SplFileInfo $file, Tokens $tokens) : void
35+
{
36+
$this->fixer->fix($file, $tokens);
37+
}
38+
39+
public function getName() : string
40+
{
41+
return (new \ReflectionClass($this))->getShortName().'/'.$this->fixer->getName();
42+
}
43+
44+
public function getPriority() : int
45+
{
46+
return $this->fixer->getPriority();
47+
}
48+
49+
public function supports(\SplFileInfo $file) : bool
50+
{
51+
if (1 !== preg_match($this->pathRegex, $file->getRealPath())) {
52+
return false;
53+
}
54+
55+
return $this->fixer->supports($file);
56+
}
57+
};
58+
59+
$header = <<<EOF
60+
This file is part of the Tarantool Queue package.
61+
62+
(c) Eugene Leonovich <[email protected]>
63+
64+
For the full copyright and license information, please view the LICENSE
65+
file that was distributed with this source code.
66+
EOF;
67+
68+
return Config::create()
69+
->setUsingCache(false)
70+
->setRiskyAllowed(true)
71+
->registerCustomFixers([
72+
new FilterableFixer(new NativeConstantInvocationFixer(), '/\bsrc\b/'),
73+
new FilterableFixer(new NativeFunctionInvocationFixer(), '/\bsrc\b/'),
74+
])
75+
->setRules([
76+
'@Symfony' => true,
77+
'@Symfony:risky' => true,
78+
'array_syntax' => ['syntax' => 'short'],
79+
'binary_operator_spaces' => ['operators' => ['=' => null, '=>' => null]],
80+
'declare_strict_types' => true,
81+
'native_constant_invocation' => false,
82+
'native_function_invocation' => false,
83+
'FilterableFixer/native_constant_invocation' => true,
84+
'FilterableFixer/native_function_invocation' => true,
85+
'no_useless_else' => true,
86+
'no_useless_return' => true,
87+
'ordered_imports' => true,
88+
'phpdoc_order' => true,
89+
'phpdoc_align' => false,
90+
'return_type_declaration' => ['space_before' => 'one'],
91+
'strict_comparison' => true,
92+
'header_comment' => [
93+
'header' => $header,
94+
'location' => 'after_declare_strict',
95+
'separate' => 'both',
96+
],
97+
])
98+
;

.travis.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ services:
66
- docker
77

88
env:
9-
- IMAGE='php:5.6-cli' TNT_CLIENT=pecl
10-
- IMAGE='php:7.0-cli' TNT_CLIENT=pecl
119
- IMAGE='php:7.1-cli' TNT_CLIENT=pecl
12-
- IMAGE='php:5.6-cli' TNT_CLIENT=pure
13-
- IMAGE='php:7.0-cli' TNT_CLIENT=pure
14-
- IMAGE='php:7.1-cli' TNT_CLIENT=pure
15-
- IMAGE='php:7.2-cli' TNT_CLIENT=pure PHPUNIT_OPTS='--coverage-clover=coverage.clover'
10+
- IMAGE='php:7.1-cli' CHECK_CS=1
11+
- IMAGE='php:7.2-cli' PHPUNIT_OPTS='--coverage-clover=coverage.clover'
12+
- IMAGE='php:7.3-rc-cli'
1613

1714
install:
1815
- ./dockerfile.sh | tee /dev/tty | docker build -t queue -
@@ -25,5 +22,5 @@ script:
2522
after_script:
2623
- if [[ -f coverage.clover ]]; then
2724
curl -sSOL https://scrutinizer-ci.com/ocular.phar &&
28-
docker run --rm -v $(pwd):/coverage -w /coverage queue php ocular.phar code-coverage:upload --format=php-clover coverage.clover;
25+
docker run --rm -v $(pwd):/queue -w /queue queue php ocular.phar code-coverage:upload --format=php-clover coverage.clover;
2926
fi

README.md

+42-26
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,34 @@
33
[![Build Status](https://travis-ci.org/tarantool-php/queue.svg?branch=master)](https://travis-ci.org/tarantool-php/queue)
44
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tarantool-php/queue/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tarantool-php/queue/?branch=master)
55
[![Code Coverage](https://scrutinizer-ci.com/g/tarantool-php/queue/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tarantool-php/queue/?branch=master)
6+
[![Mentioned in Awesome PHP](https://awesome.re/mentioned-badge.svg)](https://github.com/ziadoz/awesome-php)
67

78
[Tarantool](http://tarantool.org/) is a NoSQL database running in a Lua application server. It integrates
89
Lua modules, called [LuaRocks](https://luarocks.org/). This package provides PHP bindings for
910
[Tarantool Queue LuaRock](https://github.com/tarantool/queue/).
1011

1112

13+
## Table of contents
14+
15+
* [Installation](#installation)
16+
* [Before start](#before-start)
17+
* [Working with queue](#working-with-queue)
18+
* [Data types](#data-types)
19+
* [Tasks](#tasks)
20+
* [Producer API](#producer-api)
21+
* [Consumer API](#consumer-api)
22+
* [Statistics](#statistics)
23+
* [Custom methods](#custom-methods)
24+
* [Tests](#tests)
25+
* [License](#license)
26+
27+
1228
## Installation
1329

1430
The recommended way to install the library is through [Composer](http://getcomposer.org):
1531

16-
```sh
17-
$ composer require tarantool/queue
32+
```bash
33+
composer require tarantool/queue
1834
```
1935

2036

@@ -38,8 +54,8 @@ queue.create_tube('foobar', 'fifottl', {if_not_exists=true})
3854
To start the instance you need to copy (or symlink) `queues.lua` file into the `/etc/tarantool/instances.enabled`
3955
directory and run the following command:
4056

41-
```sh
42-
$ sudo tarantoolctl start queues
57+
```bash
58+
sudo tarantoolctl start queues
4359
```
4460

4561

@@ -104,15 +120,15 @@ Task::isDelayed()
104120

105121
As you've already seen, to insert a task into a queue you need to call `put()` method, which accepts
106122
two arguments: the data you want to process and optional array of task options, which this particular
107-
queue supports. For example, `fifottl` queue (which we defined earlier in our Lua config file),
108-
supports `delay`, `ttl`, `ttr` and `pri` options:
123+
queue supports. For example, `fifottl` queue (which we defined [earlier](#before-start) in our Lua config
124+
file), supports `delay`, `ttl`, `ttr` and `pri` options:
109125

110126
```php
111127
use Tarantool\Queue\Options;
112128

113-
$queue->put('foo', [Options::DELAY => 30]);
114-
$queue->put('bar', [Options::TTL => 5]);
115-
$queue->put('baz', [Options::TTR => 10, Options::PRI => 42]);
129+
$queue->put('foo', [Options::DELAY => 30.0]);
130+
$queue->put('bar', [Options::TTL => 5.0]);
131+
$queue->put('baz', [Options::TTR => 10.0, Options::PRI => 42]);
116132
```
117133

118134
> *See the full list of available options [here](https://github.com/tarantool/queue#queue-types).*
@@ -128,7 +144,7 @@ The method returns either a [Task](#tasks) object or `null`:
128144
$taskOrNull = $queue->take();
129145

130146
// wait 2 seconds
131-
$taskOrNull = $queue->take(2);
147+
$taskOrNull = $queue->take(2.0);
132148

133149
// wait 100 milliseconds
134150
$taskOrNull = $queue->take(.1);
@@ -150,7 +166,7 @@ Or put back into the queue in case it cannot be executed:
150166
$task = $queue->release($task->getId());
151167

152168
// for *ttl queues you can specify a delay
153-
$task = $queue->release($task->getId(), [Options::DELAY => 30]);
169+
$task = $queue->release($task->getId(), [Options::DELAY => 30.0]);
154170
```
155171

156172
To look at a task without changing its state, use:
@@ -174,7 +190,7 @@ $count = $queue->kick(3); // kick 3 buried tasks
174190
To increase TTR and/or TTL of a running task (only for *ttl queues):
175191

176192
```php
177-
$taskOrNull = $queue->touch($takenTask->getId(), 5); // increase ttr/ttl to 5 seconds
193+
$taskOrNull = $queue->touch($takenTask->getId(), 5.0); // increase ttr/ttl to 5 seconds
178194
```
179195

180196
A task (in any state) can be deleted permanently with `delete()`:
@@ -259,41 +275,41 @@ end
259275
To call this method on a `$queue` object, use `Queue::call()`:
260276

261277
```php
262-
$result = $queue->call('put_many', [[
263-
'foo' => ['foo', [Options::DELAY => 30]],
278+
$result = $queue->call('put_many', [
279+
'foo' => ['foo', [Options::DELAY => 30.0]],
264280
'bar' => ['bar'],
265-
]]);
281+
]);
266282
```
267283

268284

269285
## Tests
270286

271287
The easiest way to run tests is with Docker. First, build an image using the [dockerfile.sh](dockerfile.sh) generator:
272288

273-
```sh
274-
$ ./dockerfile.sh | docker build -t queue -
289+
```bash
290+
./dockerfile.sh | docker build -t queue -
275291
```
276292

277293
Then run Tarantool instance (needed for integration tests):
278294

279-
```sh
280-
$ docker network create tarantool-php
281-
$ docker run -d --net=tarantool-php --name=tarantool -v `pwd`:/queue \
295+
```bash
296+
docker network create tarantool-php
297+
docker run -d --net=tarantool-php --name=tarantool -v `pwd`:/queue \
282298
tarantool/tarantool:1 tarantool /queue/tests/Integration/queues.lua
283299
```
284300

285301
And then run both unit and integration tests:
286302

287-
```sh
288-
$ docker run --rm --net=tarantool-php --name=queue -v `pwd`:/queue -w /queue queue
303+
```bash
304+
docker run --rm --net=tarantool-php --name=queue -v `pwd`:/queue -w /queue queue
289305
```
290306

291307
To run only integration or unit tests, set the `PHPUNIT_OPTS` environment variable
292-
to either `--testsuite Integration` or `--testsuite Unit` respectively, e.g.:
308+
to either `--testsuite integration` or `--testsuite unit` respectively, e.g.:
293309

294-
```sh
295-
$ docker run --rm --net=tarantool-php --name=queue -v `pwd`:/queue -w /queue \
296-
-e PHPUNIT_OPTS='--testsuite Unit' queue
310+
```bash
311+
docker run --rm --net=tarantool-php --name=queue -v `pwd`:/queue -w /queue \
312+
-e PHPUNIT_OPTS='--testsuite unit' queue
297313
```
298314

299315

composer.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^5.4|^7.0"
14+
"php": "^7.1"
1515
},
1616
"require-dev": {
17+
"friendsofphp/php-cs-fixer": "^2.13",
18+
"phpunit/phpunit": "^7.4",
1719
"rybakit/msgpack": "@dev",
1820
"tarantool/client": "@dev"
1921
},
@@ -30,5 +32,11 @@
3032
"psr-4": {
3133
"Tarantool\\Queue\\Tests\\": "tests/"
3234
}
35+
},
36+
"config": {
37+
"preferred-install": {
38+
"*": "dist"
39+
},
40+
"sort-packages": true
3341
}
3442
}

dockerfile.sh

+16-16
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ if [[ -z "$TNT_CLIENT" ]] ; then
88
TNT_CLIENT='pure'
99
fi
1010

11-
RUN_CMDS=''
12-
RUN_POST_CMDS=''
13-
14-
if [[ $IMAGE == php* ]]; then
15-
RUN_CMDS="$RUN_CMDS && \\\\\n docker-php-ext-install zip"
16-
if [[ $TNT_CLIENT == pure ]]; then
17-
RUN_POST_CMDS="$RUN_POST_CMDS && \\\\\n composer require tarantool/client:@dev"
18-
else
19-
RUN_CMDS="$RUN_CMDS && \\\\\n git clone https://github.com/tarantool/tarantool-php.git /usr/src/php/ext/tarantool"
20-
if [[ $IMAGE == php:7* ]]; then RUN_CMDS="$RUN_CMDS && \\\\\n git --git-dir=/usr/src/php/ext/tarantool/.git --work-tree=/usr/src/php/ext/tarantool checkout php7-v2"; fi
21-
RUN_CMDS="$RUN_CMDS && \\\\\n echo tarantool >> /usr/src/php-available-exts && docker-php-ext-install tarantool"
22-
fi
11+
if [[ $TNT_CLIENT == pecl ]]; then
12+
RUN_CMDS="$RUN_CMDS && \\\\\n git clone https://github.com/tarantool/tarantool-php.git /usr/src/php/ext/tarantool"
13+
RUN_CMDS="$RUN_CMDS && \\\\\n git --git-dir=/usr/src/php/ext/tarantool/.git --work-tree=/usr/src/php/ext/tarantool checkout php7-v2"
14+
RUN_CMDS="$RUN_CMDS && \\\\\n echo tarantool >> /usr/src/php-available-exts && docker-php-ext-install tarantool"
15+
COMPOSER_REMOVE='tarantool/client'
2316
fi
2417

2518
if [[ $PHPUNIT_OPTS =~ (^|[[:space:]])--coverage-[[:alpha:]] ]]; then
2619
RUN_CMDS="$RUN_CMDS && \\\\\n pecl install xdebug && docker-php-ext-enable xdebug"
2720
fi
2821

22+
if [[ "1" != "$CHECK_CS" ]]; then
23+
COMPOSER_REMOVE="$COMPOSER_REMOVE friendsofphp/php-cs-fixer"
24+
fi
25+
2926
echo -e "
3027
FROM $IMAGE
3128
3229
RUN apt-get update && \\
33-
apt-get install -y git curl zlib1g-dev${RUN_CMDS} && \\
34-
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \\
35-
composer global require 'phpunit/phpunit'${RUN_POST_CMDS}
30+
apt-get install -y git curl libzip-dev && \\
31+
docker-php-ext-configure zip --with-libzip && \\
32+
docker-php-ext-install zip${RUN_CMDS}
33+
34+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
3635
3736
ENV PATH=~/.composer/vendor/bin:\$PATH
3837
ENV TARANTOOL_HOST=tarantool TARANTOOL_PORT=3301
3938
40-
CMD if [ ! -f composer.lock ]; then composer install; fi && ~/.composer/vendor/bin/phpunit\${PHPUNIT_OPTS:+ }\$PHPUNIT_OPTS
39+
CMD if [ ! -f composer.lock ]; then ${COMPOSER_REMOVE:+composer remove --dev --no-update }$COMPOSER_REMOVE${COMPOSER_REMOVE:+ && }composer install; fi && \\
40+
vendor/bin/phpunit\${PHPUNIT_OPTS:+ }\$PHPUNIT_OPTS
4141
"

phpunit.xml.dist

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
12-
verbose="true"
13-
bootstrap="tests/bootstrap.php"
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
colors="true"
5+
verbose="true"
6+
bootstrap="vendor/autoload.php"
147
>
158
<php>
169
<ini name="date.timezone" value="UTC" />
@@ -23,11 +16,11 @@
2316
</php>
2417

2518
<testsuites>
26-
<testsuite name="Unit">
19+
<testsuite name="unit">
2720
<directory>tests/Unit</directory>
2821
</testsuite>
2922

30-
<testsuite name="Integration">
23+
<testsuite name="integration">
3124
<directory>tests/Integration</directory>
3225
</testsuite>
3326
</testsuites>

0 commit comments

Comments
 (0)