/**
  * User type using a partial user type value.
  *
  * This test will ensure that the PHP driver supports the user types. This
  * test uses a partial user type where some values will not be assigned.
  *
  * @test
  * @ticket PHP-57
  */
 public function testPartialUserType()
 {
     // Alias missing from a single number
     $phone = $this->getPhoneUserType();
     $phone->set("number", "000-000-0000");
     $numbers = new Set($phone->type());
     $numbers->add($phone);
     $address = UserTypeIntegrationTest::getAddressUserType();
     $address->set("street", "123 Missing Alias Street");
     $address->set("zip", 00);
     $address->set("phone_numbers", $numbers);
     $key = $this->insertAddress($address);
     $this->assertAddressValue($this->selectAddress($key), $address);
     // Missing/NULL values during insert
     $address = UserTypeIntegrationTest::getAddressUserType();
     $address->set("street", "1 Furzeground Way");
     $key = $this->insertAddress($address);
     $address->set("zip", null);
     // Add null 'zip' to assert properly (Server will default null values)
     $address->set("phone_numbers", null);
     // Add null 'phone_numbers' (same as above)
     $this->assertAddressValue($this->selectAddress($key), $address);
 }
 /**
  * Tuple using a nested user type.
  *
  * This test will ensure that the PHP driver supports the tuples collection
  * with user types.
  *
  * @test
  * @ticket PHP-57
  * @ticket PHP-58
  */
 public function testUserType()
 {
     // Create the user types
     $this->session->execute(new SimpleStatement(UserTypeIntegrationTest::PHONE_USER_TYPE_CQL));
     $this->session->execute(new SimpleStatement(UserTypeIntegrationTest::ADDRESS_USER_TYPE_CQL));
     // Create the table
     $query = "CREATE TABLE " . $this->tableNamePrefix . " (key timeuuid PRIMARY KEY, value " . "frozen<tuple<address>>)";
     $this->session->execute(new SimpleStatement($query));
     // Generate a valid address user type and assign it to a tuple
     $address = UserTypeIntegrationTest::generateAddressValue();
     $tuple = new Tuple(array($address->type()));
     $tuple->set(0, $address);
     // Assign the values for the statement
     $key = new Timeuuid();
     $values = array($key, $tuple);
     // Insert the value into the table
     $query = "INSERT INTO " . $this->tableNamePrefix . " (key, value) VALUES (?, ?)";
     $statement = new SimpleStatement($query);
     $options = new ExecutionOptions(array("arguments" => $values));
     $this->session->execute($statement, $options);
     // Select the tuple
     $query = "SELECT value FROM " . $this->tableNamePrefix . " WHERE key=?";
     $statement = new SimpleStatement($query);
     $options = new ExecutionOptions(array("arguments" => array($key)));
     $rows = $this->session->execute($statement, $options);
     // Ensure the tuple collection is valid
     $this->assertCount(1, $rows);
     $row = $rows->first();
     $this->assertNotNull($row);
     $this->assertArrayHasKey("value", $row);
     $tuple = $row["value"];
     $this->assertInstanceOf('Cassandra\\Tuple', $tuple);
     $this->assertCount(1, $tuple);
     // Verify the value can be read from the table
     UserTypeIntegrationTest::assertAddressValue($tuple->get(0));
 }