Пример #1
0
 /**
  * Set up the test case
  *
  * @return void
  */
 public function setUp()
 {
     $this->rackspace = new RackspaceFiles('foo', 'bar');
     $this->httpClientAdapterTest = new HttpTest();
     $this->rackspace->getHttpClient()->setAdapter($this->httpClientAdapterTest);
     // authentication (from a file)
     $this->httpClientAdapterTest->setResponse(self::loadResponse('../../_files/testAuthenticate'));
     $this->assertTrue($this->rackspace->authenticate(), 'Authentication failed');
     $this->metadata = array('foo' => 'bar', 'foo2' => 'bar2');
     $this->metadata2 = array('hello' => 'world');
     // load the HTTP response (from a file)
     $this->httpClientAdapterTest->setResponse($this->loadResponse($this->getName()));
 }
Пример #2
0
 /**
  * Test the authentication error (401 Unauthorized - Bad username or password)
  *
  * @return void
  */
 public function testAuthenticateError()
 {
     $this->_files->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     $this->assertFalse($this->_files->authenticate());
     $this->assertFalse($this->_files->isSuccessful());
     $this->assertEquals($this->_files->getErrorCode(), '401');
     $this->assertEquals($this->_files->getErrorMsg(), 'Bad username or password');
 }
Пример #3
0
 /**
  * Constructor
  *
  * @param  array|Traversable $options
  * @return void
  */
 function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!is_array($options) || empty($options)) {
         throw new Exception\InvalidArgumentException('Invalid options provided');
     }
     try {
         $this->rackspace = new RackspaceFile($options[self::USER], $options[self::API_KEY]);
     } catch (RackspaceException $e) {
         throw new Exception\RuntimeException('Error on create: ' . $e->getMessage(), $e->getCode(), $e);
     }
     if (isset($options[self::HTTP_ADAPTER])) {
         $this->rackspace->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
     }
     if (!empty($options[self::REMOTE_CONTAINER])) {
         $this->container = $options[self::REMOTE_CONTAINER];
     }
 }
Пример #4
0
    /**
     * Test the get of a container
     *
     * @return void
     */
    public function testGetContainer()
    {
        $this->_files->getHttpClient()
                    ->setAdapter($this->_httpClientAdapterTest);

        $this->_httpClientAdapterTest->setResponse($this->_loadResponse('../../_files/testAuthenticate'));
        $this->assertTrue($this->_files->authenticate(),'Authentication failed');

        $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));

        $container= $this->_files->getContainer('foo');
        $this->assertTrue($this->_files->isSuccessful(),'Get container failed');
        $this->assertEquals($container->getName(),'foo','The name of container is wrong');
        $this->assertEquals($container->getSize(),9756,'The size in bytes is wrong');
        $this->assertEquals($container->getObjectCount(),2,'The objects count is wrong');
        $metadata= array(
            'foo' => 'bar',
            'foo2' => 'bar2'
        );
        $this->assertEquals($container->getMetadata(),$metadata,'The metadata is wrong');
    }