-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thanks to @Validation
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
|
||
namespace DG\Validation\Rules; | ||
|
||
|
||
use DG\Validation\Rule; | ||
|
||
class Nullable extends Rule | ||
{ | ||
/** | ||
* Check the $value is valid | ||
* | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function check($value): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1494,4 +1494,44 @@ public function testRuleUploadedFileInvalidMessages() | |
$expectedMessage = "The Sample file type must be 'jpeg', 'png', atau 'bmp'"; | ||
$this->assertEquals($validation->errors()->first('sample'), $expectedMessage); | ||
} | ||
|
||
public function testIgnoreNextRulesWithNullableRule() | ||
{ | ||
$emptyFile = [ | ||
'name' => '', | ||
'type' => '', | ||
'size' => '', | ||
'tmp_name' => '', | ||
'error' => UPLOAD_ERR_NO_FILE | ||
]; | ||
|
||
$invalidFile = [ | ||
'name' => 'sample.txt', | ||
'type' => 'plain/text', | ||
'tmp_name' => __FILE__, | ||
'size' => 1000, | ||
'error' => UPLOAD_ERR_OK, | ||
]; | ||
|
||
$data1 = [ | ||
'file' => $emptyFile, | ||
'name' => '' | ||
]; | ||
|
||
$data2 = [ | ||
'file' => $invalidFile, | ||
'name' => '[email protected]' | ||
]; | ||
|
||
$rules = [ | ||
'file' => 'nullable|uploaded_file:0,500K,png,jpeg', | ||
'name' => 'nullable|email' | ||
]; | ||
|
||
$validation1 = $this->validator->validate($data1, $rules); | ||
$validation2 = $this->validator->validate($data2, $rules); | ||
|
||
$this->assertTrue($validation1->passes()); | ||
$this->assertFalse($validation2->passes()); | ||
} | ||
} |