OpenCloudTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Gaufrette\Functional\Adapter;
  3. use Gaufrette\Adapter\OpenCloud;
  4. use Gaufrette\Filesystem;
  5. use OpenCloud\Rackspace;
  6. class OpenCloudTest extends FunctionalTestCase
  7. {
  8. /** @var \OpenCloud\ObjectStore\Service */
  9. private $objectStore;
  10. /** @var string */
  11. private $container;
  12. public function setUp()
  13. {
  14. $username = getenv('RACKSPACE_USER') ?: '';
  15. $apiKey = getenv('RACKSPACE_APIKEY') ?: '';
  16. $container = getenv('RACKSPACE_CONTAINER') ?: '';
  17. if (empty($username) || empty($apiKey) || empty($container)) {
  18. $this->markTestSkipped('Either RACKSPACE_USER, RACKSPACE_APIKEY and/or RACKSPACE_CONTAINER env vars are missing.');
  19. }
  20. $connection = new Rackspace(
  21. 'https://identity.api.rackspacecloud.com/v2.0/',
  22. [
  23. 'username' => $username,
  24. 'apiKey' => $apiKey,
  25. ],
  26. [
  27. // Guzzle ships with outdated certs
  28. // @see https://github.com/rackspace/php-opencloud/issues/727
  29. Rackspace::SSL_CERT_AUTHORITY => 'system',
  30. Rackspace::CURL_OPTIONS => [
  31. CURLOPT_SSL_VERIFYPEER => true,
  32. CURLOPT_SSL_VERIFYHOST => 2,
  33. ],
  34. ]
  35. );
  36. $this->container = uniqid($container);
  37. $this->objectStore = $connection->objectStoreService('cloudFiles', 'IAD', 'publicURL');
  38. $this->objectStore->createContainer($this->container);
  39. $adapter = new OpenCloud($this->objectStore, $this->container);
  40. $this->filesystem = new Filesystem($adapter);
  41. }
  42. public function tearDown()
  43. {
  44. if ($this->filesystem === null) {
  45. return;
  46. }
  47. $this->objectStore->getContainer($this->container)->delete(true);
  48. }
  49. }