public function testSupportsKeyBasedAccess() { $map = Type::map(Type::varint(), Type::varchar())->create(); $this->assertEquals(0, count($map)); $map->set(new Varint('123'), 'value'); $this->assertEquals(1, count($map)); $this->assertTrue($map->has(new Varint('123'))); $this->assertEquals('value', $map->get(new Varint('123'))); $map->set(new Varint('123'), 'another value'); $this->assertEquals(1, count($map)); $this->assertEquals('another value', $map->get(new Varint('123'))); }
public function scalarTypes() { return array(array(function () { return Type::ascii(); }), array(function () { return Type::bigint(); }), array(function () { return Type::blob(); }), array(function () { return Type::boolean(); }), array(function () { return Type::counter(); }), array(function () { return Type::decimal(); }), array(function () { return Type::double(); }), array(function () { return Type::float(); }), array(function () { return Type::inet(); }), array(function () { return Type::int(); }), array(function () { return Type::text(); }), array(function () { return Type::timestamp(); }), array(function () { return Type::timeuuid(); }), array(function () { return Type::uuid(); }), array(function () { return Type::varchar(); }), array(function () { return Type::varint(); })); }
public function notEqualTypes() { return array(array(Type::collection(Type::varchar()), Type::collection(Type::int())), array(Type::collection(Type::collection(Type::varchar())), Type::collection(Type::collection(Type::int()))), array(Type::collection(Type::collection(Type::int())), Type::collection(Type::set(Type::int())))); }
/** * Invalid datatypes for tuples. * * This test will ensure that an exception will occur when an invalid * datatype is used inside a tuple; issues from the server. * * @test * @ticket PHP-58 * @expectedException \Cassandra\Exception\InvalidQueryException */ public function testInvalidType() { $validType = Type::tuple(Type::int()); $invalidType = Type::tuple(Type::varchar()); $tableName = $this->createTable($validType); $options = new ExecutionOptions(array('arguments' => array("key", $invalidType->create("value")))); $this->insertValue($tableName, $options); }
public function notEqualTypes() { return array(array(Type::userType('a', Type::int()), Type::userType('a', Type::varchar())), array(Type::userType('a', Type::int(), 'b', Type::varchar()), Type::userType('a', Type::int(), 'b', Type::bigint())), array(Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::varint()), Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::bigint())), array(Type::userType('a', Type::collection(Type::int()), 'b', Type::set(Type::varchar())), Type::userType('a', Type::collection(Type::int()), 'b', Type::set(Type::int()))), array(Type::userType('a', Type::int()), Type::userType('b', Type::int())), array(Type::userType('a', Type::int(), 'c', Type::varchar()), Type::userType('b', Type::int(), 'c', Type::varchar()))); }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage type must be Cassandra\Type::varchar(), * Cassandra\Type::text(), Cassandra\Type::blob(), * Cassandra\Type::ascii(), Cassandra\Type::bigint(), * Cassandra\Type::counter(), Cassandra\Type::int(), * Cassandra\Type::varint(), Cassandra\Type::boolean(), * Cassandra\Type::decimal(), Cassandra\Type::double(), * Cassandra\Type::float(), Cassandra\Type::inet(), * Cassandra\Type::timestamp(), Cassandra\Type::uuid() * or Cassandra\Type::timeuuid(), an instance of * Cassandra\Type\UnsupportedType given */ public function testPreventsDefiningSetsWithUnsupportedTypes() { Type::set(new UnsupportedType()); }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage keyType must be Cassandra\Type::varchar(), * Cassandra\Type::text(), Cassandra\Type::blob(), * Cassandra\Type::ascii(), Cassandra\Type::bigint(), * Cassandra\Type::counter(), Cassandra\Type::int(), * Cassandra\Type::varint(), Cassandra\Type::boolean(), * Cassandra\Type::decimal(), Cassandra\Type::double(), * Cassandra\Type::float(), Cassandra\Type::inet(), * Cassandra\Type::timestamp(), Cassandra\Type::uuid() * or Cassandra\Type::timeuuid(), an instance of * Cassandra\Type\UnsupportedType given */ public function testPreventsDefiningMapsWithUnsupportedTypes() { Type::map(new UnsupportedType(), Type::varchar()); }
public function notEqualTypes() { $setType = Type::set(Type::int()); return array(array(Type::map(Type::int(), Type::int())->create(), Type::map(Type::int(), Type::varchar())->create()), array(Type::map(Type::int(), Type::varchar())->create(1, 'a', 2, 'b', 3, 'c'), Type::map(Type::int(), Type::varchar())->create(1, 'a')), array(Type::map($setType, Type::varchar())->create($setType->create(4, 5, 6), 'a', $setType->create(7, 8, 9), 'b'), Type::map($setType, Type::varchar())->create($setType->create(1, 2, 3), 'a', $setType->create(4, 5, 6), 'b'))); }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage type must be Cassandra\Type::varchar(), * Cassandra\Type::text(), Cassandra\Type::blob(), * Cassandra\Type::ascii(), Cassandra\Type::bigint(), * Cassandra\Type::counter(), Cassandra\Type::int(), * Cassandra\Type::varint(), Cassandra\Type::boolean(), * Cassandra\Type::decimal(), Cassandra\Type::double(), * Cassandra\Type::float(), Cassandra\Type::inet(), * Cassandra\Type::timestamp(), Cassandra\Type::uuid() * or Cassandra\Type::timeuuid(), an instance of * Cassandra\Type\UnsupportedType given */ public function testPreventsDefiningCollectionsWithUnsupportedTypes() { Type::collection(new UnsupportedType()); }
/** * Gets column type data * @param \Cassandra\Type $type * @return array */ protected function _getColumnTypeData(BaseType $type) { switch ($type->name()) { case 'int': return [CColumn::TYPE_INTEGER, CColumn::BIND_PARAM_INT, true]; case 'varchar': return [CColumn::TYPE_VARCHAR, CColumn::BIND_PARAM_STR, false]; case 'text': return [CColumn::TYPE_TEXT, CColumn::BIND_PARAM_STR, false]; case 'timestamp': return [CColumn::TYPE_TIMESTAMP, CColumn::BIND_PARAM_INT, true]; case 'boolean': return [CColumn::TYPE_BOOLEAN, CColumn::BIND_PARAM_BOOL, false]; case 'decimal': return [CColumn::TYPE_DECIMAL, CColumn::BIND_PARAM_DECIMAL, true]; case 'double': return [CColumn::TYPE_DOUBLE, CColumn::BIND_PARAM_DECIMAL, true]; case 'uuid': return [CColumn::TYPE_UUID, CColumn::BIND_PARAM_UUID, false]; case 'timeuuid': return [CColumn::TYPE_TIMEUUID, CColumn::BIND_PARAM_UUID, false]; case 'ascii': return [CColumn::TYPE_ASCII, CColumn::BIND_PARAM_STR, false]; case 'bigint': return [CColumn::TYPE_BIGINTEGER, CColumn::BIND_PARAM_INT, true]; case 'blob': return [CColumn::TYPE_BLOB, CColumn::BIND_PARAM_BLOB, false]; case 'counter': return [CColumn::TYPE_COUNTER, CColumn::BIND_PARAM_INT, true]; case 'float': return [CColumn::TYPE_FLOAT, CColumn::BIND_PARAM_DECIMAL, true]; case 'inet': return [CColumn::TYPE_INET, CColumn::BIND_PARAM_STR, false]; case 'list': return [CColumn::TYPE_LIST, CColumn::BIND_PARAM_ARRAY, false]; case 'map': return [CColumn::TYPE_MAP, CColumn::BIND_PARAM_ARRAY, false]; case 'set': return [CColumn::TYPE_SET, CColumn::BIND_PARAM_ARRAY, false]; case 'varint': return [CColumn::TYPE_VARINT, CColumn::BIND_PARAM_STR, false]; default: throw new CException('Unsupported data type ' . $type->name()); } }
public function testAllowCreatingTypes() { $this->assertEquals("some string", Type::varchar()->create("some string")); }