Skip to content

Commit

Permalink
PHP-172 - php_driver_value_hash hashes IS_TRUE and IS_FALSE to 1 in PHP7
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenick committed Aug 4, 2017
1 parent 4a34fc0 commit f4cebf6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 51 deletions.
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
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

0 comments on commit f4cebf6

Please sign in to comment.