8000 Update to require PHP 7.1+ by clue · Pull Request #58 · reactphp/cache · GitHub
[go: up one dir, main page]

Skip to content

Update to require PHP 7.1+ #58

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

Merged
merged 2 commits into from
Feb 13, 2024
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
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand All @@ -36,19 +31,3 @@ jobs:
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}

PHPUnit-hhvm:
name: PHPUnit (HHVM)
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- name: Run hhvm composer.phar require react/promise:^2 # downgrade Promise for HHVM
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm composer.phar require react/promise:^2
- name: Run hhvm vendor/bin/phpunit
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm vendor/bin/phpunit
13 changes: 6 additions & 7 deletions README.md
10000
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Similarly, an expired cache item (once the time-to-live is expired) is
considered a cache miss.

```php
$cache->getMultiple(array('name', 'age'))->then(function (array $values) {
$cache->getMultiple(['name', 'age'])->then(function (array $values) {
$name = $values['name'] ?? 'User';
$age = $values['age'] ?? 'n/a';

Expand Down Expand Up @@ -170,7 +170,7 @@ supports. Trying to access an expired cache items results in a cache miss,
see also [`getMultiple()`](#getmultiple).

```php
$cache->setMultiple(array('foo' => 1, 'bar' => 2), 60);
$cache->setMultiple(['foo' => 1, 'bar' => 2], 60);
```

This example eventually sets the list of values - the key `foo` to `1` value
Expand All @@ -187,7 +187,7 @@ to `true`. If the cache implementation has to go over the network to
delete it, it may take a while.

```php
$cache->deleteMultiple(array('foo', 'bar, 'baz'));
$cache->deleteMultiple(['foo', 'bar, 'baz']);
```

This example eventually deletes keys `foo`, `bar` and `baz` from the cache.
Expand Down Expand Up @@ -322,7 +322,7 @@ public function getAndCacheFooFromDb()
{
return $this->db
->get('foo')
->then(array($this, 'cacheFooFromDb'));
->then([$this, 'cacheFooFromDb']);
}

public function cacheFooFromDb($foo)
Expand Down Expand Up @@ -351,9 +351,8 @@ composer require react/cache:^3@dev
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
HHVM.
It's *highly recommended to use PHP 7+* for this project.
extensions and supports running on PHP 7.1 through current PHP 8+.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
}
],
"require": {
"php": ">=5.3.0",
"php": ">=7.1",
"react/promise": "^3.0 || ^2.0 || ^1.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
"phpunit/phpunit": "^9.6 || ^7.5"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
34 changes: 17 additions & 17 deletions src/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace React\Cache;

use React\Promise;
use React\Promise\PromiseInterface;
use function React\Promise\all;
use function React\Promise\resolve;

class ArrayCache implements CacheInterface
{
private $limit;
private $data = array();
private $expires = array();
private $data = [];
private $expires = [];
private $supportsHighResolution;

/**
Expand Down Expand Up @@ -65,15 +65,15 @@ public function get($key, $default = null)
}

if (!\array_key_exists($key, $this->data)) {
return Promise\resolve($default);
return resolve($default);
}

// remove and append to end of array to keep track of LRU info
$value = $this->data[$key];
unset($this->data[$key]);
$this->data[$key] = $value;

return Promise\resolve($value);
return resolve($value);
}

public function set($key, $value, $ttl = null)
Expand Down Expand Up @@ -105,25 +105,25 @@ public function set($key, $value, $ttl = null)
unset($this->data[$key], $this->expires[$key]);
}

return Promise\resolve(true);
return resolve(true);
}

public function delete($key)
{
unset($this->data[$key], $this->expires[$key]);

return Promise\resolve(true);
return resolve(true);
}

public function getMultiple(array $keys, $default = null)
{
$values = array();
$values = [];

foreach ($keys as $key) {
$values[$key] = $this->get($key, $default);
}

return Promise\all($values);
return all($values);
}

public function setMultiple(array $values, $ttl = null)
Expand All @@ -132,7 +132,7 @@ public function setMultiple(array $values, $ttl = null)
$this->set($key, $value, $ttl);
}

return Promise\resolve(true);
return resolve(true);
}

public function deleteMultiple(array $keys)
Expand All @@ -141,15 +141,15 @@ public function deleteMultiple(array $keys)
unset($this->data[$key], $this->expires[$key]);
}

return Promise\resolve(true);
return resolve(true);
}

public function clear()
{
$this->data = array();
$this->expires = array();
$this->data = [];
$this->expires = [];

return Promise\resolve(true);
return resolve(true);
}

public function has($key)
Expand All @@ -160,15 +160,15 @@ public function has($key)
}

if (!\array_key_exists($key, $this->data)) {
return Promise\resolve(false);
return resolve(false);
}

// remove and append to end of array to keep track of LRU info
$value = $this->data[$key];
unset($this->data[$key]);
$this->data[$key] = $value;

return Promise\resolve(true);
return resolve(true);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/CacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function delete($key);
* considered a cache miss.
*
* ```php
* $cache->getMultiple(array('name', 'age'))->then(function (array $values) {
* $cache->getMultiple(['name', 'age'])->then(function (array $values) {
* $name = $values['name'] ?? 'User';
* $age = $values['age'] ?? 'n/a';
*
Expand Down Expand Up @@ -138,7 +138,7 @@ public function getMultiple(array $keys, $default = null);
* see also [`get()`](#get).
*
* ```php
* $cache->setMultiple(array('foo' => 1, 'bar' => 2), 60);
* $cache->setMultiple(['foo' => 1, 'bar' => 2], 60);
* ```
*
* This example eventually sets the list of values - the key `foo` to 1 value
Expand Down
16 changes: 8 additions & 8 deletions tests/ArrayCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,27 @@ public function testGetMultiple()
$this->cache->set('foo', '1');

$this->cache
->getMultiple(array('foo', 'bar'), 'baz')
->then($this->expectCallableOnceWith(array('foo' => '1', 'bar' => 'baz')));
->getMultiple(['foo', 'bar'], 'baz')
->then($this->expectCallableOnceWith(['foo' => '1', 'bar' => 'baz']));
}

public function testSetMultiple()
{
$this->cache = new ArrayCache();
$this->cache->setMultiple(array('foo' => '1', 'bar' => '2'), 10);
$this->cache->setMultiple(['foo' => '1', 'bar' => '2'], 10);

$this->cache
->getMultiple(array('foo', 'bar'))
->then($this->expectCallableOnceWith(array('foo' => '1', 'bar' => '2')));
->getMultiple(['foo', 'bar'])
->then($this->expectCallableOnceWith(['foo' => '1', 'bar' => '2']));
}

public function testDeleteMultiple()
{
$this->cache = new ArrayCache();
$this->cache->setMultiple(array('foo' => 1, 'bar' => 2, 'baz' => 3));
$this->cache->setMultiple(['foo' => 1, 'bar' => 2, 'baz' => 3]);

$this->cache
->deleteMultiple(array('foo', 'baz'))
->deleteMultiple(['foo', 'baz'])
->then($this->expectCallableOnceWith(true));

$this->cache
Expand All @@ -242,7 +242,7 @@ public function testDeleteMultiple()
public function testClearShouldClearCache()
{
$this->cache = new ArrayCache();
$this->cache->setMultiple(array('foo' => 1, 'bar' => 2, 'baz' => 3));
$this->cache->setMultiple(['foo' => 1, 'bar' => 2, 'baz' => 3]);

$this->cache->clear();

Expand Down
9 changes: 5 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ protected function expectCallableNever()

protected function createCallableMock()
{
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
$builder = $this->getMockBuilder(\stdClass::class);
if (method_exists($builder, 'addMethods')) {
// PHPUnit 9+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
return $builder->addMethods(['__invoke'])->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 9
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
// legacy PHPUnit
return $builder->setMethods(['__invoke'])->getMock();
}
}
}
0