Exemplo n.º 1
0
 public function testShouldSetAConfiguration()
 {
     VCR::configure()->setCassettePath('tests');
     VCR::turnOn();
     $this->assertEquals('tests', VCR::configure()->getCassettePath());
     VCR::turnOff();
 }
 /**
  * {inheritDoc}
  */
 public function setMatchers()
 {
     parent::setMatchers();
     VCR::configure()->addRequestMatcher('exception', function (Request $first, Request $second) {
         $first = simplexml_load_string($first->getBody());
         $second = simplexml_load_string($second->getBody());
         $this->assertSame((string) $first->error->class, (string) $second->error->class);
         $this->assertSame((string) $first->request->params->var, (string) $second->request->params->var);
         return true;
     });
     VCR::configure()->enableRequestMatchers(['method', 'url', 'host', 'post_fields', 'exception']);
 }
 /**
  * {inheritDoc}
  */
 public function setMatchers()
 {
     parent::setMatchers();
     VCR::configure()->addRequestMatcher('exception', function (Request $first, Request $second) {
         $first = json_decode($first->getBody());
         $second = json_decode($second->getBody());
         $this->assertSame($first->events[0]->exceptions[0]->errorClass, $second->events[0]->exceptions[0]->errorClass);
         $this->assertSame($first->events[0]->metaData->php_version, $second->events[0]->metaData->php_version);
         return true;
     });
     VCR::configure()->enableRequestMatchers(['method', 'url', 'host', 'post_fields', 'exception']);
 }
 /**
  * {inheritDoc}
  */
 public function setMatchers()
 {
     parent::setMatchers();
     VCR::configure()->addRequestMatcher('exception', function (Request $first, Request $second) {
         $first = json_decode(gzuncompress(base64_decode($first->getBody())));
         $second = json_decode(gzuncompress(base64_decode($second->getBody())));
         $this->assertSame($first->message, $second->message);
         $this->assertSame($first->extra->php_version, $second->extra->php_version);
         return true;
     });
     VCR::configure()->enableRequestMatchers(['method', 'url', 'host', 'post_fields', 'exception']);
 }
 /**
  * {inheritDoc}
  */
 public function setMatchers()
 {
     parent::setMatchers();
     VCR::configure()->addRequestMatcher('exception', function (Request $first, Request $second) {
         $first = json_decode($first->getBody())->data->body->trace->exception;
         $second = json_decode($second->getBody())->data->body->trace->exception;
         // The below asserts will throw exceptions, however Rollbar swallows them up and PHPUnit doesn't detect
         // them. So we catch and set the exception to be rethrown when outside Rollbar.
         try {
             $this->assertSame($first->class, $second->class);
             $this->assertSame($first->message, $second->message);
         } catch (PHPUnit_Framework_ExpectationFailedException $e) {
             $this->requestsMatchedException = $e;
         }
         return true;
     });
     VCR::configure()->enableRequestMatchers(['method', 'url', 'host', 'post_fields', 'exception']);
 }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
0
 public function setUp()
 {
     \VCR\VCR::configure()->setCassettePath('test/vcr_cassettes');
     \VCR\VCR::turnOn();
 }
Exemplo n.º 8
0
<?php

if (!file_exists(__DIR__ . "/../vendor/autoload.php")) {
    die("\n[ERROR] You need to run composer before running the test suite.\n" . "To do so run the following commands:\n" . "    curl -s http://getcomposer.org/installer | php\n" . "    php composer.phar install\n\n");
}
require_once __DIR__ . '/../vendor/autoload.php';
$useCustomInfo = false;
$testConfig = \Symfony\Component\Yaml\Yaml::parse('tests/xmlrpc.yml');
if ($testConfig['endpoint'] && $testConfig['admin_login'] && $testConfig['admin_password'] && $testConfig['guest_login'] && $testConfig['guest_password']) {
    $useCustomInfo = true;
}
if (!$useCustomInfo) {
    \VCR\VCR::configure()->enableLibraryHooks(array('stream_wrapper', 'curl'));
} else {
    VCR\VCR::configure()->enableLibraryHooks(array());
}
Exemplo n.º 9
0
<?php

require_once "vendor/autoload.php";
function arrayify($object)
{
    return json_decode(json_encode($object), true);
}
function var_export_compact($object)
{
    $data = var_export($object, true);
    $data = str_replace("array (", "[", $data);
    $data = str_replace(")", "]", $data);
    $data = str_replace("\n", " ", $data);
    $data = str_replace("\t", "", $data);
    $data = preg_replace('/(\\s)+/', ' ', $data);
    $data = str_replace(", ]", "]", $data);
    $data = str_replace("[ ", "[", $data);
    return $data;
}
\Thru\TutumApi\Client::configure('matthewbaggett', 'decea003584f7df33be57f547f63f2cccd8e3188');
\VCR\VCR::configure()->setMode('new_episodes')->enableLibraryHooks(array('curl', 'stream_wrapper'));
Exemplo n.º 10
0
<?php

require 'vendor/autoload.php';
\VCR\VCR::configure()->enableLibraryHooks(['curl'])->setStorage('json');
\VCR\VCR::turnOn();
Exemplo n.º 11
0
 public function setUp()
 {
     \VCR\VCR::configure()->setCassettePath('tests/fixtures/vcr_cassettes')->enableRequestMatchers(array('method', 'url'));
 }
Exemplo n.º 12
0
<?php

if (!file_exists(__DIR__ . "/../../vendor/autoload.php")) {
    die("\n[ERROR] You need to run composer before running the test suite.\n" . "To do so run the following commands:\n" . "    curl -s http://getcomposer.org/installer | php\n" . "    php composer.phar install\n\n");
}
require_once __DIR__ . '/../../vendor/autoload.php';
\VCR\VCR::configure()->setCassettePath('test/fixtures');
\VCR\VCR::turnOn();
Exemplo n.º 13
0
<?php

error_reporting(E_ALL);
// Disable garbage collection
// https://scrutinizer-ci.com/blog/composer-gc-performance-who-is-affected-too
gc_disable();
require __DIR__ . '/../vendor/autoload.php';
// We want to compare all headers except for the User-Agent because it's based
// on the local php and curl versions which can change.
\VCR\VCR::configure()->addRequestMatcher('custom_headers', function (\VCR\Request $first, \VCR\Request $second) {
    $firstHeaders = $first->getHeaders();
    $secondHeaders = $second->getHeaders();
    unset($firstHeaders['User-Agent']);
    unset($secondHeaders['User-Agent']);
    return count(array_diff_assoc($firstHeaders, $secondHeaders)) === 0;
});
// Configure how live requests are compared against recorded tests and
// determined to be the same.
\VCR\VCR::configure()->enableRequestMatchers(array('method', 'url', 'query_string', 'body', 'custom_headers'));
// This tells PHP-VCR to record a test if there is no previous recording. If there
// is a recording then PHP-VCR will compare requests against those stored in the recording.
\VCR\VCR::configure()->setMode('once');
// This instruct PHP-VCR to only instrument guzzle with code to intercept requests
\VCR\VCR::configure()->setWhiteList(array('vendor/guzzlehttp'));
Exemplo n.º 14
0
<?php

/**
 * Bootstrap file for unit tests
 */
define('CLI_ROOT', dirname(__DIR__) . '/..');
define('TEST_DIR', dirname(__DIR__));
define('TERMINUS_CMD', 'php ' . CLI_ROOT . '/php/boot-fs.php');
putenv('CLI_TEST_MODE=1');
require_once CLI_ROOT . '/vendor/autoload.php';
require_once CLI_ROOT . '/php/boot-fs.php';
Terminus::set_config('nocache', true);
Terminus::set_config('debug', false);
use Terminus\Session;
// Set some dummy credentials
Session::setData(json_decode('{
  "user_uuid": "0ffec038-4410-43d0-a404-46997f672d7a",
  "session": "0ffec038-4410-43d0-a404-46997f672d7a%3A68486878-dd87-11e4-b243-bc764e1113b5%3AbQR2fyNMh5PQXN6F2Ewge",
  "session_expire_time": 1739299351,
  "email": "*****@*****.**"
}'));
\VCR\VCR::configure()->enableRequestMatchers(array('method', 'url', 'body'));
# Prevent API requests from being made in CI Environment
$ci_environment = getenv('CI');
if ($ci_environment) {
    \VCR\VCR::configure()->setMode('none');
}
Exemplo n.º 15
0
<?php

/**
 * PHP SMS
 *
 * Licensed under the MPL v2.0
 *
 * @author    Jacques Marneweck <*****@*****.**>
 * @copyright 2014-2016 Jacques Marneweck.  All rights strictly reserved.
 * @license   MPL
 */
require_once __DIR__ . '/../vendor/autoload.php';
\VCR\VCR::configure()->enableRequestMatchers(array('method', 'url', 'host'));
\VCR\VCR::turnOn();
Exemplo 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']);
 }
<?php

function includeIfExists($file)
{
    if (file_exists($file)) {
        return include $file;
    }
}
if (!($loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && !($loader = includeIfExists(__DIR__ . '/../../../.composer/autoload.php'))) {
    die('You must set up the project dependencies, run the following commands:' . PHP_EOL . 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . 'php composer.phar install' . PHP_EOL);
}
\VCR\VCR::configure()->setStorage('json')->setCassettePath(__DIR__ . '/../test/fixtures');
$loader->add('Kirschbaum\\DrupalBehatRemoteAPIDriver\\Tests', __DIR__);
return $loader;
Exemplo n.º 18
0
<?php

use kahlan\filter\Filter;
use VCR\VCR;
VCR::configure()->setCassettePath(__DIR__ . '/spec/fixtures');
VCR::turnOn();
Filter::register('exclude.namespaces', function ($chain) {
});
Filter::apply($this, 'interceptor', 'exclude.namespaces');
Exemplo n.º 19
0
<?php

use Composer\Autoload\ClassLoader;
use VCR\VCR;
require_once __DIR__ . '/../vendor/autoload.php';
$classloader = new ClassLoader();
$classloader->set('Wsdl2PhpGenerator', array('tests'));
$classloader->register();
VCR::configure()->setCassettePath('tests/fixtures/vcr');
VCR::turnOn();
Exemplo n.º 20
0
<?php

require __DIR__ . '/../lib/P7/SSO.php';
$config = \VCR\VCR::configure();
$config->setMode('none');
$config->enableRequestMatchers(array('method', 'url', 'host', 'query_string', 'body', 'post_fields'));
Exemplo n.º 21
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.º 22
0
// Set some dummy credentials
Session::setData(json_decode('{
    "user_uuid": "dca4f8cd-9ec2-4117-957f-fc5230c23737",
    "session": "dca4f8cd-9ec2-4117-957f-fc5230c23737:20e4ceb0-b224-11e4-94f5-bc764e111d20:jakuWJ8hw4PGMq9Plm9wk",
    "session_expire_time": 1739299351,
    "email": "*****@*****.**"
}'));
/**
 * Modified match function to replace VCR\RequestMatcher::matchHeaders() Returns true if the headers of both specified requests match.
 *
 * @param  Request $first  First request to match.
 * @param  Request $second Second request to match.
 *
 * @return boolean True if the headers of both specified requests match.
 */
\VCR\VCR::configure()->addRequestMatcher('headers', 'custom_terminus_match_headers');
function custom_terminus_match_headers($first, $second)
{
    $firstHeaders = $first->getHeaders();
    foreach ($second->getHeaders() as $key => $pattern) {
        //normalize the cookie to ensure match
        if ('Cookie' == $key) {
            return true;
        }
        if ($pattern !== $firstHeaders[$key]) {
            var_dump($pattern);
            return false;
        }
    }
    return true;
}
Exemplo n.º 23
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.º 24
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
\VCR\VCR::configure()->setCassettePath('test/fixtures')->enableLibraryHooks(['soap']);
\VCR\VCR::turnOn();
 public function setUp()
 {
     \VCR\VCR::configure()->setCassettePath('tests/fixtures/vcr_cassettes');
 }
Exemplo n.º 26
0
<?php

require __DIR__ . '/../vendor/autoload.php';
\VCR\VCR::configure()->enableLibraryHooks(['stream_wrapper', 'curl']);
\VCR\VCR::turnOn();
 /**
  * If you have made a change and VCR is complaining that the request doesn't match,
  * delete the file in tests/fixtures/{request}.yml so that a new version can be
  * generated to match against.
  */
 public function setUp()
 {
     VCR::configure()->setCassettePath('tests/fixtures')->setMode(getenv('VCR_MODE'));
     $this->setMatchers();
 }
 /**
  * @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();
 }
Exemplo n.º 29
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 = [])
        {
Exemplo n.º 30
0
<?php

use Kahlan\Filter\Filter;
use VCR\VCR;
$this->args()->argument('reporter', 'default', 'verbose');
VCR::configure()->setCassettePath(__DIR__ . '/spec/fixtures')->enableRequestMatchers(['method', 'url', 'query_string', 'host']);
VCR::turnOn();
Filter::register('exclude.namespaces', function ($chain) {
});
Filter::apply($this, 'interceptor', 'exclude.namespaces');