From d1d61638f9c7122eea467c8ec0dd5c912beda01b Mon Sep 17 00:00:00 2001 From: Vincent Dechenaux Date: Fri, 24 Nov 2017 10:18:50 +0100 Subject: [PATCH 1/4] Add PHP 7.2 (and 7.1) to travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 478b271..d68d366 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ php: - 5.5 - 5.6 - 7 + - 7.1 + - 7.2 before_script: - wget http://getcomposer.org/composer.phar From a1aaa8b0d1d087571327c8e1a1db96ac0c347154 Mon Sep 17 00:00:00 2001 From: Vincent Dechenaux Date: Fri, 24 Nov 2017 10:21:03 +0100 Subject: [PATCH 2/4] Fix warnings with PHP 7.2 --- src/M6Web/Component/RedisMock/RedisMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/M6Web/Component/RedisMock/RedisMock.php b/src/M6Web/Component/RedisMock/RedisMock.php index bc4edc0..f392016 100644 --- a/src/M6Web/Component/RedisMock/RedisMock.php +++ b/src/M6Web/Component/RedisMock/RedisMock.php @@ -230,7 +230,7 @@ public function del($key) $deletedKeyCount = 0; foreach ( $keys as $k ) { if ( isset(self::$dataValues[$this->storage][$k]) ) { - $deletedKeyCount += count(self::$dataValues[$this->storage][$k]); + $deletedKeyCount += is_array(self::$dataValues[$this->storage][$k]) ? count(self::$dataValues[$this->storage][$k]) : 1; unset(self::$dataValues[$this->storage][$k]); unset(self::$dataTypes[$this->storage][$k]); if (array_key_exists($k, self::$dataTtl[$this->storage])) { From d95ed32c46528c4ae2a86c84538454eab112ecb3 Mon Sep 17 00:00:00 2001 From: Vincent Dechenaux Date: Fri, 24 Nov 2017 13:45:43 +0100 Subject: [PATCH 3/4] Fix tests with PHP >= 7.1 --- tests/units/RedisMockFactory.php | 52 +++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/units/RedisMockFactory.php b/tests/units/RedisMockFactory.php index a6a3d66..aa0b1f0 100644 --- a/tests/units/RedisMockFactory.php +++ b/tests/units/RedisMockFactory.php @@ -124,7 +124,8 @@ public function testGetAdapterClass() /** * Build mock by using 'orphanizeConstruct' parameter - * + * + * @php < 7.1 * @return void */ public function testOrphanizeConstruct() { @@ -170,6 +171,55 @@ public function testOrphanizeConstruct() { ->notExists(); } + /** + * Build mock by using 'orphanizeConstruct' parameter + * + * @php >= 7.1 + * @return void + */ + public function testOrphanizeConstructAfterPhp7Dot1() { + $factory = new Factory(); + $this->assert + ->exception(function() use ($factory) { + $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, false); + }) + ->isInstanceOf(\ArgumentCountError::class); + + $mock = $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor'); + + $this->assert + ->object($mock) + ->isInstanceOf('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter') + ->class(get_class($mock)) + ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor'); + + $this->assert + ->string($class = $factory->getAdapterClass('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor')) + ->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter_NativeConstructor') + ->class($class) + ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor') + ->exception(function() use ($class) { + $mock = new $class(); + }) + ->isInstanceOf(\ArgumentCountError::class); + + $this->assert + ->when(function() use ($class) { + $mock = new $class(null); + }) + ->error() + ->notExists() + ->string($class2 = $factory->getAdapterClass('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, true)) + ->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter') + ->class($class2) + ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor') + ->when(function() use ($class2) { + $mock = new $class2(); + }) + ->error() + ->notExists(); + } + /** * Test the mock with a base class that implement unsupported Redis commands * From b34290c8a2597ffdb48fa0b7514e016d9300c114 Mon Sep 17 00:00:00 2001 From: Vincent Dechenaux Date: Sat, 25 Nov 2017 00:30:29 +0100 Subject: [PATCH 4/4] Drop support of versions older than 7.1 --- .travis.yml | 5 --- README.md | 2 +- composer.json | 2 +- tests/units/RedisMockFactory.php | 62 ++++---------------------------- 4 files changed, 8 insertions(+), 63 deletions(-) diff --git a/.travis.yml b/.travis.yml index d68d366..ab65f0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,6 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7 - 7.1 - 7.2 diff --git a/README.md b/README.md index 80a97b1..ed0bab4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Redis PHP Mock [![Build Status](https://secure.travis-ci.org/M6Web/RedisMock.svg?branch=master)](http://travis-ci.org/M6Web/RedisMock) [![Total Downloads](https://poser.pugx.org/m6web/redis-mock/downloads.svg)](https://packagist.org/packages/m6web/redis-mock) -PHP 5.3 library providing a Redis PHP mock for your tests. +PHP 7.1 library providing a Redis PHP mock for your tests. **Work for now only with predis** diff --git a/composer.json b/composer.json index 597ab1e..f0dac48 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "psr-0": {"M6Web\\Component\\RedisMock": "src/"} }, "require": { - "php": ">=5.3.3" + "php": ">=7.1.0" }, "require-dev": { "atoum/atoum": "master-dev", diff --git a/tests/units/RedisMockFactory.php b/tests/units/RedisMockFactory.php index aa0b1f0..4e20297 100644 --- a/tests/units/RedisMockFactory.php +++ b/tests/units/RedisMockFactory.php @@ -125,17 +125,15 @@ public function testGetAdapterClass() /** * Build mock by using 'orphanizeConstruct' parameter * - * @php < 7.1 * @return void */ public function testOrphanizeConstruct() { $factory = new Factory(); $this->assert - ->when(function() use ($factory) { + ->exception(function() use ($factory) { $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, false); }) - ->error() - ->exists(); + ->isInstanceOf(\ArgumentCountError::class);; $mock = $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor'); @@ -150,11 +148,12 @@ public function testOrphanizeConstruct() { ->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter_NativeConstructor') ->class($class) ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor') - ->when(function() use ($class) { + ->exception(function() use ($class) { $mock = new $class(); }) - ->error() - ->exists() + ->isInstanceOf(\ArgumentCountError::class); + + $this->assert ->when(function() use ($class) { $mock = new $class(null); }) @@ -171,55 +170,6 @@ public function testOrphanizeConstruct() { ->notExists(); } - /** - * Build mock by using 'orphanizeConstruct' parameter - * - * @php >= 7.1 - * @return void - */ - public function testOrphanizeConstructAfterPhp7Dot1() { - $factory = new Factory(); - $this->assert - ->exception(function() use ($factory) { - $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, false); - }) - ->isInstanceOf(\ArgumentCountError::class); - - $mock = $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor'); - - $this->assert - ->object($mock) - ->isInstanceOf('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter') - ->class(get_class($mock)) - ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor'); - - $this->assert - ->string($class = $factory->getAdapterClass('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor')) - ->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter_NativeConstructor') - ->class($class) - ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor') - ->exception(function() use ($class) { - $mock = new $class(); - }) - ->isInstanceOf(\ArgumentCountError::class); - - $this->assert - ->when(function() use ($class) { - $mock = new $class(null); - }) - ->error() - ->notExists() - ->string($class2 = $factory->getAdapterClass('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, true)) - ->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter') - ->class($class2) - ->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor') - ->when(function() use ($class2) { - $mock = new $class2(); - }) - ->error() - ->notExists(); - } - /** * Test the mock with a base class that implement unsupported Redis commands *