-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format rule for required_without (#4196)
* test: 🧪 add failing tests for row validator * format rule for required_without * fix: phpunit error when run in php7.4 * fix: style ci * fix: style ci --------- Co-authored-by: Younes el Barnoussi <[email protected]>
- Loading branch information
1 parent
203d0cd
commit fccd234
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Maatwebsite\Excel\Tests\Validators; | ||
|
||
use Illuminate\Contracts\Validation\Factory; | ||
use Maatwebsite\Excel\Tests\TestCase; | ||
use Maatwebsite\Excel\Validators\RowValidator; | ||
|
||
class RowValidatorTest extends TestCase | ||
{ | ||
/** | ||
* The RowValidator instance. | ||
*/ | ||
protected $validator; | ||
|
||
/** | ||
* Set up the test. | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->validator = new RowValidator(app(Factory::class)); | ||
} | ||
|
||
public function test_format_rule_with_array_input() | ||
{ | ||
$rules = ['rule1', 'rule2']; | ||
|
||
$result = $this->callPrivateMethod('formatRule', [$rules]); | ||
|
||
$this->assertEquals($rules, $result); | ||
} | ||
|
||
public function test_format_rule_with_object_input() | ||
{ | ||
$rule = new \stdClass(); | ||
|
||
$result = $this->callPrivateMethod('formatRule', [$rule]); | ||
|
||
$this->assertEquals($rule, $result); | ||
} | ||
|
||
public function test_format_rule_with_callable_input() | ||
{ | ||
$rule = function () { | ||
return 'callable'; | ||
}; | ||
|
||
$result = $this->callPrivateMethod('formatRule', [$rule]); | ||
|
||
$this->assertEquals($rule, $result); | ||
} | ||
|
||
public function test_format_rule_with_required_without_all() | ||
{ | ||
$rule = 'required_without_all:first_name,last_name'; | ||
|
||
$result = $this->callPrivateMethod('formatRule', [$rule]); | ||
|
||
$this->assertEquals('required_without_all:*.first_name,*.last_name', $result); | ||
} | ||
|
||
public function test_format_rule_with_required_without() | ||
{ | ||
$rule = 'required_without:first_name'; | ||
|
||
$result = $this->callPrivateMethod('formatRule', [$rule]); | ||
|
||
$this->assertEquals('required_without:*.first_name', $result); | ||
} | ||
|
||
public function test_format_rule_with_string_input_not_matching_pattern() | ||
{ | ||
$rule = 'rule'; | ||
|
||
$result = $this->callPrivateMethod('formatRule', [$rule]); | ||
|
||
$this->assertEquals($rule, $result); | ||
} | ||
|
||
/** | ||
* Call a private function. | ||
* | ||
* @param string $name | ||
* @param array $args | ||
* @return mixed | ||
*/ | ||
public function callPrivateMethod(string $name, array $args) | ||
{ | ||
$method = new \ReflectionMethod(RowValidator::class, $name); | ||
$method->setAccessible(true); | ||
|
||
return $method->invokeArgs($this->validator, $args); | ||
} | ||
} |