Skip to content

Commit

Permalink
replace E_USER_DEPRECATED with deprecationWarning()
Browse files Browse the repository at this point in the history
replace E_USER_DEPRECATED with deprecationWarning()
+ use deprecated() helper in test
  • Loading branch information
saeideng committed Oct 29, 2017
1 parent 6c969fc commit 0e838ba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
5 changes: 2 additions & 3 deletions src/Http/Client/FormData.php
Expand Up @@ -102,10 +102,9 @@ public function add($name, $value = null)
} elseif (is_resource($value)) {
$this->addFile($name, $value);
} elseif (is_string($value) && strlen($value) && $value[0] === '@') {
trigger_error(
deprecationWarning(
'Using the @ syntax for file uploads is not safe and is deprecated. ' .
'Instead you should use file handles.',
E_USER_DEPRECATED
'Instead you should use file handles.'
);
$this->addFile($name, $value);
} elseif ($name instanceof FormDataPart && $value === null) {
Expand Down
61 changes: 30 additions & 31 deletions tests/TestCase/Http/Client/FormDataTest.php
Expand Up @@ -121,41 +121,40 @@ public function testAddArray()
/**
* Test adding a part with a file in it.
*
* @group deprecated
* @return void
*/
public function testAddArrayWithFile()
{
$errorLevel = error_reporting();
error_reporting($errorLevel & ~E_USER_DEPRECATED);

$file = CORE_PATH . 'VERSION.txt';
$contents = file_get_contents($file);

$data = new FormData();
$data->add('Article', [
'title' => 'first post',
'thumbnail' => '@' . $file
]);
$boundary = $data->boundary();
$result = (string)$data;

$expected = [
'--' . $boundary,
'Content-Disposition: form-data; name="Article[title]"',
'',
'first post',
'--' . $boundary,
'Content-Disposition: form-data; name="Article[thumbnail]"; filename="VERSION.txt"',
'Content-Type: text/plain; charset=us-ascii',
'',
$contents,
'--' . $boundary . '--',
'',
'',
];
$this->assertEquals(implode("\r\n", $expected), $result);

error_reporting($errorLevel);
$this->deprecated(function () {

$file = CORE_PATH . 'VERSION.txt';
$contents = file_get_contents($file);

$data = new FormData();
$data->add('Article', [
'title' => 'first post',
'thumbnail' => '@' . $file
]);
$boundary = $data->boundary();
$result = (string)$data;

$expected = [
'--' . $boundary,
'Content-Disposition: form-data; name="Article[title]"',
'',
'first post',
'--' . $boundary,
'Content-Disposition: form-data; name="Article[thumbnail]"; filename="VERSION.txt"',
'Content-Type: text/plain; charset=us-ascii',
'',
$contents,
'--' . $boundary . '--',
'',
'',
];
$this->assertEquals(implode("\r\n", $expected), $result);
});
}

/**
Expand Down

0 comments on commit 0e838ba

Please sign in to comment.