Clean up namespacing

This commit is contained in:
Zach Borboa
2017-04-30 15:58:33 -07:00
parent b754ebf065
commit 2264362338
6 changed files with 86 additions and 78 deletions
-1
View File
@@ -3,7 +3,6 @@ require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
$curl = new Curl();
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$curl->setOpt(CURLOPT_NOBODY, true);
-1
View File
@@ -643,7 +643,6 @@ class MultiCurl
}
do {
// Wait for activity on any curl_multi connection when curl_multi_select (libcurl) fails to correctly block.
// https://bugs.php.net/bug.php?id=63411
if (curl_multi_select($this->multiCurl) === -1) {
+4 -4
View File
@@ -33,7 +33,7 @@ class Test
* previously forced method might be inherited.
* Especially, POSTs must be configured to not perform post-redirect-get.
*/
private function chained_request($request_method)
private function chainedRequest($request_method)
{
if ($request_method === 'POST') {
$this->server('request_method', $request_method, array(), true);
@@ -43,10 +43,10 @@ class Test
\PHPUnit\Framework\Assert::assertEquals($request_method, $this->curl->responseHeaders['X-REQUEST-METHOD']);
}
public function chain_requests($first, $second)
public function chainRequests($first, $second)
{
$this->chained_request($first);
$this->chained_request($second);
$this->chainedRequest($first);
$this->chainedRequest($second);
}
}
+72 -70
View File
@@ -1,5 +1,7 @@
<?php
namespace CurlTest;
use \Curl\Curl;
use \Curl\CaseInsensitiveArray;
use \Helper\Test;
@@ -283,7 +285,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
'Connection: keep-alive' . "\r\n" .
"\r\n";
$reflector = new ReflectionClass('\Curl\Curl');
$reflector = new \ReflectionClass('\Curl\Curl');
$reflection_method = $reflector->getMethod('parseResponseHeaders');
$reflection_method->setAccessible(true);
@@ -366,17 +368,17 @@ class CurlTest extends \PHPUnit\Framework\TestCase
{
$tests = array();
$file_path_1 = Helper\get_png();
$file_path_1 = \Helper\get_png();
$tests[] = array(
'file_path' => $file_path_1,
'post_data_image' => '@' . $file_path_1,
);
if (class_exists('CURLFile')) {
$file_path_2 = Helper\get_png();
$file_path_2 = \Helper\get_png();
$tests[] = array(
'file_path' => $file_path_2,
'post_data_image' => new CURLFile($file_path_2),
'post_data_image' => new \CURLFile($file_path_2),
);
}
@@ -426,7 +428,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testPostFilePathUpload()
{
$file_path = Helper\get_png();
$file_path = \Helper\get_png();
$test = new Test();
$this->assertEquals('image/png', $test->server('post_file_path_upload', 'POST', array(
@@ -441,12 +443,12 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testPostCurlFileUpload()
{
if (class_exists('CURLFile')) {
$file_path = Helper\get_png();
$file_path = \Helper\get_png();
$test = new Test();
$this->assertEquals('image/png', $test->server('post_file_path_upload', 'POST', array(
'key' => 'image',
'image' => new CURLFile($file_path),
'image' => new \CURLFile($file_path),
)));
unlink($file_path);
@@ -529,8 +531,8 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testPutFileHandle()
{
$png = Helper\create_png();
$tmp_file = Helper\create_tmp_file($png);
$png = \Helper\create_png();
$tmp_file = \Helper\create_tmp_file($png);
$test = new Test();
$test->curl->setHeader('X-DEBUG-TEST', 'put_file_handle');
@@ -610,8 +612,8 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testDownload()
{
// Create and upload a file.
$upload_file_path = Helper\get_png();
$uploaded_file_path = Helper\upload_file_to_server($upload_file_path);
$upload_file_path = \Helper\get_png();
$uploaded_file_path = \Helper\upload_file_to_server($upload_file_path);
// Download the file.
$downloaded_file_path = tempnam('/tmp', 'php-curl-class.');
@@ -632,7 +634,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$this->assertFalse(is_bool($download_test->curl->rawResponse));
// Remove server file.
Helper\remove_file_from_server($uploaded_file_path);
\Helper\remove_file_from_server($uploaded_file_path);
unlink($upload_file_path);
unlink($downloaded_file_path);
@@ -643,8 +645,8 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testDownloadCallback()
{
// Create and upload a file.
$upload_file_path = Helper\get_png();
$uploaded_file_path = Helper\upload_file_to_server($upload_file_path);
$upload_file_path = \Helper\get_png();
$uploaded_file_path = \Helper\upload_file_to_server($upload_file_path);
// Download the file.
$callback_called = false;
@@ -665,7 +667,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($callback_called);
// Remove server file.
Helper\remove_file_from_server($uploaded_file_path);
\Helper\remove_file_from_server($uploaded_file_path);
unlink($upload_file_path);
$this->assertFalse(file_exists($upload_file_path));
@@ -674,8 +676,8 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testDownloadRange()
{
// Create and upload a file.
$filename = Helper\get_png();
$uploaded_file_path = Helper\upload_file_to_server($filename);
$filename = \Helper\get_png();
$uploaded_file_path = \Helper\upload_file_to_server($filename);
$filesize = filesize($filename);
@@ -712,7 +714,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
) as $length) {
$source = Test::TEST_URL;
$destination = Helper\get_tmp_file_path();
$destination = \Helper\get_tmp_file_path();
// Start with no file.
if ($length === false) {
@@ -774,7 +776,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
}
// Remove server file.
Helper\remove_file_from_server($uploaded_file_path);
\Helper\remove_file_from_server($uploaded_file_path);
unlink($filename);
$this->assertFalse(file_exists($filename));
@@ -1123,7 +1125,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$curl = new Curl();
$curl->setHeader('Content-Type', $content_type);
$reflector = new ReflectionClass('\Curl\Curl');
$reflector = new \ReflectionClass('\Curl\Curl');
$property = $reflector->getProperty('headers');
$property->setAccessible(true);
$headers = $property->getValue($curl);
@@ -1248,7 +1250,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testPostFileFormDataContentType()
{
$file_path = Helper\get_png();
$file_path = \Helper\get_png();
$test = new Test();
$test->server('server', 'POST', array(
@@ -1268,11 +1270,11 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$this->markTestSkipped();
}
$file_path = Helper\get_png();
$file_path = \Helper\get_png();
$test = new Test();
$test->server('server', 'POST', array(
'image' => new CURLFile($file_path),
'image' => new \CURLFile($file_path),
));
$this->assertEquals('100-continue', $test->curl->requestHeaders['Expect']);
preg_match('/^multipart\/form-data; boundary=/', $test->curl->requestHeaders['Content-Type'], $content_type);
@@ -1481,7 +1483,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
'text/x-json',
);
$class = new ReflectionClass('\Curl\Curl');
$class = new \ReflectionClass('\Curl\Curl');
$property = $class->getProperty('jsonPattern');
$property->setAccessible(true);
$json_pattern = $property->getValue(new Curl);
@@ -2595,7 +2597,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$this->assertInstanceOf('SimpleXMLElement', $test->curl->response);
$doc = new DOMDocument();
$doc = new \DOMDocument();
$doc->formatOutput = true;
$rss = $doc->appendChild($doc->createElement('rss'));
$rss->setAttribute('version', '2.0');
@@ -2620,7 +2622,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
{
$response = "\r\n\r\n";
$reflector = new ReflectionClass('\Curl\Curl');
$reflector = new \ReflectionClass('\Curl\Curl');
$reflection_method = $reflector->getMethod('parseResponseHeaders');
$reflection_method->setAccessible(true);
@@ -2817,78 +2819,78 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testRequestMethodSuccessiveGetRequests()
{
$test = new Test();
$test->chain_requests('GET', 'POST');
$test->chain_requests('GET', 'PUT');
$test->chain_requests('GET', 'PATCH');
$test->chain_requests('GET', 'DELETE');
$test->chain_requests('GET', 'HEAD');
$test->chain_requests('GET', 'OPTIONS');
$test->chainRequests('GET', 'POST');
$test->chainRequests('GET', 'PUT');
$test->chainRequests('GET', 'PATCH');
$test->chainRequests('GET', 'DELETE');
$test->chainRequests('GET', 'HEAD');
$test->chainRequests('GET', 'OPTIONS');
}
public function testRequestMethodSuccessivePostRequests()
{
$test = new Test();
$test->chain_requests('POST', 'GET');
$test->chain_requests('POST', 'PUT');
$test->chain_requests('POST', 'PATCH');
$test->chain_requests('POST', 'DELETE');
$test->chain_requests('POST', 'HEAD');
$test->chain_requests('POST', 'OPTIONS');
$test->chainRequests('POST', 'GET');
$test->chainRequests('POST', 'PUT');
$test->chainRequests('POST', 'PATCH');
$test->chainRequests('POST', 'DELETE');
$test->chainRequests('POST', 'HEAD');
$test->chainRequests('POST', 'OPTIONS');
}
public function testRequestMethodSuccessivePutRequests()
{
$test = new Test();
$test->chain_requests('PUT', 'GET');
$test->chain_requests('PUT', 'POST');
$test->chain_requests('PUT', 'PATCH');
$test->chain_requests('PUT', 'DELETE');
$test->chain_requests('PUT', 'HEAD');
$test->chain_requests('PUT', 'OPTIONS');
$test->chainRequests('PUT', 'GET');
$test->chainRequests('PUT', 'POST');
$test->chainRequests('PUT', 'PATCH');
$test->chainRequests('PUT', 'DELETE');
$test->chainRequests('PUT', 'HEAD');
$test->chainRequests('PUT', 'OPTIONS');
}
public function testRequestMethodSuccessivePatchRequests()
{
$test = new Test();
$test->chain_requests('PATCH', 'GET');
$test->chain_requests('PATCH', 'POST');
$test->chain_requests('PATCH', 'PUT');
$test->chain_requests('PATCH', 'DELETE');
$test->chain_requests('PATCH', 'HEAD');
$test->chain_requests('PATCH', 'OPTIONS');
$test->chainRequests('PATCH', 'GET');
$test->chainRequests('PATCH', 'POST');
$test->chainRequests('PATCH', 'PUT');
$test->chainRequests('PATCH', 'DELETE');
$test->chainRequests('PATCH', 'HEAD');
$test->chainRequests('PATCH', 'OPTIONS');
}
public function testRequestMethodSuccessiveDeleteRequests()
{
$test = new Test();
$test->chain_requests('DELETE', 'GET');
$test->chain_requests('DELETE', 'POST');
$test->chain_requests('DELETE', 'PUT');
$test->chain_requests('DELETE', 'PATCH');
$test->chain_requests('DELETE', 'HEAD');
$test->chain_requests('DELETE', 'OPTIONS');
$test->chainRequests('DELETE', 'GET');
$test->chainRequests('DELETE', 'POST');
$test->chainRequests('DELETE', 'PUT');
$test->chainRequests('DELETE', 'PATCH');
$test->chainRequests('DELETE', 'HEAD');
$test->chainRequests('DELETE', 'OPTIONS');
}
public function testRequestMethodSuccessiveHeadRequests()
{
$test = new Test();
$test->chain_requests('HEAD', 'GET');
$test->chain_requests('HEAD', 'POST');
$test->chain_requests('HEAD', 'PUT');
$test->chain_requests('HEAD', 'PATCH');
$test->chain_requests('HEAD', 'DELETE');
$test->chain_requests('HEAD', 'OPTIONS');
$test->chainRequests('HEAD', 'GET');
$test->chainRequests('HEAD', 'POST');
$test->chainRequests('HEAD', 'PUT');
$test->chainRequests('HEAD', 'PATCH');
$test->chainRequests('HEAD', 'DELETE');
$test->chainRequests('HEAD', 'OPTIONS');
}
public function testRequestMethodSuccessiveOptionsRequests()
{
$test = new Test();
$test->chain_requests('OPTIONS', 'GET');
$test->chain_requests('OPTIONS', 'POST');
$test->chain_requests('OPTIONS', 'PUT');
$test->chain_requests('OPTIONS', 'PATCH');
$test->chain_requests('OPTIONS', 'DELETE');
$test->chain_requests('OPTIONS', 'HEAD');
$test->chainRequests('OPTIONS', 'GET');
$test->chainRequests('OPTIONS', 'POST');
$test->chainRequests('OPTIONS', 'PUT');
$test->chainRequests('OPTIONS', 'PATCH');
$test->chainRequests('OPTIONS', 'DELETE');
$test->chainRequests('OPTIONS', 'HEAD');
}
public function testMemoryLeak()
@@ -3121,7 +3123,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
);
foreach ($tests as $test) {
$curl_1 = new Curl();
$reflector = new ReflectionObject($curl_1);
$reflector = new \ReflectionObject($curl_1);
$method = $reflector->getMethod('buildURL');
$method->setAccessible(true);
$actual_url = $method->invoke($curl_1, $test['args']['url'], $test['args']['mixed_data']);
@@ -3149,7 +3151,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$curl = new Curl();
$reflector = new ReflectionObject($curl);
$reflector = new \ReflectionObject($curl);
$method = $reflector->getMethod('buildURL');
$method->setAccessible(true);
+5 -2
View File
@@ -1,5 +1,8 @@
<?php
namespace CurlTest;
use \Curl\Curl;
use \Curl\MultiCurl;
use \Helper\Test;
@@ -2233,7 +2236,7 @@ class MultiCurlTest extends \PHPUnit\Framework\TestCase
public function testDownloadCallback()
{
// Upload a file.
$upload_file_path = Helper\get_png();
$upload_file_path = \Helper\get_png();
$upload_test = new Test();
$upload_test->server('upload_response', 'POST', array(
'image' => '@' . $upload_file_path,
@@ -2547,7 +2550,7 @@ class MultiCurlTest extends \PHPUnit\Framework\TestCase
public function testAddCurl()
{
$curl = new Curl\Curl();
$curl = new Curl();
$curl->setUrl(Test::TEST_URL);
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$curl->setOpt(CURLOPT_HTTPGET, true);
+5
View File
@@ -7,4 +7,9 @@
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.UseOneParamPerLine" />
</rule>
<!-- Disable "No PHP code was found in this file" for symlinks. -->
<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>
</ruleset>