Google\Cloud\Datastore\DatastoreSessionHandler::destroy PHP Method

destroy() public method

Delete the session data from Cloud Datastore.
public destroy ( $id )
    public function destroy($id)
    {
        try {
            $key = $this->datastore->key($this->kind, $id, ['namespaceId' => $this->namespaceId]);
            $this->transaction->delete($key);
            $this->transaction->commit();
        } catch (Exception $e) {
            trigger_error(sprintf('Datastore delete failed: %s', $e->getMessage()), E_USER_WARNING);
            return false;
        }
        return true;
    }

Usage Example

 /**
  * @expectedException PHPUnit_Framework_Error_Warning
  */
 public function testDestroyWithException()
 {
     $key = new Key('projectid');
     $key->pathElement(self::KIND, 'sessionid');
     $this->transaction->delete($key)->shouldBeCalledTimes(1);
     $this->transaction->commit()->shouldBeCalledTimes(1)->willThrow(new Exception());
     $this->datastore->transaction()->shouldBeCalledTimes(1)->willReturn($this->transaction->reveal());
     $this->datastore->key(self::KIND, 'sessionid', ['namespaceId' => self::NAMESPACE_ID])->shouldBeCalledTimes(1)->willReturn($key);
     $datastoreSessionHandler = new DatastoreSessionHandler($this->datastore->reveal());
     $datastoreSessionHandler->open(self::NAMESPACE_ID, self::KIND);
     $ret = $datastoreSessionHandler->destroy('sessionid');
     $this->assertEquals(false, $ret);
 }