-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
1 deletion.
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
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,54 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Validation; | ||
|
||
use Illuminate\Translation\ArrayLoader; | ||
use Illuminate\Translation\Translator; | ||
use Illuminate\Validation\ValidationException; | ||
use Illuminate\Validation\Validator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ValidationExceptionTest extends TestCase | ||
{ | ||
public function testExceptionSummarizesZeroErrors() | ||
{ | ||
$exception = $this->getException([], []); | ||
|
||
$this->assertEquals('The given data was invalid.', $exception->getMessage()); | ||
} | ||
|
||
|
||
public function testExceptionSummarizesOneError() | ||
{ | ||
$exception = $this->getException([], ['foo' => 'required']); | ||
|
||
$this->assertEquals('validation.required', $exception->getMessage()); | ||
} | ||
|
||
|
||
public function testExceptionSummarizesTwoErrors() | ||
{ | ||
$exception = $this->getException([], [ 'foo' => 'required', 'bar' => 'required' ]); | ||
|
||
$this->assertEquals('validation.required (and 1 more error)', $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionSummarizesThreeOrMoreErrors() | ||
{ | ||
$exception = $this->getException([], [ | ||
'foo' => 'required', | ||
'bar' => 'required', | ||
'baz' => 'required', | ||
]); | ||
|
||
$this->assertEquals('validation.required (and 2 more errors)', $exception->getMessage()); | ||
} | ||
|
||
protected function getException($data = [], $rules = []) | ||
{ | ||
$translator = new Translator(new ArrayLoader, 'en'); | ||
$validator = new Validator($translator, $data, $rules); | ||
|
||
return new ValidationException($validator); | ||
} | ||
} |