/** * Float tests */ public function testFloat() { $this->assertSame(1.0, Type::float(1)); $this->assertSame(1.2, Type::float(1.2)); $this->assertSame(0.2, Type::float(0.2)); $this->assertSame(1.0, Type::float('1')); $this->assertSame(0.0, Type::float('test1')); $this->assertSame(1.0, Type::float('1test2')); $this->assertSame(0.0, Type::float([])); $this->assertSame(1.0, Type::float(['test'])); $this->assertFalse(Type::isFloat(1)); $this->assertFalse(Type::isFloat('1')); $this->assertTrue(Type::isFloat(1.2)); $this->assertFalse(Type::isFloat([])); }
/** * Scalar Cassandra types to be used by data providers */ public function scalarCassandraTypes() { return array(array(Type::ascii(), array("a", "b", "c")), array(Type::bigint(), array(new Bigint("1"), new Bigint("2"), new Bigint("3"))), array(Type::blob(), array(new Blob("x"), new Blob("y"), new Blob("z"))), array(Type::boolean(), array(true, false, true, false)), array(Type::double(), array(1.1, 2.2, 3.3, 4.4)), 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::text(), array("a", "b", "c", "x", "y", "z")), array(Type::timestamp(), array(new Timestamp(123), new Timestamp(456), new Timestamp(789))), array(Type::timeuuid(), array(new Timeuuid(0), new Timeuuid(1), new Timeuuid(2))), array(Type::uuid(), array(new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2"), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c3"), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c4"))), array(Type::varchar(), array("a", "b", "c", "x", "y", "z")), array(Type::varint(), array(new Varint(1), new Varint(2), new Varint(3)))); }
public function scalarTypes() { return array(array(Type::ascii(), "ascii"), array(Type::bigint(), new Bigint("9223372036854775807")), array(Type::blob(), new Blob("blob")), array(Type::boolean(), true), array(Type::counter(), new Bigint(123)), array(Type::decimal(), new Decimal("3.14159265359")), array(Type::double(), 3.14159), array(Type::float(), new Float(3.14159)), array(Type::inet(), new Inet("127.0.0.1")), array(Type::int(), 123), array(Type::text(), "text"), array(Type::timestamp(), new Timestamp(123)), array(Type::timeuuid(), new Timeuuid(0)), array(Type::uuid(), new Uuid("03398c99-c635-4fad-b30a-3b2c49f785c2")), array(Type::varchar(), "varchar"), array(Type::varint(), new Varint("9223372036854775808"))); }
/** * @param array $values * @param string $key * @param float $default * @return float */ public static function float(array $values, $key, $default = 0.0) { if (isset($values[$key])) { return Type::float($values[$key]); } return $default; }
/** * Paging advancement does not create memory leak * * This test will ensure that the driver does not create memory leaks * associated advancing to the next page of results. * * @test * @ticket PHP-101 */ public function testNoPagingMemoryLeak() { // Create the user types and table for the test $this->session->execute(new SimpleStatement("DROP TABLE {$this->tableNamePrefix}")); $this->session->execute(new SimpleStatement("CREATE TYPE price_history (time timestamp, price float)")); $priceHistory = Type::userType("time", Type::timestamp(), "price", Type::float()); $this->session->execute(new SimpleStatement("CREATE TYPE purchase_stats (day_of_week int, total_purchases int)")); $purchaseStats = Type::userType("day_of_week", Type::int(), "total_purchases", Type::int()); $this->session->execute(new SimpleStatement("CREATE TABLE {$this->tableNamePrefix} (id uuid PRIMARY KEY,\n history frozen<price_history>, stats frozen<purchase_stats>,\n comments text)")); // Populate the table with some random data $totalInserts = 500; $statement = $this->session->prepare("INSERT INTO {$this->tableNamePrefix}\n (id, history, stats, comments) VALUES (?, ?, ?, ?)"); foreach (range(1, $totalInserts) as $i) { // Create the values for the insert $history = $priceHistory->create("time", new Timestamp(mt_rand(1270094400000, 1459483200000)), "price", new Float(mt_rand(1, 1000) / 100)); $stats = $purchaseStats->create("day_of_week", mt_rand(0, 6), "total_purchases", mt_rand(0, 1000)); $values = array(new Uuid(), $history, $stats, $this->randomString()); $options = new ExecutionOptions(array("arguments" => $values)); $this->session->execute($statement, $options); } // Select all the rows in the table using paging $statement = new SimpleStatement("SELECT * FROM {$this->tableNamePrefix}"); $options = new ExecutionOptions(array("page_size" => 2)); $rows = $this->session->execute($statement, $options); // Validate paging and ensure all the rows were read $count = $this->validatePageResults($rows); $this->assertEquals($totalInserts, $count); }