From f224799a7d6adcd44c746bb4f9a4c3b357a13e18 Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Mon, 25 Jan 2021 13:29:12 +0000 Subject: [PATCH 01/11] Fix tests --- composer.json | 2 +- phpunit.xml | 4 +-- src/DataTypes/Counter.php | 16 +++++++++ src/Ql/Cql/CqlConnection.php | 31 ++++-------------- src/Ql/Cql/DalSocket.php | 5 ++- tests/Cache/Apc/ApcConnectionTest.php | 2 +- .../Connection/CqlExceptionTest.php | 4 +-- .../Connection/PdoExceptionTest.php | 4 +-- tests/FileSystem/FileSystemDataStoreTest.php | 4 +-- tests/FileSystem/JsonFileDaoTest.php | 4 +-- .../Foundation/AbstractSanitizableDaoTest.php | Bin 9950 -> 9921 bytes tests/Ql/Cql/CqlTest.php | 2 +- 12 files changed, 40 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 3d6d035..a8c854f 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "ext-apcu": "*" }, "require-dev": { - "phpunit/phpunit": "~7" + "phpunit/phpunit": "~8" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index cdcf171..95744a6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -14,11 +14,11 @@ > - tests + ./tests/* - + src diff --git a/src/DataTypes/Counter.php b/src/DataTypes/Counter.php index 854d4cb..4e92086 100644 --- a/src/DataTypes/Counter.php +++ b/src/DataTypes/Counter.php @@ -26,6 +26,7 @@ public function current() public function setValue($value) { + $by = $this->_safeValue($value); $this->_value = $value; $this->_adjust = 0; $this->_adjusted = true; @@ -36,8 +37,22 @@ public function calculated() return $this->_value + $this->_adjust; } + protected function _safeValue($by) + { + if(is_int($by) || is_float($by)) + { + return $by; + } + if(is_numeric($by) && strpos($by, '.') > 0) + { + return (float)$by; + } + return (int)$by; + } + public function increment($by = 1) { + $by = $this->_safeValue($by); $this->_adjust += abs($by); $this->_adjusted = abs($by) > 0; return $this; @@ -45,6 +60,7 @@ public function increment($by = 1) public function decrement($by = 1) { + $by = $this->_safeValue($by); $this->_adjust -= abs($by); $this->_adjusted = abs($by) > 0; return $this; diff --git a/src/Ql/Cql/CqlConnection.php b/src/Ql/Cql/CqlConnection.php index fa6f6ed..d0d498d 100644 --- a/src/Ql/Cql/CqlConnection.php +++ b/src/Ql/Cql/CqlConnection.php @@ -96,10 +96,7 @@ public function connect() { $this->_prepareCache = []; - $remainingAttempts = (int)$this->_config()->getItem( - 'connect_attempts', - 1 - ); + $remainingAttempts = (int)$this->_config()->getItem('connect_attempts', 1); while($remainingAttempts > 0) { @@ -109,35 +106,21 @@ public function connect() { if(empty($this->_availableHosts)) { - $this->_availableHosts = ValueAs::arr( - $this->_config()->getItem('hosts', 'localhost') - ); + $this->_availableHosts = ValueAs::arr($this->_config()->getItem('hosts', 'localhost')); $this->_availableHostCount = count($this->_availableHosts); if($this->_availableHostCount < 1) { - throw new ConnectionException( - 'Could not find any configured hosts' - ); + throw new ConnectionException('Could not find any configured hosts'); } } shuffle($this->_availableHosts); $host = reset($this->_availableHosts); - $this->_socket = new DalSocket( - $host, - (int)$this->_config()->getItem('port', 9160), - $this->_isPersistent() - ); - $this->_socket->setConnectTimeout( - (int)$this->_config()->getItem('connect_timeout', 1000) - ); - $this->_socket->setRecvTimeout( - (int)$this->_config()->getItem('receive_timeout', 1000) - ); - $this->_socket->setSendTimeout( - (int)$this->_config()->getItem('send_timeout', 1000) - ); + $this->_socket = new DalSocket($host, (int)$this->_config()->getItem('port', 9160), $this->_isPersistent()); + $this->_socket->setConnectTimeout((int)$this->_config()->getItem('connect_timeout', 1000)); + $this->_socket->setRecvTimeout((int)$this->_config()->getItem('receive_timeout', 1000)); + $this->_socket->setSendTimeout((int)$this->_config()->getItem('send_timeout', 1000)); $this->_transport = new TFramedTransport($this->_socket); $this->_protocol = new TBinaryProtocolAccelerated($this->_transport); diff --git a/src/Ql/Cql/DalSocket.php b/src/Ql/Cql/DalSocket.php index 5761765..d754df1 100644 --- a/src/Ql/Cql/DalSocket.php +++ b/src/Ql/Cql/DalSocket.php @@ -28,7 +28,10 @@ public function close() { $persist = $this->persist_; $this->persist_ = false; - parent::close(); + if($this->handle_ !== null && !is_bool($this->handle_)) + { + parent::close(); + } $this->persist_ = $persist; } diff --git a/tests/Cache/Apc/ApcConnectionTest.php b/tests/Cache/Apc/ApcConnectionTest.php index c308192..9674635 100644 --- a/tests/Cache/Apc/ApcConnectionTest.php +++ b/tests/Cache/Apc/ApcConnectionTest.php @@ -8,7 +8,7 @@ class ApcConnectionTest extends TestCase { - protected function setUp() + protected function setUp(): void { if(!((extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled')) diff --git a/tests/Exceptions/Connection/CqlExceptionTest.php b/tests/Exceptions/Connection/CqlExceptionTest.php index 752c776..152d7db 100644 --- a/tests/Exceptions/Connection/CqlExceptionTest.php +++ b/tests/Exceptions/Connection/CqlExceptionTest.php @@ -31,12 +31,12 @@ public function testExceptions($exception, $code, $contains) { foreach($contains as $contain) { - $this->assertContains($contain, $formed->getMessage()); + $this->assertStringContainsString($contain, $formed->getMessage()); } } else { - $this->assertContains($contains, $formed->getMessage()); + $this->assertStringContainsString($contains, $formed->getMessage()); } $this->assertSame($exception, $formed->getPrevious()); } diff --git a/tests/Exceptions/Connection/PdoExceptionTest.php b/tests/Exceptions/Connection/PdoExceptionTest.php index 00864aa..4adc2c9 100644 --- a/tests/Exceptions/Connection/PdoExceptionTest.php +++ b/tests/Exceptions/Connection/PdoExceptionTest.php @@ -25,12 +25,12 @@ public function testExceptions($exception, $code, $contains) { foreach($contains as $contain) { - $this->assertContains($contain, $formed->getMessage()); + $this->assertStringContainsString($contain, $formed->getMessage()); } } else { - $this->assertContains($contains, $formed->getMessage()); + $this->assertStringContainsString($contains, $formed->getMessage()); } $this->assertSame($exception, $formed->getPrevious()); } diff --git a/tests/FileSystem/FileSystemDataStoreTest.php b/tests/FileSystem/FileSystemDataStoreTest.php index c458163..2f81692 100644 --- a/tests/FileSystem/FileSystemDataStoreTest.php +++ b/tests/FileSystem/FileSystemDataStoreTest.php @@ -19,13 +19,13 @@ protected function _getResourceLocation($filename) return Path::system(dirname(__DIR__), 'resources', 'FileSystem', $filename); } - protected function setUp() + protected function setUp(): void { $resolver = new DalResolver(); $resolver->boot(); } - protected function tearDown() + protected function tearDown(): void { Dao::unsetDalResolver(); } diff --git a/tests/FileSystem/JsonFileDaoTest.php b/tests/FileSystem/JsonFileDaoTest.php index 3d50b5f..d1d69f9 100644 --- a/tests/FileSystem/JsonFileDaoTest.php +++ b/tests/FileSystem/JsonFileDaoTest.php @@ -14,13 +14,13 @@ protected function _getResourceLocation($filename) return Path::system(dirname(__DIR__), 'resources', 'FileSystem', $filename); } - protected function setUp() + protected function setUp(): void { $resolver = new DalResolver(); $resolver->boot(); } - protected function tearDown() + protected function tearDown(): void { Dao::unsetDalResolver(); } diff --git a/tests/Foundation/AbstractSanitizableDaoTest.php b/tests/Foundation/AbstractSanitizableDaoTest.php index 819cde96c29777728bd2bd687bc419af69b05e4b..8a7ea0eb35b67d201e3a0ce4b3d7036743bf62a7 100644 GIT binary patch delta 162 zcmccTd(d}73ESiuf+CYIaIj3?#4Zw4oSKtnWtCb{keXcLT9KSuP?DLSr=cDb6Ofpk zotU1Q662DX6B7fMDvkjPCX9iC5f4N#Sq?ReXidE?8S~nMTwOfo9(6Na{~bLYB~J? delta 221 zcmX@;d(U@630tbZmKK+Sf`XQULuy4qYH~?xifcu3YC%b6ex5>1Kw@%sVtQ&yj7wrp z3|zbz$jt{~xCky2d{c{yf%+9DbFnALLlgn+!VV^9v0Ji%)#y(yWYeE~p2K_dH+C^5 z4(I&5lElos;>`+NzXfFSN>YpR5_3W-3sN=I6N`!xE7f%rREkoIOLIyl2dXJ;_LeT= F1_0~qMIQhF diff --git a/tests/Ql/Cql/CqlTest.php b/tests/Ql/Cql/CqlTest.php index 54ba3d4..9967a84 100644 --- a/tests/Ql/Cql/CqlTest.php +++ b/tests/Ql/Cql/CqlTest.php @@ -165,7 +165,7 @@ public function testLsd() $this->assertEquals(123456, $dao->intVal); $this->assertEquals(-123456, $dao->bigintVal); $this->assertEquals(123456, $dao->doubleVal); - $this->assertEquals(12.3456, $dao->floatVal, '', 0.00001); + $this->assertEqualsWithDelta(12.3456, $dao->floatVal, 0.00001); $this->assertEquals(1200, $dao->decimalVal); $this->assertEquals(-54.321, $dao->negDecimalVal); $this->assertEquals(strtotime('2015-04-02'), $dao->timestampVal); From 145b587e5acbcdbc92a91614d558d5b7c6e9294f Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Mon, 25 Jan 2021 13:35:24 +0000 Subject: [PATCH 02/11] Php unit forced upgrade --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a8c854f..6da3ea9 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": ">=7.1", + "php": ">=7.2", "ext-json": "*", "packaged/helpers": "~1.23||~2.5", "packaged/docblock": "~0.1||~1.0", From a2c2b956cbb0650d8a4fe9e04211417ee42a742c Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Mon, 25 Jan 2021 13:36:18 +0000 Subject: [PATCH 03/11] Add php8 --- .circleci/config.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ac83f9..e4c9495 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,12 +103,27 @@ jobs: MYSQL_ALLOW_EMPTY_PASSWORD: yes MYSQL_ROOT_HOST: "%" - image: memcached:1.4 + build-php80: + <<: *defaults + docker: + - image: php:8.0-alpine + environment: + ADD_PACKAGES: "php8-apcu php8-memcached" + ADD_MODULES: "mysqli pdo pdo_mysql" + - image: cassandra:2.1 + environment: + CASSANDRA_START_RPC: yes + - image: circleci/mysql:5.6 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_ROOT_HOST: "%" + - image: memcached:1.4 workflows: version: 2 build: jobs: - - build-php71 - build-php72 - build-php73 - build-php74 + - build-php80 From a8f6448d54b497884c66a93f56b6d1308115a40a Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Mon, 25 Jan 2021 13:38:15 +0000 Subject: [PATCH 04/11] Correct value --- src/DataTypes/Counter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DataTypes/Counter.php b/src/DataTypes/Counter.php index 4e92086..270e6d4 100644 --- a/src/DataTypes/Counter.php +++ b/src/DataTypes/Counter.php @@ -26,8 +26,7 @@ public function current() public function setValue($value) { - $by = $this->_safeValue($value); - $this->_value = $value; + $this->_value = $this->_safeValue($value); $this->_adjust = 0; $this->_adjusted = true; } From b2f153d958be39e9cbdc6f8e8f742315ac62ed79 Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Mon, 25 Jan 2021 13:42:57 +0000 Subject: [PATCH 05/11] Packages --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e4c9495..4a336d2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: docker: - image: php:8.0-alpine environment: - ADD_PACKAGES: "php8-apcu php8-memcached" + ADD_PACKAGES: "php-apcu php-memcached" ADD_MODULES: "mysqli pdo pdo_mysql" - image: cassandra:2.1 environment: From ac76772e6b28bf77355c9ab8fd8b08b6459a671e Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Mon, 21 Jun 2021 16:10:19 +0100 Subject: [PATCH 06/11] php8 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4a336d2..e4c9495 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: docker: - image: php:8.0-alpine environment: - ADD_PACKAGES: "php-apcu php-memcached" + ADD_PACKAGES: "php8-apcu php8-memcached" ADD_MODULES: "mysqli pdo pdo_mysql" - image: cassandra:2.1 environment: From 0c7f009ada537a02795f1f493e7422f28675b5e8 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Mon, 21 Jun 2021 16:16:30 +0100 Subject: [PATCH 07/11] try ADD_PECL --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e4c9495..40f0627 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: docker: - image: php:8.0-alpine environment: - ADD_PACKAGES: "php8-apcu php8-memcached" + ADD_PECL: "apcu memcached" ADD_MODULES: "mysqli pdo pdo_mysql" - image: cassandra:2.1 environment: From f1514cca6e2ffd88e9b95f04e2b0b1038cbc59ea Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Mon, 21 Jun 2021 16:20:42 +0100 Subject: [PATCH 08/11] add zlib-dev --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 40f0627..892f4ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,8 +108,9 @@ jobs: docker: - image: php:8.0-alpine environment: - ADD_PECL: "apcu memcached" ADD_MODULES: "mysqli pdo pdo_mysql" + ADD_PECL: "apcu memcached" + ADD_PHPIZE_DEPS: "zlib-dev" - image: cassandra:2.1 environment: CASSANDRA_START_RPC: yes From ff81b4dce92a24ead147f78f3dec9eb6e74d9189 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Mon, 21 Jun 2021 16:23:36 +0100 Subject: [PATCH 09/11] add memcached-dev --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 892f4ec..938502e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -110,7 +110,7 @@ jobs: environment: ADD_MODULES: "mysqli pdo pdo_mysql" ADD_PECL: "apcu memcached" - ADD_PHPIZE_DEPS: "zlib-dev" + ADD_PHPIZE_DEPS: "zlib-dev memcached-dev" - image: cassandra:2.1 environment: CASSANDRA_START_RPC: yes From e97593b37a2217dda94212e261013a11c9280ff9 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Mon, 21 Jun 2021 16:26:13 +0100 Subject: [PATCH 10/11] install the lib, plonker --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 938502e..6281128 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -110,7 +110,7 @@ jobs: environment: ADD_MODULES: "mysqli pdo pdo_mysql" ADD_PECL: "apcu memcached" - ADD_PHPIZE_DEPS: "zlib-dev memcached-dev" + ADD_PHPIZE_DEPS: "zlib-dev libmemcached-dev" - image: cassandra:2.1 environment: CASSANDRA_START_RPC: yes From 6d41cab8188c4cf88e8e96e276c03c0b30dee8c7 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Mon, 21 Jun 2021 16:34:11 +0100 Subject: [PATCH 11/11] add libmemcached --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6281128..b80d560 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,6 +108,7 @@ jobs: docker: - image: php:8.0-alpine environment: + ADD_PACKAGES: "libmemcached" ADD_MODULES: "mysqli pdo pdo_mysql" ADD_PECL: "apcu memcached" ADD_PHPIZE_DEPS: "zlib-dev libmemcached-dev"