Skip to content

Commit

Permalink
Merge pull request #111 from hirak/improve-test-coverage
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
hirak authored Jun 26, 2016
2 parents 49e50d3 + 618aaea commit b85d88e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function getProxy($url)
* @param $githubDomains
* @param $gitlabDomains
*/
protected function setupAuthentication(IO\IOInterface $io, $useRedirector, array $githubDomains = array(), array $gitlabDomains = array())
protected function setupAuthentication(IO\IOInterface $io, $useRedirector, array $githubDomains, array $gitlabDomains)
{
if (preg_match('/\.github\.com$/', $this->host)) {
$authKey = 'github.com';
Expand Down Expand Up @@ -270,4 +270,9 @@ public function setCA($path = null, $file = null)
$this->capath = $path;
$this->cafile = $file;
}

public function isHTTP()
{
return $this->scheme === 'http' || $this->scheme === 'https';
}
}
7 changes: 6 additions & 1 deletion src/CopyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public function __construct($url, $destination, $useRedirector, IO\IOInterface $
$this->setURL($url);
$this->setDestination($destination);
$this->setCA($config->get('capath'), $config->get('cafile'));
$this->setupAuthentication($io, $useRedirector, $config->get('github-domains'), $config->get('gitlab-domains'));
$this->setupAuthentication(
$io,
$useRedirector,
$config->get('github-domains') ?: array(),
$config->get('gitlab-domains') ?: array()
);
}

public function __destruct()
Expand Down
5 changes: 4 additions & 1 deletion src/CurlRemoteFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

class CurlRemoteFilesystem extends Util\RemoteFilesystem
{
protected $io, $config, $options, $disableTls;
protected $io;
protected $config;
protected $options;
protected $disableTls;

private $req;

Expand Down
11 changes: 9 additions & 2 deletions src/FetchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public function __construct($url, IO\IOInterface $io, Config $config)
{
$this->setURL($url);
$this->setCA($config->get('capath'), $config->get('cafile'));
$this->setupAuthentication($io, false, $config->get('github-domains'), $config->get('gitlab-domains'));
$this->setupAuthentication(
$io,
false,
$config->get('github-domains') ?: array(),
$config->get('gitlab-domains') ?: array()
);
}

public function getCurlOptions()
Expand Down Expand Up @@ -71,7 +76,9 @@ public function fetch()
$this->error = curl_error($ch);
$info = curl_getinfo($ch);

if ($errno === CURLE_OK && $info['http_code'] === 200) {
if (!$this->isHTTP()) {
return $result;
} elseif ($errno === CURLE_OK && $info['http_code'] === 200) {
return $result;
} else {
return false;
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/CurlRemoteFilesystemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace Hirak\Prestissimo;

class CurlRemoteFilesystemTest extends \PHPUnit_Framework_TestCase
{
// dummy objects
private $iop;
private $configp;

protected function setUp()
{
$this->iop = $this->prophesize('Composer\IO\IOInterface');
$this->configp = $this->prophesize('Composer\Config');
}

public function testConstruct()
{
$rfs = new CurlRemoteFilesystem(
$this->iop->reveal(),
$this->configp->reveal()
);

self::assertEmpty($rfs->__debugInfo());

$content = $rfs->getContents('https://packagist.jp', 'https://packagist.jp/packages.json');
self::assertInternalType('string', $content);

$headers = $rfs->getLastHeaders();
self::assertInternalType('array', $headers);
}
}

0 comments on commit b85d88e

Please sign in to comment.