Forráskód Böngészése

Merge pull request #22 from agungsijawir/master

Patch for Issues #21
Xu Ding 7 éve
szülő
commit
5624d5a5a7

+ 1 - 1
src/Network/SimpleResponse.php

@@ -16,7 +16,7 @@ class SimpleResponse implements Response
         } else if (404==$statusCode) {
             return header("HTTP/1.0 404 Not Found");
         }
-        return header("HTTP/1.0 404 Not Found");
+        return header("HTTP/1.0 204 No Content");
     }
 
 }

+ 2 - 2
src/Resumable.php

@@ -162,7 +162,7 @@ class Resumable
         $chunkNumber = $this->resumableParam('chunkNumber');
 
         if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
-            return $this->response->header(404);
+            return $this->response->header(204);
         } else {
             return $this->response->header(200);
         }
@@ -265,7 +265,7 @@ class Resumable
 
     public function tmpChunkFilename($filename, $chunkNumber)
     {
-        return $filename . '.part' . $chunkNumber;
+        return $filename . '.' . str_pad($chunkNumber, 4, 0, STR_PAD_LEFT);
     }
 
     public function createFileFromChunks($chunkFiles, $destFile)

+ 0 - 0
test/files/mock.png.part1 → test/files/mock.png.0001


+ 0 - 0
test/files/mock.png.part2 → test/files/mock.png.0002


+ 0 - 0
test/files/mock.png.part3 → test/files/mock.png.0003


+ 1 - 1
test/src/Network/SimpleRequestTest.php

@@ -76,7 +76,7 @@ class SimpleRequestTest extends \PHPUnit_Framework_TestCase
        $file = array(
            'name'=> 'mock.png',
            'type'=> 'application/octet-stream',
-           'tmp_name'=>  'test/files/mock.png.part3',
+           'tmp_name'=>  'test/files/mock.png.0003',
            'error'=> 0,
            'size'=> 1048576,
        );

+ 2 - 1
test/src/Network/SimpleResponseTest.php

@@ -26,8 +26,9 @@ class SimpleResponseTest extends \PHPUnit_Framework_TestCase
     {
         return array(
             array(404,404),
+            array(204,204),
             array(200,200),
-            array(500,404),
+            array(500,204),
         );
     }
 

+ 12 - 12
test/src/ResumableTest.php

@@ -50,7 +50,7 @@ class ResumbableTest extends \PHPUnit_Framework_TestCase
         $this->request->method('file')
                     ->will($this->returnValue(array(
                             'name'=> 'mock.png',
-                            'tmp_name'=>  'test/files/mock.png.part3',
+                            'tmp_name'=>  'test/files/mock.png.003',
                             'error'=> 0,
                             'size'=> 27000,
                         )));
@@ -142,7 +142,7 @@ class ResumbableTest extends \PHPUnit_Framework_TestCase
         $this->request->method('file')
                 ->willReturn(array(
                     'name'=> 'mock.png',
-                    'tmp_name'=>  'test/files/mock.png.part3',
+                    'tmp_name'=>  'test/files/mock.png.003',
                     'error'=> 0,
                     'size'=> 27000,
                 ));
@@ -154,7 +154,7 @@ class ResumbableTest extends \PHPUnit_Framework_TestCase
         $this->resumbable->handleChunk();
 
         $this->assertFileExists('test/uploads/mock.png');
-        unlink('test/tmp/identifier/mock.png.part3');
+        unlink('test/tmp/identifier/mock.png.003');
         unlink('test/uploads/mock.png');
     }
 
@@ -226,22 +226,22 @@ class ResumbableTest extends \PHPUnit_Framework_TestCase
     {
         $this->resumbable = new Resumable($this->request,$this->response);
         $filename = 'mock-file.png';
-        $chunkNumber = 1;
-        $expected = $filename.'.part'.$chunkNumber;
+        $chunkNumber = str_pad(1, 4, 0, STR_PAD_LEFT);
+        $expected = $filename.'.'.$chunkNumber;
         $this->assertEquals($expected, $this->resumbable->tmpChunkFilename($filename,$chunkNumber));
     }
 
     public function testCreateFileFromChunks()
     {
         $files = array(
-            'test/files/mock.png.part1',
-            'test/files/mock.png.part2',
-            'test/files/mock.png.part3',
+            'test/files/mock.png.0001',
+            'test/files/mock.png.0002',
+            'test/files/mock.png.0003',
         );
         $totalFileSize = array_sum(array(
-            filesize('test/files/mock.png.part1'),
-            filesize('test/files/mock.png.part2'),
-            filesize('test/files/mock.png.part3')
+            filesize('test/files/mock.png.0001'),
+            filesize('test/files/mock.png.0002'),
+            filesize('test/files/mock.png.0003')
         ));
         $destFile = 'test/files/5.png';
 
@@ -256,7 +256,7 @@ class ResumbableTest extends \PHPUnit_Framework_TestCase
     {
         $destFile = 'test/files/4.png';
         $this->resumbable = new Resumable($this->request,$this->response);
-        $this->resumbable->moveUploadedFile('test/files/mock.png.part1', $destFile);
+        $this->resumbable->moveUploadedFile('test/files/mock.png.0001', $destFile);
         $this->assertFileExists($destFile);
         unlink($destFile);
     }

+ 0 - 0
test/tmp/identifier/mock.png.part1 → test/tmp/identifier/mock.png.0001


+ 0 - 0
test/tmp/identifier/mock.png.part2 → test/tmp/identifier/mock.png.0002