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

Fix tests #65

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
TomK marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,7 +23,7 @@
"ext-apcu": "*"
},
"require-dev": {
"phpunit/phpunit": "~7"
"phpunit/phpunit": "~8"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
>
<testsuites>
<testsuite name="dal">
<directory>tests</directory>
<directory>./tests/*</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
Expand Down
17 changes: 16 additions & 1 deletion src/DataTypes/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function current()

public function setValue($value)
{
$this->_value = $value;
$this->_value = $this->_safeValue($value);
$this->_adjust = 0;
$this->_adjusted = true;
}
Expand All @@ -36,15 +36,30 @@ 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;
}

public function decrement($by = 1)
{
$by = $this->_safeValue($by);
$this->_adjust -= abs($by);
$this->_adjusted = abs($by) > 0;
return $this;
Expand Down
31 changes: 7 additions & 24 deletions src/Ql/Cql/CqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/Ql/Cql/DalSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/Apc/ApcConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions tests/Exceptions/Connection/CqlExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Exceptions/Connection/PdoExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/FileSystem/FileSystemDataStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/FileSystem/JsonFileDaoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Binary file modified tests/Foundation/AbstractSanitizableDaoTest.php
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/Ql/Cql/CqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down