Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option when VCR is enabled globally for all tests #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions PHPUnit/Util/Log/VCR.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PHPUnit_Util_Log_VCR implements PHPUnit_Framework_TestListener
*/
public function __construct(array $options = array())
{
$this->options = $options;
}

/**
Expand All @@ -55,7 +56,7 @@ public function __construct(array $options = array())
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
}

/**
* A warning occurred.
*
Expand Down Expand Up @@ -144,7 +145,10 @@ public function startTest(PHPUnit_Framework_Test $test)
return true;
}

\VCR\VCR::turnOn();
if (!$this->options['enableGlobally']) {
\VCR\VCR::turnOn();
}

\VCR\VCR::insertCassette($cassetteName);
}

Expand All @@ -153,7 +157,7 @@ private static function parseDocBlock($doc_block, $tag)
$matches = array();

if (empty($doc_block))
return $matches;
return $matches;

$regex = "/{$tag} (.*)(\\r\\n|\\r|\\n)/U";
preg_match_all($regex, $doc_block, $matches);
Expand All @@ -167,7 +171,7 @@ private static function parseDocBlock($doc_block, $tag)

// Trim the results, array item by array item
foreach ($matches as $ix => $match)
$matches[$ix] = trim( $match );
$matches[$ix] = trim( $match );

return $matches;
}
Expand All @@ -179,7 +183,9 @@ private static function parseDocBlock($doc_block, $tag)
*/
public function endTest(PHPUnit_Framework_Test $test, $time)
{
\VCR\VCR::turnOff();
if (!$this->options['enableGlobally']) {
\VCR\VCR::turnOff();
}
}

/**
Expand Down