Browse Source

replace E_USER_DEPRECATED with deprecationWarning()

replace E_USER_DEPRECATED with deprecationWarning()
+ use deprecated() helper in test
saeid 8 years ago
parent
commit
0e838ba8f3
2 changed files with 32 additions and 34 deletions
  1. 2 3
      src/Http/Client/FormData.php
  2. 30 31
      tests/TestCase/Http/Client/FormDataTest.php

+ 2 - 3
src/Http/Client/FormData.php

@@ -102,10 +102,9 @@ class FormData implements Countable
         } 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) {

+ 30 - 31
tests/TestCase/Http/Client/FormDataTest.php

@@ -121,41 +121,40 @@ class FormDataTest extends TestCase
     /**
      * 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);
+        });
     }
 
     /**