...
 
Commits (4)
...@@ -2,6 +2,7 @@ variables: ...@@ -2,6 +2,7 @@ variables:
# Configure mysql service (https://hub.docker.com/_/mysql/) # Configure mysql service (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: wordpress_tests MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: mysql MYSQL_ROOT_PASSWORD: mysql
PECL_REDIS_VERSION: 'redis'
WP_VERSION: latest WP_VERSION: latest
cache: cache:
...@@ -13,6 +14,10 @@ before_script: ...@@ -13,6 +14,10 @@ before_script:
# Set up WordPress tests # Set up WordPress tests
- bash bin/install-wp-tests.sh $MYSQL_DATABASE root $MYSQL_ROOT_PASSWORD mysql $WP_VERSION true - bash bin/install-wp-tests.sh $MYSQL_DATABASE root $MYSQL_ROOT_PASSWORD mysql $WP_VERSION true
# Install PECL extension we rely on
- pecl config-set php_ini /tmp/php.ini
- yes '' | pecl install -f $PECL_REDIS_VERSION
# PHPUnit # PHPUnit
- | - |
if [[ $(php -v) =~ "PHP 7." ]]; then if [[ $(php -v) =~ "PHP 7." ]]; then
...@@ -25,18 +30,23 @@ PHPunit:PHP5.3:MySQL: ...@@ -25,18 +30,23 @@ PHPunit:PHP5.3:MySQL:
stage: test stage: test
variables: variables:
WP_VERSION: '5.1' WP_VERSION: '5.1'
PECL_REDIS_VERSION: 'redis-2.2.8'
image: containers.ethitter.com:443/docker/images/php:5.3 image: containers.ethitter.com:443/docker/images/php:5.3
services: services:
- mysql:5.6 - mysql:5.6
- redis:latest
script: script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l - find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit - phpunit
PHPunit:PHP5.6:MySQL: PHPunit:PHP5.6:MySQL:
stage: test stage: test
variables:
PECL_REDIS_VERSION: 'redis-2.2.8'
image: containers.ethitter.com:443/docker/images/php:5.6 image: containers.ethitter.com:443/docker/images/php:5.6
services: services:
- mysql:5.6 - mysql:5.6
- redis:latest
script: script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l - find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit - phpunit
...@@ -46,6 +56,7 @@ PHPunit:PHP7.0:MySQL: ...@@ -46,6 +56,7 @@ PHPunit:PHP7.0:MySQL:
image: containers.ethitter.com:443/docker/images/php:7.0 image: containers.ethitter.com:443/docker/images/php:7.0
services: services:
- mysql:5.6 - mysql:5.6
- redis:latest
script: script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l - find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit - phpunit
...@@ -55,6 +66,7 @@ PHPunit:PHP7.1:MySQL: ...@@ -55,6 +66,7 @@ PHPunit:PHP7.1:MySQL:
image: containers.ethitter.com:443/docker/images/php:7.1 image: containers.ethitter.com:443/docker/images/php:7.1
services: services:
- mysql:5.6 - mysql:5.6
- redis:latest
script: script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l - find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit - phpunit
...@@ -64,6 +76,7 @@ PHPunit:PHP7.2:MySQL: ...@@ -64,6 +76,7 @@ PHPunit:PHP7.2:MySQL:
image: containers.ethitter.com:443/docker/images/php:7.2 image: containers.ethitter.com:443/docker/images/php:7.2
services: services:
- mysql:5.6 - mysql:5.6
- redis:latest
script: script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l - find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit - phpunit
...@@ -73,6 +86,7 @@ PHPunit:PHP7.3:MySQL: ...@@ -73,6 +86,7 @@ PHPunit:PHP7.3:MySQL:
image: containers.ethitter.com:443/docker/images/php:7.3 image: containers.ethitter.com:443/docker/images/php:7.3
services: services:
- mysql:5.6 - mysql:5.6
- redis:latest
script: script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l - find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit - phpunit
......
...@@ -16,7 +16,7 @@ Store WordPress user session tokens in Redis rather than the usermeta table. ...@@ -16,7 +16,7 @@ Store WordPress user session tokens in Redis rather than the usermeta table.
## Installation ## ## Installation ##
1. Install and configure Redis. There is a good tutorial [here](http://www.saltwebsites.com/2012/install-redis-245-service-centos-6). 1. Install and configure Redis. There is a good tutorial [here](https://serverpilot.io/docs/how-to-install-the-php-redis-extension).
2. Install the [Redis PECL module](http://pecl.php.net/package/redis). 2. Install the [Redis PECL module](http://pecl.php.net/package/redis).
3. Activate the plugin network-wide or by placing it in `mu-plugins`. 3. Activate the plugin network-wide or by placing it in `mu-plugins`.
4. By default, the script will connect to Redis at 127.0.0.1:6379. See the *Connecting to Redis* section for further options. 4. By default, the script will connect to Redis at 127.0.0.1:6379. See the *Connecting to Redis* section for further options.
......
...@@ -269,6 +269,15 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens { ...@@ -269,6 +269,15 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens {
protected function get_key() { protected function get_key() {
return $this->prefix . ':' . $this->user_id; return $this->prefix . ':' . $this->user_id;
} }
/**
* Is Redis connected?
*
* @return bool
*/
public function redis_connected() {
return $this->redis_connected;
}
} }
/** /**
......
<?php
/**
* Plugin tests
*
* @package WP_Redis_User_Session_Storage
*/
/**
* Class Test_Plugin.
*/
class Test_Plugin extends WP_UnitTestCase {
/**
* Check that Redis backend is available.
*/
public function test_connection() {
$this->assertTrue(
WP_Session_Tokens::get_instance( 0 )->redis_connected(),
'Failed to assert that Redis is available.'
);
}
}
<?php
/**
* Class SampleTest
*
* @package WP_Redis_User_Session_Storage
*/
/**
* Sample test case.
*/
class SampleTest extends WP_UnitTestCase {
/**
* A single example test.
*/
public function test_sample() {
// Replace this with some actual testing code.
$this->assertTrue( true );
}
}