Skip to content

Commit

Permalink
Merge branch 'develop' into testing3/http
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-parry committed Oct 10, 2018
2 parents b3ae918 + c1e2d88 commit 38a0905
Show file tree
Hide file tree
Showing 10 changed files with 970 additions and 31 deletions.
14 changes: 13 additions & 1 deletion system/HTTP/CLIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ public function getOptions(): array

//--------------------------------------------------------------------

/**
* Returns the path segments.
*
* @return array
*/
public function getSegments(): array
{
return $this->segments;
}

//--------------------------------------------------------------------

/**
* Returns the value for a single CLI option that was passed in.
*
Expand Down Expand Up @@ -178,7 +190,7 @@ public function getOptionString(): string
$out .= "-{$name} $value ";
}

return $out;
return trim($out);
}

//--------------------------------------------------------------------
Expand Down
27 changes: 17 additions & 10 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace CodeIgniter\HTTP;
<?php

namespace CodeIgniter\HTTP;

/**
* CodeIgniter
Expand Down Expand Up @@ -71,10 +73,10 @@ class CURLRequest extends Request
* @var array
*/
protected $config = [
'timeout' => 0.0,
'connect_timeout' => 150,
'debug' => false,
'verify' => true
'timeout' => 0.0,
'connect_timeout' => 150,
'debug' => false,
'verify' => true
];

/**
Expand All @@ -84,9 +86,9 @@ class CURLRequest extends Request
* @var array
*/
protected $redirectDefaults = [
'max' => 5,
'strict' => true,
'protocols' => ['http', 'https'],
'max' => 5,
'strict' => true,
'protocols' => ['http', 'https'],
];

/**
Expand Down Expand Up @@ -114,7 +116,10 @@ public function __construct(App $config, URI $uri, ResponseInterface $response =
{
if ( ! function_exists('curl_version'))
{
// we won't see this during travis-CI
// @codeCoverageIgnoreStart
throw HTTPException::forMissingCurl();
// @codeCoverageIgnoreEnd
}

parent::__construct($config);
Expand Down Expand Up @@ -571,7 +576,7 @@ protected function setCURLOptions(array $curl_options = [], array $config = [])
$cert = $cert[0];
}

if (! file_exists($cert))
if ( ! file_exists($cert))
{
throw HTTPException::forSSLCertNotFound($cert);
}
Expand All @@ -586,7 +591,7 @@ protected function setCURLOptions(array $curl_options = [], array $config = [])
{
$file = realpath($config['ssl_key']);

if (! $file)
if ( ! $file)
{
throw HTTPException::forInvalidSSLKey($config['ssl_key']);
}
Expand Down Expand Up @@ -723,6 +728,8 @@ protected function setCURLOptions(array $curl_options = [], array $config = [])
* Does the actual work of initializing cURL, setting the options,
* and grabbing the output.
*
* @codeCoverageIgnore
*
* @param array $curl_options
*
* @return string
Expand Down
6 changes: 6 additions & 0 deletions system/HTTP/Exceptions/HTTPException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class HTTPException extends FrameworkException implements ExceptionInterface
* For CurlRequest
*
* @return \CodeIgniter\HTTP\Exceptions\HTTPException
*
* Not testable with travis-ci
* @codeCoverageIgnore
*/
public static function forMissingCurl()
{
Expand Down Expand Up @@ -48,6 +51,9 @@ public static function forInvalidSSLKey(string $key)
* @param string $error
*
* @return \CodeIgniter\HTTP\Exceptions\HTTPException
*
* Not testable with travis-ci; we over-ride the method which triggers it
* @codeCoverageIgnore
*/
public static function forCurlError(string $errorNum, string $error)
{
Expand Down
1 change: 1 addition & 0 deletions tests/_support/HTTP/Files/CookiesHolder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

17 changes: 15 additions & 2 deletions tests/_support/HTTP/MockCURLRequest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Tests\Support\HTTP;
<?php

namespace Tests\Support\HTTP;

use CodeIgniter\HTTP\CURLRequest;

Expand All @@ -11,8 +13,8 @@
*/
class MockCURLRequest extends CURLRequest
{
public $curl_options;

public $curl_options;
protected $output = '';

//--------------------------------------------------------------------
Expand All @@ -35,5 +37,16 @@ protected function sendRequest(array $curl_options = []): string
}

//--------------------------------------------------------------------
// for testing purposes only
public function getBaseURI()
{
return $this->baseURI;
}

// for testing purposes only
public function getDelay()
{
return $this->delay;
}

}
Loading

0 comments on commit 38a0905

Please sign in to comment.