Skip to content

Commit 89c56ba

Browse files
author
Recca Tsai
committed
const
1 parent 9ff5551 commit 89c56ba

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/Uploaders/Base.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
abstract class Base implements Uploader
1212
{
13+
/**
14+
* TMPFILE_EXTENSION.
15+
*
16+
* @var string
17+
*/
18+
const TMPFILE_EXTENSION = '.part';
19+
1320
/**
1421
* $request.
1522
*
@@ -89,13 +96,14 @@ protected function tmpfile($originalName)
8996
protected function receiveChunkedFile($originalName, $input, $start, $mimeType, $isCompleted = false, $headers = [])
9097
{
9198
$tmpfile = $this->tmpfile($originalName);
92-
$this->filesystem->appendStream($tmpfile.'.part', $input, $start);
99+
$extension = static::TMPFILE_EXTENSION;
100+
$this->filesystem->appendStream($tmpfile.$extension, $input, $start);
93101

94102
if ($isCompleted === false) {
95103
throw new ChunkedResponseException($headers);
96104
}
97105

98-
$this->filesystem->move($tmpfile.'.part', $tmpfile);
106+
$this->filesystem->move($tmpfile.$extension, $tmpfile);
99107
$size = $this->filesystem->size($tmpfile);
100108

101109
return $this->filesystem->createUploadedFile($tmpfile, $originalName, $mimeType, $size);

tests/Uploader/FileAPITest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function test_upload_chunk_file_throw_chunk_response()
6767
$extension = pathinfo($originalName, PATHINFO_EXTENSION);
6868
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
6969
$tmpfile = $path.'/'.md5($originalName.$token).'.'.$extension;
70+
$tmpfileExtension = FileAPI::TMPFILE_EXTENSION;
7071

7172
$start = 5242880;
7273
$end = 5767167;
@@ -113,7 +114,7 @@ public function test_upload_chunk_file_throw_chunk_response()
113114
$request->shouldHaveReceived('header')->with('content-type')->once();
114115
$filesystem->shouldHaveReceived('extension')->with($originalName)->once();
115116
$request->shouldHaveReceived('get')->with('token')->once();
116-
$filesystem->shouldHaveReceived('appendStream')->with($tmpfile.'.part', $input, $start)->once();
117+
$filesystem->shouldHaveReceived('appendStream')->with($tmpfile.$tmpfileExtension, $input, $start)->once();
117118
}
118119

119120
public function test_upload_chunk_file()
@@ -136,6 +137,7 @@ public function test_upload_chunk_file()
136137
$extension = pathinfo($originalName, PATHINFO_EXTENSION);
137138
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
138139
$tmpfile = $path.'/'.md5($originalName.$token).'.'.$extension;
140+
$tmpfileExtension = FileAPI::TMPFILE_EXTENSION;
139141

140142
$start = 5242880;
141143
$end = 7845180;
@@ -160,7 +162,7 @@ public function test_upload_chunk_file()
160162
$filesystem
161163
->shouldReceive('extension')->with($originalName)->andReturn($extension)
162164
->shouldReceive('mimeType')->with($originalName)->andReturn($mimeType)
163-
->shouldReceive('move')->with($tmpfile.'.part', $tmpfile)
165+
->shouldReceive('move')->with($tmpfile.$tmpfileExtension, $tmpfile)
164166
->shouldReceive('size')->with($tmpfile)->andReturn($total);
165167

166168
$uploader = new FileAPI($request, $filesystem, $path);
@@ -179,8 +181,8 @@ public function test_upload_chunk_file()
179181
$filesystem->shouldHaveReceived('extension')->with($originalName)->once();
180182
$filesystem->shouldHaveReceived('mimeType')->with($originalName)->once();
181183
$request->shouldHaveReceived('get')->with('token')->once();
182-
$filesystem->shouldHaveReceived('appendStream')->with($tmpfile.'.part', $input, $start)->once();
183-
$filesystem->shouldHaveReceived('move')->with($tmpfile.'.part', $tmpfile)->once();
184+
$filesystem->shouldHaveReceived('appendStream')->with($tmpfile.$tmpfileExtension, $input, $start)->once();
185+
$filesystem->shouldHaveReceived('move')->with($tmpfile.$tmpfileExtension, $tmpfile)->once();
184186
$filesystem->shouldHaveReceived('size')->once();
185187
$filesystem->shouldHaveReceived('createUploadedFile')->with($tmpfile, $originalName, $mimeType, $size)->once();
186188
}

tests/Uploader/PluploadTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function test_upload_chunk_file()
118118
$extension = pathinfo($originalName, PATHINFO_EXTENSION);
119119
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
120120
$tmpfile = $path.'/'.md5($originalName.$token).'.'.$extension;
121+
$tmpfileExtension = Plupload::TMPFILE_EXTENSION;
121122

122123
$chunks = 8;
123124
$chunk = 7;
@@ -147,7 +148,7 @@ public function test_upload_chunk_file()
147148

148149
$filesystem
149150
->shouldReceive('extension')->with($originalName)->andReturn($extension)
150-
->shouldReceive('move')->with($tmpfile.'.part', $tmpfile)
151+
->shouldReceive('move')->with($tmpfile.$tmpfileExtension, $tmpfile)
151152
->shouldReceive('size')->with($tmpfile)->andReturn($size);
152153

153154
$uploader = new Plupload($request, $filesystem, $path);
@@ -167,7 +168,7 @@ public function test_upload_chunk_file()
167168
$request->shouldHaveReceived('get')->with('name')->once();
168169
$request->shouldHaveReceived('get')->with('token')->once();
169170
$filesystem->shouldHaveReceived('extension')->with($originalName)->once();
170-
$filesystem->shouldHaveReceived('appendStream')->with($tmpfile.'.part', $input, $start)->once();
171+
$filesystem->shouldHaveReceived('appendStream')->with($tmpfile.$tmpfileExtension, $input, $start)->once();
171172
$filesystem->shouldHaveReceived('createUploadedFile')->with($tmpfile, $originalName, $mimeType, $size)->once();
172173
}
173174

0 commit comments

Comments
 (0)