/**
  * @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();
 }
Exemplo n.º 2
0
 public function testDoesNotBlockThrowingExceptions()
 {
     VCR::turnOn();
     $this->setExpectedException('InvalidArgumentException');
     VCR::insertCassette('unittest_cassette1');
     throw new \InvalidArgumentException('test');
 }
Exemplo n.º 3
0
 public function testFindTotalStats()
 {
     VCR::insertCassette('stats.yml');
     $totalStats = Unsplash\Stat::total();
     VCR::eject();
     $this->assertEquals($this->total['photo_downloads'], $totalStats->photo_downloads);
     $this->assertEquals($this->total['batch_downloads'], $totalStats->batch_downloads);
 }
 function testPostRequestIsUnsuccessful()
 {
     \VCR\VCR::insertCassette('gathercontent_post_projects_failure.yml');
     $subject = new HTTPClient('*****@*****.**', 'bogus-api-key');
     $response = $subject->post('https://api.gathercontent.com/projects', ['account_id' => '20225', 'name' => 'Project Name'], ['Accept: application/vnd.gathercontent.v0.5+json']);
     $this->assertNotEquals(200, $response->status);
     $this->assertEquals('Invalid credentials.', $response->body);
 }
Exemplo n.º 5
0
 public function testFindUserLikedPhoto()
 {
     VCR::insertCassette('users.yml');
     $user = Unsplash\User::find('dechuck');
     $likes = $user->likes();
     VCR::eject();
     $this->assertNotEmpty($likes);
 }
Exemplo n.º 6
0
 public function testRequest()
 {
     VCR::insertCassette('endpoint.yml');
     $res = Unsplash\Endpoint::__callStatic('get', ['categories/2', []]);
     VCR::eject();
     $body = json_decode($res->getBody());
     $this->assertEquals(2, $body->id);
 }
Exemplo n.º 7
0
 public function testFindNoPhotoForACategory()
 {
     VCR::insertCassette('categories.yml');
     $category = Unsplash\Category::find(2);
     $photos = $category->photos(2000);
     VCR::eject();
     $this->assertEquals(0, $photos->count());
 }
 public function testFindCuratedBatchPhotos()
 {
     VCR::insertCassette('curated_batches.yml');
     $curatedBatch = Unsplash\CuratedBatch::find(68);
     $photos = $curatedBatch->photos();
     VCR::eject();
     $this->assertEquals(10, $photos->count());
 }
 public function testRequestSendThroughClient()
 {
     Unsplash\HttpClient::$connection = $this->connection;
     VCR::insertCassette('categories.yml');
     $response = (new Unsplash\HttpClient())->send("get", ['categories/2']);
     $body = json_decode($response->getBody(), true);
     VCR::eject();
     $this->assertEquals(2, $body['id']);
 }
Exemplo n.º 10
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();
 }
Exemplo n.º 11
0
 public function testRandomPhotoWithFilters()
 {
     VCR::insertCassette('photos.yml');
     $filters = ['category' => [2, 3], 'featured' => true, 'username' => 'andy_brunner', 'query' => 'ice', 'w' => 100, 'h' => 100];
     $photo = Unsplash\Photo::random($filters);
     VCR::eject();
     $this->assertEquals('ZUaqqMxtxYk', $photo->id);
     $this->assertEquals('https://unsplash.imgix.net/photo-1428681756973-d318f055795a?q=75&fm=jpg&w=100&h=100&fit=max&s=b223d24e28ba1ced6731e98d46cd5f83', $photo->urls['custom']);
 }
Exemplo n.º 12
0
 public function testUnlikePhoto()
 {
     VCR::insertCassette('photos.yml');
     $photo = Unsplash\Photo::find('j0g8taxHZa0');
     $like = $photo->like();
     $unlike = $photo->unlike();
     VCR::eject();
     $this->assertTrue($unlike);
 }
Exemplo n.º 13
0
 public function testUpdateUser()
 {
     $this->markTestIncomplete('Due to an issue with VCR, we do not run this test.');
     $newInstagramUsername = '******' . time();
     VCR::insertCassette('users.yml');
     $user = Unsplash\User::find('dechuck');
     $user->update(['instagram_username' => $newInstagramUsername]);
     VCR::eject();
     $this->assertEquals($newInstagramUsername, $user->instagram_username);
 }
Exemplo n.º 14
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();
 }
Exemplo n.º 16
0
 /**
  * Gets the URL with file_get_contents, explicitly setting follow_location 
  * in the context
  */
 public function testWithVcrFollowLocation()
 {
     \VCR\VCR::insertCassette('with_follow_location');
     $opts = array('http' => array('follow_location' => 1));
     $context = stream_context_create($opts);
     $source = file_get_contents(self::URL, false, $context);
     # Make sure contents were got
     $this->assertNotEmpty($source);
     # Make sure there's nothing before the contents
     $this->assertSame(0, strpos($source, '<!doctype html>'), 'Source starts with "' . substr($source, 0, 15) . '"');
     # Make sure we grabbed the right thing
     $this->assertContains('<title>abeger - Gravatar Profile</title>', $source);
     \VCR\VCR::eject();
 }
Exemplo n.º 17
0
 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();
 }
Exemplo n.º 19
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();
 }
Exemplo n.º 21
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();
 }
Exemplo n.º 22
0
<?php

namespace Teazee\Spec\Provider;

use GuzzleHttp\Client;
use Http\Adapter\Guzzle6\Client as HttpAdapter;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use RuntimeException;
use Teazee\Provider\TimezoneDb;
use Teazee\ZoneInfo;
use VCR\VCR;
describe(TimezoneDb::class, function () {
    before(function () {
        VCR::insertCassette('timezone_db');
        $this->lat = 40.1146914;
        $this->lng = -88.3121289;
    });
    beforeEach(function () {
        $this->teazee = new TimezoneDb('TVDB_TEAZEE_KEY', false, new HttpAdapter(new Client()), new GuzzleMessageFactory());
    });
    it('->getName()', function () {
        expect($this->teazee->getName())->toBe('timezone_db');
    });
    context('without discovery', function () {
        it('fails without an HttpClient', function () {
            expect(function () {
                new TimezoneDb('SOME_API_KEY');
            })->toThrow();
        });
        it('fails without a MessageFactory', function () {
            expect(function () {
Exemplo n.º 23
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();
 }
Exemplo n.º 24
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);
 }
Exemplo n.º 25
0
if (PHP_SAPI == 'cli' && isset($argv)) {
    $source = explode('/', $argv[0]);
    $source = end($source);
}
define('TERMINUS_SCRIPT', $source);
date_default_timezone_set('UTC');
include TERMINUS_ROOT . '/php/utils.php';
include TERMINUS_ROOT . '/php/FileCache.php';
include TERMINUS_ROOT . '/php/dispatcher.php';
include TERMINUS_ROOT . '/php/class-terminus.php';
include TERMINUS_ROOT . '/php/class-terminus-command.php';
\Terminus\Utils\load_dependencies();
//Set a custom exception handler
set_exception_handler('\\Terminus\\Utils\\handle_exception');
if (isset($_SERVER['TERMINUS_HOST']) && $_SERVER['TERMINUS_HOST'] != '') {
    define('TERMINUS_HOST', $_SERVER['TERMINUS_HOST']);
} else {
    define('TERMINUS_HOST', 'dashboard.getpantheon.com');
}
define('TERMINUS_PORT', '443');
if (isset($_SERVER['VCR_CASSETTE'])) {
    \VCR\VCR::configure()->enableRequestMatchers(array('method', 'url', 'body'));
    \VCR\VCR::configure()->setMode($_SERVER['VCR_MODE']);
    \VCR\VCR::turnOn();
    \VCR\VCR::insertCassette($_SERVER['VCR_CASSETTE']);
}
Terminus::get_runner()->run();
if (isset($_SERVER['VCR_CASSETTE'])) {
    \VCR\VCR::eject();
    \VCR\VCR::turnOff();
}
Exemplo n.º 26
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));
 }
Exemplo n.º 27
0
<?php

use Sturgeon\PHPArse\Info;
use Sturgeon\PHPArse\Parser;
use VCR\VCR;
describe(Parser::class, function () {
    before(function () {
        VCR::insertCassette('phpinfos');
    });
    after(function () {
        VCR::eject();
    });
    beforeEach(function () {
        $url = 'http://localhost:8000/?version=7.0.11';
        $this->parser = Parser::readFromUrl($url);
    });
    describe('->parse()', function () {
        it('returns an instance of info, which is probably correct', function () {
            expect($this->parser->parse())->toBeAnInstanceOf(Info::class);
        });
    });
    describe('->locatePhpVersion()', function () {
        it("returns '5.6.12'", function () {
            expect($this->parser->locatePhpVersion())->toBe('5.6.12');
        });
    });
    describe('->locateGeneralInfo()', function () {
        it("returns a few key items", function () {
            $info = $this->parser->locateGeneralInfo();
            expect($info)->toContainKey('Build Date');
            expect($info)->toContainKey('Configure Command');
Exemplo n.º 28
0
    context('with invalid parameters', function () {
        it('fails with an invalid API key', function () {
            $expected = function () {
                (new GoogleMaps('TEAZEE_BAD_KEY', new HttpAdapter(new Client()), new GuzzleMessageFactory()))->find($this->lat, $this->lng, 1455926050);
            };
            expect($expected)->toThrow(new RuntimeException('The provided API key is invalid.'));
        });
    });
    context('when no timestamp given', function () {
        before(function () {
            VCR::turnOff();
        });
        beforeEach(function () {
            $this->now = (new DateTimeImmutable(null, new DateTimeZone('UTC')))->getTimestamp();
            $this->time = $this->teazee->find($this->lat, $this->lng)->getTimestamp();
        });
        it('uses the default timestamp', function () {
            // Note: this _could_ fail if response times are especially bad, but it's google,
            // so we'll take our chances.
            expect($this->time)->toBeGreaterThan($this->now - 1);
            expect($this->time)->toBeLessThan($this->now + 3);
        });
        after(function () {
            VCR::turnOn();
            VCR::insertCassette('google_maps');
        });
    });
    after(function () {
        VCR::eject();
    });
});
Exemplo n.º 29
0
 /**
  * @covers \Plutus\Client\User::getUsers
  */
 public function testNullLimitMoreThan100()
 {
     \VCR\VCR::insertCassette('unittest_user_get_users_limit_null_offset_100');
     $response = $this->client->getUsers(null, 100);
     $this->assertObjectHasAttribute('status', $response);
     $this->assertObjectHasAttribute('details', $response);
     $this->assertInternalType('string', $response->status);
     $this->assertInternalType('array', $response->details);
     $this->assertEquals('ok', $response->status);
     $this->assertCount(100, $response->details);
     \VCR\VCR::eject();
 }
 /**
  * @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();
 }