/** * @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(); }
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); }
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 testFindUserLikedPhoto() { VCR::insertCassette('users.yml'); $user = Unsplash\User::find('dechuck'); $likes = $user->likes(); VCR::eject(); $this->assertNotEmpty($likes); }
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 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); }
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']); }
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']); }
public function testUnlikePhoto() { VCR::insertCassette('photos.yml'); $photo = Unsplash\Photo::find('j0g8taxHZa0'); $like = $photo->like(); $unlike = $photo->unlike(); VCR::eject(); $this->assertTrue($unlike); }
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); }
/** * @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(); }
public function testShouldInterceptSoapLibrary() { VCR::configure()->enableLibraryHooks(array('soap')); VCR::turnOn(); VCR::insertCassette('unittest_soap_test'); $client = new \SoapClient('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL', array('soap_version' => SOAP_1_2)); $actual = $client->GetCityWeatherByZIP(array('ZIP' => '10013')); $temperature = $actual->GetCityWeatherByZIPResult->Temperature; $this->assertEquals('1337', $temperature, 'Soap call was not intercepted.'); VCR::eject(); VCR::turnOff(); }
/** * 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(); }
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(); }
/** * @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(); }
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(); }); });
/** * @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(); }
/** * Stops PHP-VCR's recording and playback * * @return void */ private function stopVCR() { VCR::eject(); VCR::turnOff(); }
public function tearDown() { VCR::eject(); VCR::turnOff(); parent::tearDown(); }
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(); }
function tearDown() { \VCR\VCR::eject(); \VCR\VCR::turnOff(); }
/** * @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(); }
/** * @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(); }