Skip to content

Commit c0a8005

Browse files
committed
test: refactor: separate arrange, act, assert code
1 parent 3a7722c commit c0a8005

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

tests/system/HTTP/Files/FileMovingTest.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ protected function tearDown(): void
5555
public function testMove()
5656
{
5757
$finalFilename = 'fileA';
58-
59-
$_FILES = [
58+
$_FILES = [
6059
'userfile1' => [
6160
'name' => $finalFilename . '.txt',
6261
'type' => 'text/plain',
@@ -79,7 +78,6 @@ public function testMove()
7978
$this->assertTrue($collection->hasFile('userfile2'));
8079

8180
$destination = $this->destination;
82-
8381
// Create the destination if not exists
8482
if (! is_dir($destination)) {
8583
mkdir($destination, 0777, true);
@@ -97,8 +95,7 @@ public function testMove()
9795
public function testMoveOverwriting()
9896
{
9997
$finalFilename = 'file_with_delimiters_underscore';
100-
101-
$_FILES = [
98+
$_FILES = [
10299
'userfile1' => [
103100
'name' => $finalFilename . '.txt',
104101
'type' => 'text/plain',
@@ -129,7 +126,6 @@ public function testMoveOverwriting()
129126
$this->assertTrue($collection->hasFile('userfile3'));
130127

131128
$destination = $this->destination;
132-
133129
// Create the destination if not exists
134130
if (! is_dir($destination)) {
135131
mkdir($destination, 0777, true);
@@ -149,8 +145,7 @@ public function testMoveOverwriting()
149145
public function testMoved()
150146
{
151147
$finalFilename = 'fileA';
152-
153-
$_FILES = [
148+
$_FILES = [
154149
'userfile1' => [
155150
'name' => $finalFilename . '.txt',
156151
'type' => 'text/plain',
@@ -165,7 +160,6 @@ public function testMoved()
165160
$this->assertTrue($collection->hasFile('userfile1'));
166161

167162
$destination = $this->destination;
168-
169163
// Create the destination if not exists
170164
if (! is_dir($destination)) {
171165
mkdir($destination, 0777, true);
@@ -175,15 +169,16 @@ public function testMoved()
175169

176170
$this->assertInstanceOf(UploadedFile::class, $file);
177171
$this->assertFalse($file->hasMoved());
172+
178173
$file->move($destination, $file->getName(), false);
174+
179175
$this->assertTrue($file->hasMoved());
180176
}
181177

182178
public function testStore()
183179
{
184180
$finalFilename = 'fileA';
185-
186-
$_FILES = [
181+
$_FILES = [
187182
'userfile1' => [
188183
'name' => $finalFilename . '.txt',
189184
'type' => 'text/plain',
@@ -198,7 +193,6 @@ public function testStore()
198193
$this->assertTrue($collection->hasFile('userfile1'));
199194

200195
$destination = $this->destination;
201-
202196
// Create the destination if not exists
203197
if (! is_dir($destination)) {
204198
mkdir($destination, 0777, true);
@@ -207,15 +201,16 @@ public function testStore()
207201
$file = $collection->getFile('userfile1');
208202

209203
$this->assertInstanceOf(UploadedFile::class, $file);
204+
210205
$path = $file->store($destination, $file->getName());
206+
211207
$this->assertSame($destination . '/fileA.txt', $path);
212208
}
213209

214210
public function testAlreadyMoved()
215211
{
216212
$finalFilename = 'fileA';
217-
218-
$_FILES = [
213+
$_FILES = [
219214
'userfile1' => [
220215
'name' => $finalFilename . '.txt',
221216
'type' => 'text/plain',
@@ -230,7 +225,6 @@ public function testAlreadyMoved()
230225
$this->assertTrue($collection->hasFile('userfile1'));
231226

232227
$destination = $this->destination;
233-
234228
// Create the destination if not exists
235229
if (! is_dir($destination)) {
236230
mkdir($destination, 0777, true);
@@ -257,11 +251,11 @@ public function testInvalidFile()
257251
];
258252

259253
$destination = $this->destination;
260-
261-
$collection = new FileCollection();
262-
$file = $collection->getFile('userfile');
254+
$collection = new FileCollection();
263255

264256
$this->expectException(HTTPException::class);
257+
258+
$file = $collection->getFile('userfile');
265259
$file->move($destination, $file->getName(), false);
266260
}
267261

@@ -278,16 +272,16 @@ public function testFailedMoveBecauseOfWarning()
278272
];
279273

280274
$destination = $this->destination;
281-
282275
// Create the destination and make it read only
283276
if (! is_dir($destination)) {
284277
mkdir($destination, 0400, true);
285278
}
286279

287280
$collection = new FileCollection();
288-
$file = $collection->getFile('userfile');
289281

290282
$this->expectException(HTTPException::class);
283+
284+
$file = $collection->getFile('userfile');
291285
$file->move($destination, $file->getName(), false);
292286
}
293287

@@ -308,20 +302,17 @@ public function testFailedMoveBecauseOfFalseReturned()
308302
$this->assertTrue($collection->hasFile('userfile1'));
309303

310304
$destination = $this->destination;
311-
312305
// Create the destination if not exists
313306
if (! is_dir($destination)) {
314307
mkdir($destination, 0777, true);
315308
}
316-
317-
$file = $collection->getFile('userfile1');
318-
319309
// Set the mock's return value to false
320310
move_uploaded_file('', '', false);
321311

322312
$this->expectException(HTTPException::class);
323313
$this->expectExceptionMessage('move_uploaded_file() returned false');
324314

315+
$file = $collection->getFile('userfile1');
325316
$file->move($destination, $file->getName(), false);
326317
}
327318
}

0 commit comments

Comments
 (0)