diff --git a/src/PhpBrew/Testing/CommandTestCase.php b/src/PhpBrew/Testing/CommandTestCase.php index c3453c04b..9feec077a 100644 --- a/src/PhpBrew/Testing/CommandTestCase.php +++ b/src/PhpBrew/Testing/CommandTestCase.php @@ -2,9 +2,10 @@ namespace PhpBrew\Testing; -use CLIFramework\Testing\CommandTestCase as BaseCommandTestCase; use PhpBrew\Console; use GetOptionKit\Option; +use PhpBrew\Testing\VCRAdapter; +use CLIFramework\Testing\CommandTestCase as BaseCommandTestCase; abstract class CommandTestCase extends BaseCommandTestCase { @@ -16,6 +17,11 @@ abstract class CommandTestCase extends BaseCommandTestCase public $primaryVersion = '5.5.37'; + /** + * You need to set this to true in each subclass you want to use VCR in. + */ + public $usesVCR = false; + public function getPrimaryVersion() { /* @@ -53,6 +59,10 @@ public function setUp() $option->setValue(true); $options->set('no-progress', $option); } + + if ($this->usesVCR) { + VCRAdapter::enableVCR($this); + } } /* @@ -68,6 +78,10 @@ public function tearDown() if ($this->previousPhpBrewHome !== null) { // putenv('PHPBREW_HOME=' . $this->previousPhpBrewHome); } + + if ($this->usesVCR) { + VCRAdapter::disableVCR(); + } } public function assertCommandSuccess($args) diff --git a/src/PhpBrew/Testing/VCRAdapter.php b/src/PhpBrew/Testing/VCRAdapter.php new file mode 100644 index 000000000..4ec6d7815 --- /dev/null +++ b/src/PhpBrew/Testing/VCRAdapter.php @@ -0,0 +1,27 @@ +logger = Logger::getInstance(); $this->logger->setQuiet(); + + VCRAdapter::enableVCR($this); + } + + public function tearDown() { + VCRAdapter::disableVCR(); } + /** + * @group noVCR + */ public function testDownloadByWgetCommand() { $this->_test('PhpBrew\Downloader\WgetCommandDownloader'); } + /** + * @group noVCR + */ public function testDownloadByCurlCommand() { $this->_test('PhpBrew\Downloader\CurlCommandDownloader'); diff --git a/tests/PhpBrew/Extension/ExtensionInstallerTest.php b/tests/PhpBrew/Extension/ExtensionInstallerTest.php index 9f247b66f..3b0dc5f9f 100644 --- a/tests/PhpBrew/Extension/ExtensionInstallerTest.php +++ b/tests/PhpBrew/Extension/ExtensionInstallerTest.php @@ -1,17 +1,17 @@ runCommand("phpbrew use php-{$versionName}"); } + /** + * @group noVCR + */ public function testPackageUrl() { $logger = new Logger; diff --git a/tests/PhpBrew/Extension/ExtensionManagerTest.php b/tests/PhpBrew/Extension/ExtensionManagerTest.php index 71b68b2f1..742c6626b 100644 --- a/tests/PhpBrew/Extension/ExtensionManagerTest.php +++ b/tests/PhpBrew/Extension/ExtensionManagerTest.php @@ -1,7 +1,9 @@ setQuiet(); $this->manager = new ExtensionManager($logger); + + VCRAdapter::enableVCR($this); + } + + public function tearDown() + { + VCRAdapter::disableVCR(); } public function testCleanExtension() diff --git a/tests/PhpBrew/Extension/ExtensionTest.php b/tests/PhpBrew/Extension/ExtensionTest.php index e27694769..6e8f1d089 100644 --- a/tests/PhpBrew/Extension/ExtensionTest.php +++ b/tests/PhpBrew/Extension/ExtensionTest.php @@ -1,10 +1,12 @@ setCassettePath(__DIR__.'/fixtures/vcr_cassettes') - ->enableLibraryHooks(array('curl')) + ->setCassettePath('tests/fixtures/vcr_cassettes') + ->enableLibraryHooks(array('curl', 'stream_wrapper')) ->setStorage('json'); diff --git a/tests/fixtures/vcr_cassettes/Downloader/DownloaderTest b/tests/fixtures/vcr_cassettes/Downloader/DownloaderTest new file mode 100644 index 000000000..0e56ea30a --- /dev/null +++ b/tests/fixtures/vcr_cassettes/Downloader/DownloaderTest @@ -0,0 +1,27 @@ +[{ + "request": { + "method": "GET", + "url": "http:\/\/httpbin.org\/", + "headers": { + "Host": "httpbin.org" + } + }, + "response": { + "status": { + "http_version": "1.1", + "code": "200", + "message": "OK" + }, + "headers": { + "Connection": "keep-alive", + "Server": "gunicorn\/19.9.0", + "Date": "Mon, 05 Nov 2018 03:56:04 GMT", + "Content-Type": "text\/html; charset=utf-8", + "Content-Length": "10122", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Credentials": "true", + "Via": "1.1 vegur" + }, + "body": "\n\n\n
\n \n