Browse Source

Make sure we can connect to memcached

Timothy J. Warren 1 year ago
parent
commit
1378768ff0
4 changed files with 18 additions and 22 deletions
  1. 2
    8
      .gitlab-ci.yml
  2. 4
    5
      src/Driver/MemcachedDriver.php
  3. 10
    4
      tests/Driver/MemcachedDriverTest.php
  4. 2
    5
      tests/PoolTest.php

+ 2
- 8
.gitlab-ci.yml View File

@@ -5,23 +5,17 @@ services:
5 5
 test:7:
6 6
     before_script:
7 7
       - sh build/docker_install.sh > /dev/null
8
-      #- apk add --no-cache php7-apcu php7-memcached php7-phpdbg
9
-      #- echo '\nextension=apcu.so\nextension=memcached.so' >> /etc/php7/php.ini
10 8
       - curl -sS https://getcomposer.org/installer | php
11 9
       - php composer.phar install --ignore-platform-reqs
12
-    #image: php:7-alpine
13 10
     image: php:7
14 11
     script:
15
-      - phpdbg -qrr -- ./vendor/bin/phpunit -c build
12
+      - phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never
16 13
       
17 14
 test:7.1:
18 15
     before_script:
19 16
       - sh build/docker_install.sh > /dev/null
20
-      #- apk add --no-cache php7.1-apcu php7.1-memcached php7.1-phpdbg
21
-      #- echo '\nextension=apcu.so\nextension=memcached.so' >> /etc/php7.1/php.ini
22 17
       - curl -sS https://getcomposer.org/installer | php
23 18
       - php composer.phar install --ignore-platform-reqs
24
-    #image: php:7.1-alpine
25 19
     image: php:7.1
26 20
     script:
27
-      - phpdbg -qrr -- ./vendor/bin/phpunit -c build
21
+      - phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never

+ 4
- 5
src/Driver/MemcachedDriver.php View File

@@ -33,14 +33,15 @@ class MemcachedDriver extends AbstractDriver {
33 33
 	 * @param array $options
34 34
 	 * @throws CacheException
35 35
 	 */
36
-	public function __construct(array $config = [], array $options = [])
36
+	public function __construct(
37
+		array $config = ['host' => '127.0.0.1', 'port' => '11211'], 
38
+		array $options = []
39
+	)
37 40
 	{
38
-		// @codeCoverageIgnoreStart
39 41
 		if ( ! class_exists('Memcached'))
40 42
 		{
41 43
 			throw new CacheException("Memcached driver requires memcached extensions");
42 44
 		}
43
-		// @codeCoverageIgnoreEnd
44 45
 
45 46
 		try
46 47
 		{
@@ -48,7 +49,6 @@ class MemcachedDriver extends AbstractDriver {
48 49
 			$this->conn->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
49 50
 			$this->conn->addServer($config['host'], (int) $config['port']);
50 51
 
51
-			// @codeCoverageIgnoreStart
52 52
 			if ( ! empty($options))
53 53
 			{
54 54
 				$this->conn->setOptions($options);
@@ -60,7 +60,6 @@ class MemcachedDriver extends AbstractDriver {
60 60
 			// match the requirements of the interface
61 61
 			throw new CacheException($e->getMessage(), $e->getCode(), $e);
62 62
 		}
63
-		// @codeCoverageIgnoreEnd
64 63
 	}
65 64
 
66 65
 	/**

+ 10
- 4
tests/Driver/MemcachedDriverTest.php View File

@@ -22,10 +22,16 @@ class MemcachedDriverTest extends DriverTestBase {
22 22
 
23 23
 	public function setUp()
24 24
 	{
25
-		$this->driver = new MemcachedDriver([
26
-			'host' => 'localhost',
27
-			'port' => '11211',
28
-		]);
25
+		$config = [
26
+			'host' => '127.0.0.1',
27
+			'port' => 11211
28
+		];
29
+		if (array_key_exists('MEMCACHED_HOST', $_ENV)) 
30
+		{
31
+			$config['host'] = $_ENV['MEMCACHED_HOST'];
32
+		}
33
+		
34
+		$this->driver = new MemcachedDriver($config);
29 35
 		$this->driver->flush();
30 36
 	}
31 37
 }

+ 2
- 5
tests/PoolTest.php View File

@@ -16,15 +16,12 @@
16 16
 
17 17
 namespace Aviat\Banker\Tests;
18 18
 
19
-use Aviat\Banker\Pool;
20
-use Aviat\Banker\Item;
21
-use Aviat\Banker\ItemCollection;
19
+use Aviat\Banker\{Item, ItemCollection, Pool};
22 20
 use Aviat\Banker\Exception\InvalidArgumentException;
23 21
 use Monolog\Logger;
24 22
 use Monolog\Handler\SyslogHandler;
25 23
 use PHPUnit\Framework\TestCase;
26
-use Psr\Log\LoggerInterface;
27
-use Psr\Log\NullLogger;
24
+use Psr\Log\{LoggerInterface, NullLogger};
28 25
 
29 26
 class PoolTest extends TestCase {
30 27