Skip to content
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

Update codebase to PHP 7.4 #6

Merged
merged 1 commit into from
Nov 30, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":[
Expand All @@ -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/"]
},
Expand Down
11 changes: 8 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
74 changes: 31 additions & 43 deletions src/Codeception/Module/Memcache.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

declare(strict_types=1);

namespace Codeception\Module;

use Codeception\Module as CodeceptionModule;
use Codeception\Module;
use Codeception\TestInterface;
use Codeception\Exception\ModuleConfigException;
use Memcached;

/**
* Connects to [memcached](http://www.memcached.org/) using either _Memcache_ or _Memcached_ extension.
Expand Down Expand Up @@ -37,15 +41,15 @@
* * **memcache** - instance of _Memcache_ or _Memcached_ object
*
*/
class Memcache extends CodeceptionModule
class Memcache extends Module
{
/**
* @var \Memcache|\Memcached
* @var \Memcache|Memcached
*/
public $memcache = null;

/**
* {@inheritdoc}
* @var array
*/
protected $config = [
'host' => 'localhost',
Expand All @@ -55,7 +59,6 @@ class Memcache extends CodeceptionModule
/**
* Code to run before each test.
*
* @param TestInterface $test
* @throws ModuleConfigException
*/
public function _before(TestInterface $test)
Expand All @@ -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');
Expand All @@ -73,8 +76,6 @@ public function _before(TestInterface $test)

/**
* Code to run after each test.
*
* @param TestInterface $test
*/
public function _after(TestInterface $test)
{
Expand All @@ -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();
}
}

Expand All @@ -101,10 +99,9 @@ public function _after(TestInterface $test)
* ``` php
* <?php
* $users_count = $I->grabValueFromMemcached('users_count');
* ?>
* ```
*
* @param $key
* @param string|array $key
* @return array|string
*/
public function grabValueFromMemcached($key)
Expand All @@ -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");
}
}

Expand All @@ -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();
}
Expand Down