From e8c6e5671c4fc2970428af5ab5f0943d1f8ecd79 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Mon, 3 Jun 2019 20:30:25 -0700 Subject: [PATCH] Begin tests --- .gitlab-ci.yml | 6 ++++++ inc/class-wp-redis-user-session-storage.php | 9 +++++++++ tests/test-plugin.php | 21 +++++++++++++++++++++ tests/test-sample.php | 20 -------------------- 4 files changed, 36 insertions(+), 20 deletions(-) create mode 100755 tests/test-plugin.php delete mode 100755 tests/test-sample.php diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e03fb8..0bd1e99 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,7 @@ PHPunit:PHP5.3:MySQL: image: containers.ethitter.com:443/docker/images/php:5.3 services: - mysql:5.6 + - redis:latest script: - find . -type "f" -iname "*.php" | xargs -L "1" php -l - phpunit @@ -37,6 +38,7 @@ PHPunit:PHP5.6:MySQL: image: containers.ethitter.com:443/docker/images/php:5.6 services: - mysql:5.6 + - redis:latest script: - find . -type "f" -iname "*.php" | xargs -L "1" php -l - phpunit @@ -46,6 +48,7 @@ PHPunit:PHP7.0:MySQL: image: containers.ethitter.com:443/docker/images/php:7.0 services: - mysql:5.6 + - redis:latest script: - find . -type "f" -iname "*.php" | xargs -L "1" php -l - phpunit @@ -55,6 +58,7 @@ PHPunit:PHP7.1:MySQL: image: containers.ethitter.com:443/docker/images/php:7.1 services: - mysql:5.6 + - redis:latest script: - find . -type "f" -iname "*.php" | xargs -L "1" php -l - phpunit @@ -64,6 +68,7 @@ PHPunit:PHP7.2:MySQL: image: containers.ethitter.com:443/docker/images/php:7.2 services: - mysql:5.6 + - redis:latest script: - find . -type "f" -iname "*.php" | xargs -L "1" php -l - phpunit @@ -73,6 +78,7 @@ PHPunit:PHP7.3:MySQL: image: containers.ethitter.com:443/docker/images/php:7.3 services: - mysql:5.6 + - redis:latest script: - find . -type "f" -iname "*.php" | xargs -L "1" php -l - phpunit diff --git a/inc/class-wp-redis-user-session-storage.php b/inc/class-wp-redis-user-session-storage.php index d7c70a1..dcffeed 100644 --- a/inc/class-wp-redis-user-session-storage.php +++ b/inc/class-wp-redis-user-session-storage.php @@ -269,6 +269,15 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens { protected function get_key() { return $this->prefix . ':' . $this->user_id; } + + /** + * Is Redis connected? + * + * @return bool + */ + public function redis_connected() { + return $this->redis_connected; + } } /** diff --git a/tests/test-plugin.php b/tests/test-plugin.php new file mode 100755 index 0000000..30a2614 --- /dev/null +++ b/tests/test-plugin.php @@ -0,0 +1,21 @@ +<?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.' + ); + } +} diff --git a/tests/test-sample.php b/tests/test-sample.php deleted file mode 100755 index ccdf95b..0000000 --- a/tests/test-sample.php +++ /dev/null @@ -1,20 +0,0 @@ -<?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 ); - } -} -- GitLab