-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add PSR-7 support for FileValidator #15421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraints\File; | ||
use Symfony\Component\Validator\Constraints\FileValidator; | ||
|
||
class FileValidatorPsr7Test extends AbstractConstraintValidatorTest | ||
{ | ||
protected function createValidator() | ||
{ | ||
return new FileValidator(); | ||
} | ||
|
||
public function testValidUploadedFile() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not putting them in the FileValidatorTest class directly ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is not one FileValidatorTest, there are 2: |
||
{ | ||
$file = $this->getMock('Psr\Http\Message\UploadedFileInterface'); | ||
$file->expects($this->any())->method('getError')->willReturn(UPLOAD_ERR_OK); | ||
|
||
$this->validator->validate($file, new File()); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function testInvalidUploadedFile() | ||
{ | ||
$file = $this->getMock('Psr\Http\Message\UploadedFileInterface'); | ||
$file->expects($this->any())->method('getError')->willReturn(UPLOAD_ERR_FORM_SIZE); | ||
|
||
$constraint = new File(array( | ||
'uploadFormSizeErrorMessage' => 'myMessage', | ||
)); | ||
|
||
$this->validator->validate($file, $constraint); | ||
|
||
$this->buildViolation('myMessage') | ||
->setCode(UPLOAD_ERR_FORM_SIZE) | ||
->assertRaised(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,8 @@ | |
"symfony/expression-language": "~2.4|~3.0.0", | ||
"doctrine/annotations": "~1.0", | ||
"doctrine/cache": "~1.0", | ||
"egulias/email-validator": "~1.2,>=1.2.1" | ||
"egulias/email-validator": "~1.2,>=1.2.1", | ||
"psr/http-message": "~1.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this go into suggest too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to be here because we reference the Psr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now also added it to the suggests section as well. |
||
}, | ||
"suggest": { | ||
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.", | ||
|
@@ -40,7 +41,8 @@ | |
"symfony/config": "", | ||
"egulias/email-validator": "Strict (RFC compliant) email validation", | ||
"symfony/property-access": "For using the 2.4 Validator API", | ||
"symfony/expression-language": "For using the 2.4 Expression validator" | ||
"symfony/expression-language": "For using the 2.4 Expression validator", | ||
"psr/http-message": "For validating PSR-7 UploadedFileInterface implementations" | ||
}, | ||
"autoload": { | ||
"psr-4": { "Symfony\\Component\\Validator\\": "" } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is equal to
HttpFoundation\File\UploadedFile::getMaxFilesize()
. It exists here in order to remove the dependency on HttpFoundation for creating the error message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we still have a dependency on the component, so what's the advantage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind - it's a
dev
dependency. I'm with you :)