diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc13173..ab7eb8b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.4, 8.0, 8.1] steps: - name: Checkout code diff --git a/composer.json b/composer.json index b285667..1ce465e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name":"codeception/module-memcache", "description":"Memcache module for Codeception", "keywords":["codeception", "memcache"], - "homepage":"http://codeception.com/", + "homepage":"https://codeception.com/", "type":"library", "license":"MIT", "authors":[ @@ -12,9 +12,13 @@ ], "minimum-stability": "RC", "require": { - "php": ">=5.6.0 <9.0", + "php": "^7.4 | ^8.0", "codeception/codeception": "^4.0" }, + "require-dev": { + "ext-memcache": "*", + "ext-memcached": "*" + }, "autoload":{ "classmap": ["src/"] }, diff --git a/readme.md b/readme.md index e24ac3d..990ba7d 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,16 @@ -# Memcache module for Codeception +# Codeception Module Memcache -[![Build Status](https://github.com/Codeception/module-memcache/workflows/CI/badge.svg)](https://github.com/Codeception/module-memcache/actions) +Memcache module for Codeception. + +[![Actions Status](https://github.com/Codeception/module-memcache/workflows/CI/badge.svg)](https://github.com/Codeception/module-memcache/actions) +[![Latest Stable Version](https://poser.pugx.org/codeception/module-memcache/v/stable)](https://github.com/Codeception/module-memcache/releases) +[![Total Downloads](https://poser.pugx.org/codeception/module-memcache/downloads)](https://packagist.org/packages/codeception/module-memcache) +[![License](https://poser.pugx.org/codeception/module-memcache/license)](/LICENSE) ## Installation ``` -composer require --dev "codeception/module-memcache" +composer require "codeception/module-memcache" --dev ``` ## Documentation diff --git a/src/Codeception/Module/Memcache.php b/src/Codeception/Module/Memcache.php index 69ce2e0..869933b 100644 --- a/src/Codeception/Module/Memcache.php +++ b/src/Codeception/Module/Memcache.php @@ -1,9 +1,13 @@ 'localhost', @@ -55,7 +59,6 @@ class Memcache extends CodeceptionModule /** * Code to run before each test. * - * @param TestInterface $test * @throws ModuleConfigException */ public function _before(TestInterface $test) @@ -64,7 +67,7 @@ public function _before(TestInterface $test) $this->memcache = new \Memcache; $this->memcache->connect($this->config['host'], $this->config['port']); } elseif (class_exists('\Memcached')) { - $this->memcache = new \Memcached; + $this->memcache = new Memcached; $this->memcache->addServer($this->config['host'], $this->config['port']); } else { throw new ModuleConfigException(__CLASS__, 'Memcache classes not loaded'); @@ -73,8 +76,6 @@ public function _before(TestInterface $test) /** * Code to run after each test. - * - * @param TestInterface $test */ public function _after(TestInterface $test) { @@ -83,13 +84,10 @@ public function _after(TestInterface $test) } $this->memcache->flush(); - switch (get_class($this->memcache)) { - case 'Memcache': - $this->memcache->close(); - break; - case 'Memcached': - $this->memcache->quit(); - break; + if (get_class($this->memcache) == 'Memcache') { + $this->memcache->close(); + } elseif (get_class($this->memcache) == 'Memcached') { + $this->memcache->quit(); } } @@ -101,10 +99,9 @@ public function _after(TestInterface $test) * ``` php * grabValueFromMemcached('users_count'); - * ?> * ``` * - * @param $key + * @param string|array $key * @return array|string */ public function grabValueFromMemcached($key) @@ -127,21 +124,20 @@ public function grabValueFromMemcached($key) * * // Checks a 'users_count' exists and has the value 200 * $I->seeInMemcached('users_count', 200); - * ?> * ``` * - * @param $key - * @param $value + * @param string|array $key + * @param mixed $value */ - public function seeInMemcached($key, $value = null) + public function seeInMemcached($key, $value = null): void { $actual = $this->memcache->get($key); $this->debugSection("Value", $actual); if (null === $value) { - $this->assertNotFalse($actual, "Cannot find key '$key' in Memcached"); + $this->assertNotFalse($actual, "Cannot find key '{$key}' in Memcached"); } else { - $this->assertEquals($value, $actual, "Cannot find key '$key' in Memcached with the provided value"); + $this->assertEquals($value, $actual, "Cannot find key '{$key}' in Memcached with the provided value"); } } @@ -157,49 +153,41 @@ public function seeInMemcached($key, $value = null) * * // Checks a 'users_count' exists does not exist or its value is not the one provided * $I->dontSeeInMemcached('users_count', 200); - * ?> * ``` * - * @param $key - * @param $value + * @param string|array $key + * @param mixed $value */ - public function dontSeeInMemcached($key, $value = null) + public function dontSeeInMemcached($key, $value = null): void { $actual = $this->memcache->get($key); $this->debugSection("Value", $actual); if (null === $value) { - $this->assertFalse($actual, "The key '$key' exists in Memcached"); - } else { - if (false !== $actual) { - $this->assertEquals($value, $actual, "The key '$key' exists in Memcached with the provided value"); - } + $this->assertFalse($actual, "The key '{$key}' exists in Memcached"); + } elseif (false !== $actual) { + $this->assertEquals($value, $actual, "The key '{$key}' exists in Memcached with the provided value"); } } /** * Stores an item `$value` with `$key` on the Memcached server. * - * @param string $key * @param mixed $value - * @param int $expiration */ - public function haveInMemcached($key, $value, $expiration = null) + public function haveInMemcached(string $key, $value, int $expiration = null): void { - switch (get_class($this->memcache)) { - case 'Memcache': - $this->assertTrue($this->memcache->set($key, $value, null, $expiration)); - break; - case 'Memcached': - $this->assertTrue($this->memcache->set($key, $value, $expiration)); - break; + if (get_class($this->memcache) == 'Memcache') { + $this->assertTrue($this->memcache->set($key, $value, null, $expiration)); + } elseif (get_class($this->memcache) == 'Memcached') { + $this->assertTrue($this->memcache->set($key, $value, $expiration)); } } /** * Flushes all Memcached data. */ - public function clearMemcache() + public function clearMemcache(): void { $this->memcache->flush(); }