Skip to content

Commit 80af0ea

Browse files
committed
Add a test to make sure is_uploaded_file works
1 parent 27e5301 commit 80af0ea

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/Rules/UploadedFileTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testValidUploadedFile()
1717
'type' => 'text/plain',
1818
'size' => filesize(__FILE__),
1919
'tmp_name' => __FILE__,
20-
'error' => 0
20+
'error' => UPLOAD_ERR_OK
2121
];
2222

2323
$uploadedFileRule = $this->getMockBuilder(UploadedFile::class)
@@ -31,10 +31,24 @@ public function testValidUploadedFile()
3131
$this->assertTrue($uploadedFileRule->check($file));
3232
}
3333

34+
/**
35+
* Make sure we can't just passing array like valid $_FILES['key']
36+
*/
37+
public function testValidateWithoutMockShouldBeInvalid()
38+
{
39+
$this->assertFalse($this->rule->check([
40+
'name' => pathinfo(__FILE__, PATHINFO_BASENAME),
41+
'type' => 'text/plain',
42+
'size' => filesize(__FILE__),
43+
'tmp_name' => __FILE__,
44+
'error' => UPLOAD_ERR_OK
45+
]));
46+
}
47+
3448
/**
3549
* Missing UPLOAD_ERR_NO_FILE should be valid because it is job for required rule
3650
*/
37-
public function testNoUploadedFileShouldBeValid()
51+
public function testEmptyUploadedFileShouldBeValid()
3852
{
3953
$this->assertTrue($this->rule->check([
4054
'name' => '',

0 commit comments

Comments
 (0)