Cassandra\TupleIntegrationTest::testUserType PHP Метод

testUserType() публичный Метод

This test will ensure that the PHP driver supports the tuples collection with user types.
public testUserType ( )
    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));
    }