Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion ext/src/Cluster/Builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ zend_class_entry *php_driver_cluster_builder_ce = NULL;

PHP_METHOD(ClusterBuilder, build)
{
CassError rc;
php_driver_cluster* cluster;
php_driver_cluster_builder *self = PHP_DRIVER_GET_CLUSTER_BUILDER(getThis());

Expand Down Expand Up @@ -125,7 +126,16 @@ PHP_METHOD(ClusterBuilder, build)
cass_cluster_set_tcp_nodelay(cluster->cluster, self->enable_tcp_nodelay);
cass_cluster_set_tcp_keepalive(cluster->cluster, self->enable_tcp_keepalive, self->tcp_keepalive_delay);
cass_cluster_set_use_schema(cluster->cluster, self->enable_schema);
ASSERT_SUCCESS(cass_cluster_set_use_hostname_resolution(cluster->cluster, self->enable_hostname_resolution));

rc = cass_cluster_set_use_hostname_resolution(cluster->cluster, self->enable_hostname_resolution);
if (rc == CASS_ERROR_LIB_NOT_IMPLEMENTED) {
if (self->enable_hostname_resolution) {
php_error_docref0(NULL TSRMLS_CC, E_WARNING,
"The underlying C/C++ driver does not implement hostname resolution it will be disabled");
}
} else {
ASSERT_SUCCESS(rc);
}
ASSERT_SUCCESS(cass_cluster_set_use_randomized_contact_points(cluster->cluster, self->enable_randomized_contact_points));
cass_cluster_set_connection_heartbeat_interval(cluster->cluster, self->connection_heartbeat_interval);

Expand Down
4 changes: 4 additions & 0 deletions ext/src/Cluster/Builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ Cluster\Builder:
If enabled the driver will resolve hostnames for IP addresses using
reverse IP lookup. This is useful for authentication (Kerberos) or
encryption SSL services that require a valid hostname for verification.

Important: It's possible that the underlying C/C++ driver does not
support hostname resolution. A PHP warning will be emitted if the driver
does not support hostname resolution.
params:
enabled:
comment: whether the driver uses hostname resolution.
Expand Down
2 changes: 1 addition & 1 deletion ext/src/Collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ PHP_METHOD(Collection, __construct)
CassValueType value_type;
if (!php_driver_value_type(Z_STRVAL_P(type), &value_type TSRMLS_CC))
return;
self->type = php_driver_type_set_from_value_type(value_type TSRMLS_CC);
self->type = php_driver_type_collection_from_value_type(value_type TSRMLS_CC);
} else if (Z_TYPE_P(type) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(type), php_driver_type_ce TSRMLS_CC)) {
if (!php_driver_type_validate(type, "type" TSRMLS_CC)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/src/Map.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ php_driver_map_compare(zval *obj1, zval *obj2 TSRMLS_DC)
return 1;
}
result = php_driver_value_compare(PHP5TO7_ZVAL_MAYBE_P(curr->value),
PHP5TO7_ZVAL_MAYBE_P(entry->value));
PHP5TO7_ZVAL_MAYBE_P(entry->value) TSRMLS_CC);
if (result != 0) return result;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/src/Timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ PHP_METHOD(Timestamp, toDateTime)
php_date_initialize(datetime_obj, str, str_len, NULL, NULL, 0 TSRMLS_CC);
efree(str);

RETVAL_ZVAL(datetime, 0, 0);
RETVAL_ZVAL(datetime, 0, 1);
}
/* }}} */

Expand Down
1 change: 0 additions & 1 deletion ext/src/UserTypeValue.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ PHP_METHOD(UserTypeValue, type)
PHP_METHOD(UserTypeValue, values)
{
php_driver_user_type_value *self = NULL;
array_init(return_value);
self = PHP_DRIVER_GET_USER_TYPE_VALUE(getThis());

array_init(return_value);
Expand Down
2 changes: 1 addition & 1 deletion ext/util/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ php_driver_value_hash(zval* zvalue TSRMLS_DC) {

#if PHP_MAJOR_VERSION >= 7
case IS_TRUE: return 1;
case IS_FALSE: return 1;
case IS_FALSE: return 0;
#else
case IS_BOOL: return Z_BVAL_P(zvalue);
#endif
Expand Down
25 changes: 17 additions & 8 deletions tests/integration/Cassandra/CollectionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ public function testScalarTypes($type, $value) {
* Data provider for lists with scalar types
*/
public function collectionWithScalarTypes() {
return array_map(function ($cassandraType) {
$listType = Type::collection($cassandraType[0]);
$list = $listType->create();
foreach ($cassandraType[1] as $value) {
$list->add($value);
}
return array($listType, $list);
}, $this->scalarCassandraTypes());
return array_merge(
array_map(function ($cassandraType) {
$listType = Type::collection($cassandraType[0]);
$list = $listType->create();
foreach ($cassandraType[1] as $value) {
$list->add($value);
}
return array($listType, $list);
}, $this->scalarCassandraTypes()),
array_map(function ($cassandraType) {
$list = new Collection($cassandraType[0]);
foreach ($cassandraType[1] as $value) {
$list->add($value);
}
return array($list->type(), $list);
}, $this->constantScalarCassandraTypes())
);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/Cassandra/DatatypeIntegrationTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function scalarCassandraTypes() {
new Duration(-1, 0, -(2 ** 31)),
new Duration((2 ** 31) - 1, 1, 0),
new Duration(-(2 ** 31), -1, 0))),
array(Type::int(), array(1, 2, 99)),
array(Type::float(), array(new Float(1.0), new Float(2.2), new Float(2.2))),
array(Type::inet(), array(new Inet("127.0.0.1"), new Inet("127.0.0.2"), new Inet("127.0.0.3"))),
array(Type::smallint(), array(Smallint::min(), Smallint::max(), new Smallint(0), new Smallint(74))),
Expand All @@ -56,6 +57,40 @@ public function scalarCassandraTypes() {
);
}

/**
* Global constant scalar Cassandra types to be used by data providers
*/
public function constantScalarCassandraTypes() {
$constants = array(
\Cassandra::TYPE_TEXT,
\Cassandra::TYPE_ASCII,
\Cassandra::TYPE_VARCHAR,
\Cassandra::TYPE_BIGINT,
\Cassandra::TYPE_SMALLINT,
\Cassandra::TYPE_TINYINT,
\Cassandra::TYPE_BLOB,
\Cassandra::TYPE_BOOLEAN,
\Cassandra::TYPE_DECIMAL,
\Cassandra::TYPE_DOUBLE,
\Cassandra::TYPE_FLOAT,
\Cassandra::TYPE_INT,
\Cassandra::TYPE_TIMESTAMP,
\Cassandra::TYPE_UUID,
\Cassandra::TYPE_VARINT,
\Cassandra::TYPE_TIMEUUID,
\Cassandra::TYPE_INET
);
$scalarCassandraTypes = $this->scalarCassandraTypes();

return array_map(function($type) use ($scalarCassandraTypes) {
$match = array_filter($scalarCassandraTypes, function($item) use ($type) {
return (string)$item[0] === $type;
});
assert(isset($match) && count($match) > 0);
return array($type, current($match)[1]);
}, $constants);
}

/**
* Create a table using $type for the value's type and insert $value using
* positional parameters.
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/Cassandra/MapIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ function($cassandraType) {
return array($mapType, $map);
}, $this->scalarCassandraTypes());

return array_merge($mapKeyTypes, $mapValueTypes);
$mapConstantScalarTypes = array_map(function ($cassandraType) {
$map = new Map($cassandraType[0], $cassandraType[0]);
$values = $cassandraType[1];
for ($i = 0; $i < count($cassandraType[1]); $i++) {
$map->set($values[$i], $values[$i]);
}
return array($map->type(), $map);
}, $this->constantScalarCassandraTypes());

return array_merge($mapKeyTypes, $mapValueTypes, $mapConstantScalarTypes);
}

/**
Expand Down
25 changes: 17 additions & 8 deletions tests/integration/Cassandra/SetIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ function($cassandraType) {
}
);

return array_map(function ($cassandraType) {
$setType = Type::set($cassandraType[0]);
$set = $setType->create();
foreach ($cassandraType[1] as $value) {
$set->add($value);
}
return array($setType, $set);
}, $scalarCassandraTypes);
return array_merge(
array_map(function ($cassandraType) {
$setType = Type::set($cassandraType[0]);
$set = $setType->create();
foreach ($cassandraType[1] as $value) {
$set->add($value);
}
return array($setType, $set);
}, $scalarCassandraTypes),
array_map(function ($cassandraType) {
$set = new Set($cassandraType[0]);
foreach ($cassandraType[1] as $value) {
$set->add($value);
}
return array($set->type(), $set);
}, $this->constantScalarCassandraTypes())
);
}

/**
Expand Down
56 changes: 31 additions & 25 deletions tests/unit/Cassandra/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,39 +97,45 @@ public function testSupportsKeyBasedAccess()
/**
* @dataProvider scalarTypes
*/
public function testScalarKeys($keyType, $keyValue, $keyValueCopy)
public function testScalarKeys($keyType, $values)
{
$map = Type::map($keyType, Type::varchar())->create();
$map->set($keyValue, "value");
$this->assertEquals(1, count($map));
$this->assertEquals($map->get($keyValue), "value");
$this->assertEquals($map->get($keyValueCopy), "value");
$this->assertTrue($map->has($keyValue));
$this->assertTrue($map->has($keyValueCopy));
$map->remove($keyValue);
foreach ($values as $index => $keyValue) {
$map->set($keyValue, "value$index");
}
$this->assertEquals(count($values), count($map));

foreach ($values as $index => $keyValue) {
$this->assertTrue($map->has($keyValue));
$this->assertEquals($map->get($keyValue), "value$index");
}

foreach ($values as $keyValue) {
$map->remove($keyValue);
}
$this->assertEquals(0, count($map));
}

public function scalarTypes()
{
return array(
array(Type::ascii(), "ascii", "ascii"),
array(Type::bigint(), new Bigint("9223372036854775807"), new Bigint("9223372036854775807")),
array(Type::blob(), new Blob("blob"), new Blob("blob")),
array(Type::boolean(), true, true),
array(Type::counter(), new Bigint(123), new Bigint(123)),
array(Type::decimal(), new Decimal("3.14159265359"), new Decimal("3.14159265359")),
array(Type::double(), 3.14159, 3.14159),
array(Type::float(), new Float(3.14159), new Float(3.14159)),
array(Type::inet(), new Inet("127.0.0.1"), new Inet("127.0.0.1")),
array(Type::int(), 123, 123),
array(Type::text(), "text", "text"),
array(Type::timestamp(), new Timestamp(123), new Timestamp(123)),
array(Type::timeuuid(), new Timeuuid(0), new Timeuuid(0)),
array(Type::uuid(), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2"), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2")),
array(Type::varchar(), "varchar", "varchar"),
array(Type::varint(), new Varint("9223372036854775808"), new Varint("9223372036854775808")),
array(Type::duration(), new Duration(1, 2, 3), new Duration(1, 2, 3))
array(Type::ascii(), array("ascii")),
array(Type::bigint(), array(new Bigint("9223372036854775807"))),
array(Type::blob(), array(new Blob("blob"))),
array(Type::boolean(), array(true, false)),
array(Type::counter(), array(new Bigint(123))),
array(Type::decimal(), array(new Decimal("3.14159265359"))),
array(Type::double(), array(3.14159)),
array(Type::float(), array(new Float(3.14159))),
array(Type::inet(), array(new Inet("127.0.0.1"))),
array(Type::int(), array(123)),
array(Type::text(), array("text")),
array(Type::timestamp(), array(new Timestamp(123))),
array(Type::timeuuid(), array(new Timeuuid(0))),
array(Type::uuid(), array(new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2"))),
array(Type::varchar(), array("varchar")),
array(Type::varint(), array(new Varint("9223372036854775808"))),
array(Type::duration(), array(new Duration(1, 2, 3)))
);
}

Expand Down
57 changes: 32 additions & 25 deletions tests/unit/Cassandra/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,44 @@ public function testContainsUniqueValues()
/**
* @dataProvider scalarTypes
*/
public function testScalarKeys($type, $value, $valueCopy)
public function testScalarKeys($type, $values)
{
$map = Type::set($type)->create();
$map->add($value);
$this->assertEquals(1, count($map));
$this->assertTrue($map->has($value));
$this->assertTrue($map->has($valueCopy));
$map->remove($value);
$this->assertEquals(0, count($map));
$set = Type::set($type)->create();
foreach($values as $value) {
$set->add($value);
}
$this->assertEquals(count($values), count($set));

foreach($values as $value) {
$this->assertTrue($set->has($value));
}

foreach($values as $value) {
$set->remove($value);
}
$this->assertEquals(0, count($set));
}

public function scalarTypes()
{
return array(
array(Type::ascii(), "ascii", "ascii"),
array(Type::bigint(), new Bigint("9223372036854775807"), new Bigint("9223372036854775807")),
array(Type::blob(), new Blob("blob"), new Blob("blob")),
array(Type::boolean(), true, true),
array(Type::counter(), new Bigint(123), new Bigint(123)),
array(Type::decimal(), new Decimal("3.14159265359"), new Decimal("3.14159265359")),
array(Type::double(), 3.14159, 3.14159),
array(Type::float(), new Float(3.14159), new Float(3.14159)),
array(Type::inet(), new Inet("127.0.0.1"), new Inet("127.0.0.1")),
array(Type::int(), 123, 123),
array(Type::text(), "text", "text"),
array(Type::timestamp(), new Timestamp(123), new Timestamp(123)),
array(Type::timeuuid(), new Timeuuid(0), new Timeuuid(0)),
array(Type::uuid(), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2"), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2")),
array(Type::varchar(), "varchar", "varchar"),
array(Type::varint(), new Varint("9223372036854775808"), new Varint("9223372036854775808")),
array(Type::duration(), new Duration(1, 2, 3), new Duration(1, 2, 3))
array(Type::ascii(), array("ascii")),
array(Type::bigint(), array(new Bigint("9223372036854775807"))),
array(Type::blob(), array(new Blob("blob"))),
array(Type::boolean(), array(true, false)),
array(Type::counter(), array(new Bigint(123))),
array(Type::decimal(), array(new Decimal("3.14159265359"))),
array(Type::double(), array(3.14159)),
array(Type::float(), array(new Float(3.14159))),
array(Type::inet(), array(new Inet("127.0.0.1"))),
array(Type::int(), array(123)),
array(Type::text(), array("text")),
array(Type::timestamp(), array(new Timestamp(123))),
array(Type::timeuuid(), array(new Timeuuid(0))),
array(Type::uuid(), array(new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2"))),
array(Type::varchar(), array("varchar")),
array(Type::varint(), array(new Varint("9223372036854775808"))),
array(Type::duration(), array(new Duration(1, 2, 3)))
);
}

Expand Down