/**
  * @test
  * @vcr should_create_and_delete_user_and_return_empty_array.json
  */
 public function should_create_and_delete_user_and_return_empty_array()
 {
     VCR::turnOn();
     VCR::insertCassette('should_create_user_and_return_user_id.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $user = $client->api('user')->userCreate($this->test_user_params());
     $this->assertObjectHasAttribute('uid', $user);
     $this->assertNotNull($user->uid);
     VCR::eject();
     VCR::turnOff();
     VCR::turnOn();
     VCR::insertCassette('should_add_role_to_user.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results2 = $client->api('user')->userAddRole($user, 'authenticated user');
     $this->assertEquals('Role successfully added', $results2['message']);
     VCR::eject();
     VCR::turnOff();
     VCR::turnOn();
     VCR::insertCassette('should_create_and_delete_user_and_return_empty_array.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results3 = $client->api('user')->userDelete($user);
     $this->assertEmpty($results3);
     VCR::eject();
     VCR::turnOff();
 }
Ejemplo n.º 2
0
 public function testShouldSetAConfiguration()
 {
     VCR::configure()->setCassettePath('tests');
     VCR::turnOn();
     $this->assertEquals('tests', VCR::configure()->getCassettePath());
     VCR::turnOff();
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     parent::setUp();
     VCR::turnOn();
     $calledClass = explode("\\", get_called_class());
     $cassette = end($calledClass) . "/" . $this->getName();
     VCR::insertCassette($cassette);
     $this->apiClient = Client::getInstance();
 }
Ejemplo n.º 4
0
 public function setUp()
 {
     $authClient = new AuthenticatedClient("phpunit-auth.json");
     if (!$authClient->isAuthenticationSetup()) {
         $this->markTestSkipped();
     }
     PulseBoard::setApiKey($authClient->getApiToken());
     VCR::turnOn();
     VCR::insertCassette('PhpPulseVCR');
 }
 /**
  * @test
  * @vcr should_pass_basic_auth_and_drupal_auth_with_username_and_password.json
  */
 public function should_pass_basic_auth_and_drupal_auth_with_username_and_password()
 {
     VCR::turnOn();
     VCR::insertCassette('should_pass_basic_auth_and_drupal_auth_with_username_and_password.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results = $client->api('nodes')->createNode($this->test_node_params());
     $this->assertObjectHasAttribute('nid', $results);
     VCR::eject();
     VCR::turnOff();
 }
 function testSaveAsDownloadsFileToTarget()
 {
     \VCR\VCR::turnOn();
     \VCR\VCR::insertCassette('gathercontent_save_file.yml');
     $file_url = 'https://gathercontent.s3.amazonaws.com/filename_hash';
     $target_filename = $this->tempDir() . '/file.jpg';
     $this->assertFileNotExists($target_filename);
     $subject = new Downloader($file_url);
     $subject->saveAs($target_filename);
     $this->assertFileExists($target_filename);
     $this->assertEquals('file-contents', file_get_contents($target_filename));
     \VCR\VCR::eject();
     \VCR\VCR::turnOff();
 }
 /**
  * @test
  * @@vcr info_status
  */
 public function get_status()
 {
     VCR::turnOn();
     //VCR::insertCassette('authenticate');
     VCR::insertCassette('info_status');
     //Arrange
     $sauce_api = new Client();
     //Act
     $who = $sauce_api->api('provider_information')->status();
     //Assert
     $this->assertArrayHasKey('service_operational', $who);
     // To stop recording requests, eject the cassette
     VCR::eject();
     // Turn off VCR to stop intercepting requests
     VCR::turnOff();
 }
Ejemplo n.º 8
0
 /**
  * @test
  * @@vcr show_activity
  */
 public function should_get_activity()
 {
     VCR::turnOn();
     //VCR::insertCassette('authenticate');
     VCR::insertCassette('show_activity');
     //Arrange
     $sauce_api = new Client();
     $sauce_api->authenticate($_ENV['USERNAME_KEY'], $_ENV['TOKEN_PASSWORD'], Client::AUTH_HTTP_PASSWORD);
     //Act
     $what = $sauce_api->api('current_user')->getUserActivity($_ENV['USERNAME_KEY']);
     //Assert
     $this->assertArrayHasKey('subaccounts', $what);
     // To stop recording requests, eject the cassette
     VCR::eject();
     // Turn off VCR to stop intercepting requests
     VCR::turnOff();
 }
 public function testExecuteQueryWithInvalidAPIKey()
 {
     \VCR\VCR::turnOn();
     \VCR\VCR::insertCassette('search_without_valid_api_key');
     $temp_key = getenv('TWINGLY_SEARCH_KEY');
     putenv('TWINGLY_SEARCH_KEY=wrong');
     $c = new Client();
     try {
         $q = $c->query();
         $q->pattern = 'something';
         $c->execute_query($q);
         $this->fail('Should throw AuthException.');
     } catch (AuthException $e) {
         $this->assertEquals('The API key does not exist.', $e->getMessage());
         putenv('TWINGLY_SEARCH_KEY=' . $temp_key);
     }
     \VCR\VCR::turnOff();
 }
Ejemplo n.º 10
0
 /**
  * @test
  * @vcr job_asset_download_video
  */
 public function jobDownLoadVideo()
 {
     $username = $_ENV['USERNAME_KEY'];
     VCR::turnOn();
     //VCR::insertCassette('authenticate');
     VCR::insertCassette('job_asset_download_video');
     //Arrange
     $sauce_api = new Client();
     $sauce_api->authenticate($username, $_ENV['TOKEN_PASSWORD'], Client::AUTH_HTTP_PASSWORD);
     //Act
     $jobId = '1cde7b77e8744ff5b6198489ceffce81';
     $response = $sauce_api->api('assets')->downloadVideo($username, $jobId);
     //Assert
     $this->assertNotEmpty($response);
     // To stop recording requests, eject the cassette
     VCR::eject();
     // Turn off VCR to stop intercepting requests
     VCR::turnOff();
 }
Ejemplo n.º 11
0
 public function setUp()
 {
     // Only load env file if it exist.
     // It will use the env variable on server if there's no file
     if (file_exists(__DIR__ . '/.env')) {
         $dotenv = new Dotenv(__DIR__);
         $dotenv->load();
     }
     $this->provider = m::mock('Crew\\Unsplash\\Provider', ['clientId' => 'mock_client_id', 'clientSecret' => 'mock_secret', 'redirectUri' => 'none']);
     $this->provider->clientId = 'mock_client_id';
     $this->accessToken = new AccessToken(['access_token' => getenv('ACCESS_TOKEN')]);
     VCR::configure()->setStorage('json')->addRequestMatcher('validate_authorization', function (\VCR\Request $first, \VCR\Request $second) {
         if ($first->getHeaders()['Authorization'] == $second->getHeaders()['Authorization']) {
             return true;
         } else {
             return false;
         }
     })->enableRequestMatchers(array('method', 'url', 'host', 'query_string', 'body', 'post_fields', 'validate_authorization'));
     VCR::turnOn();
 }
Ejemplo n.º 12
0
 public function testExecuteQueryWithInvalidAPIKey()
 {
     \VCR\VCR::turnOn();
     \VCR\VCR::insertCassette('search_for_spotify_on_sv_blogs');
     $q = $this->client->query();
     $q->pattern = 'spotify page-size:10';
     $q->language = 'sv';
     $r = $q->execute();
     $this->assertGreaterThan(0, count($r->posts));
     \VCR\VCR::turnOff();
 }
Ejemplo n.º 13
0
 function setUp()
 {
     \VCR\VCR::turnOn();
 }
Ejemplo n.º 14
0
 /**
  * A test started.
  *
  * @param PHPUnit_Framework_Test $test
  * @return bool|null
  */
 public function startTest(PHPUnit_Framework_Test $test)
 {
     $class = get_class($test);
     $method = $test->getName(false);
     if (!method_exists($class, $method)) {
         return;
     }
     $reflection = new ReflectionMethod($class, $method);
     $doc_block = $reflection->getDocComment();
     // Use regex to parse the doc_block for a specific annotation
     $parsed = self::parseDocBlock($doc_block, '@vcr');
     $cassetteName = array_pop($parsed);
     // If the cassette name ends in .json, then use the JSON storage format
     if (substr($cassetteName, '-5') == '.json') {
         \VCR\VCR::configure()->setStorage('json');
     }
     if (empty($cassetteName)) {
         return true;
     }
     \VCR\VCR::turnOn();
     \VCR\VCR::insertCassette($cassetteName);
 }
Ejemplo n.º 15
0
 public function setUp()
 {
     \VCR\VCR::configure()->setCassettePath('test/vcr_cassettes');
     \VCR\VCR::turnOn();
 }
Ejemplo n.º 16
0
 /**
  * Starts and configures PHP-VCR
  *
  * @param string[] $options Elements as follow:
  *        string cassette The name of the fixture in tests/fixtures to record or run in this feature test run
  *        string mode     Mode in which to run PHP-VCR (options are none, once, strict, and new_episodes)
  * @return void
  */
 private function startVCR(array $options = ['cassette' => 'tmp', 'mode' => 'none'])
 {
     VCR::configure()->enableRequestMatchers(['method', 'url', 'body']);
     VCR::configure()->setMode($options['mode']);
     VCR::turnOn();
     VCR::insertCassette($options['cassette']);
 }
Ejemplo n.º 17
0
 /**
  * A test started.
  *
  * @param PHPUnit_Framework_Test $test
  */
 public function startTest(PHPUnit_Framework_Test $test)
 {
     $class = get_class($test);
     $method = $test->getName();
     if (!method_exists($class, $method)) {
         return;
     }
     $reflection = new ReflectionMethod($class, $method);
     $doc_block = $reflection->getDocComment();
     // Use regex to parse the doc_block for a specific annotation
     $cassetteName = self::parseDocBlock($doc_block, '@vcr');
     if (empty($cassetteName)) {
         return true;
     }
     \VCR\VCR::turnOn();
     \VCR\VCR::insertCassette(array_pop($cassetteName));
 }
 /**
  * @test
  * @vcr should_take_exception_when_too_many_terms_are_provided.json
  * @expectedException \Kirschbaum\DrupalBehatRemoteAPIDriver\Exception\RuntimeException
  * @expectedExceptionMessage The field_tags field on the remote site requires no more than 1 terms. 2 were provided.
  */
 public function should_take_exception_when_too_many_terms_are_provided()
 {
     // Having trouble with URL encoding match: https://github.com/php-vcr/php-vcr/issues/66
     VCR::configure()->addRequestMatcher('url', function ($first, $second) {
         return $second->getPath() == $first->getPath();
     });
     VCR::turnOn();
     VCR::insertCassette('should_take_exception_when_too_many_terms_are_provided.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $nodeRequest = $client->api('nodes');
     $node = $this->test_node_params();
     $node->field_tags = 'Tag one, Tag two';
     $results = $nodeRequest->createNode($node);
     VCR::eject();
     VCR::turnOff();
 }
Ejemplo n.º 19
0
<?php

namespace {
    require_once __DIR__ . "/../vendor/autoload.php";
    \VCR\VCR::configure()->enableLibraryHooks(['curl'])->setMode('once');
    \VCR\VCR::turnOn();
    function dummyObject($properties = [])
    {
        $object = new \StdClass();
        foreach ($properties as $key => $value) {
            $object->{$key} = $value;
        }
        return $object;
    }
}
namespace Test {
    class HTTPClient
    {
        public $email = null;
        public $api_key = null;
        function get($url, $params, $headers)
        {
        }
        function post($url, $params, $headers)
        {
        }
    }
    class Request
    {
        function get($endpoint, $params = [])
        {
 /**
  * @test
  * @vcr should_delete_term_and_return_empty_array.json
  */
 public function should_delete_term_and_return_empty_array()
 {
     VCR::turnOn();
     VCR::insertCassette('should_create_term_and_return_object_with_term_id.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $term = $client->api('term')->termCreate($this->test_term_params());
     $this->assertObjectHasAttribute('tid', $term);
     VCR::eject();
     VCR::turnOff();
     VCR::turnOn();
     VCR::insertCassette('should_delete_term_and_return_empty_array.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results = $client->api('term')->termDelete($term);
     $this->assertEmpty($results);
     VCR::eject();
     VCR::turnOff();
 }