Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit392d88e

Browse files
minor#45511 [Validator] Improve tests for the Image and File constraints (fancyweb)
This PR was merged into the 4.4 branch.Discussion----------[Validator] Improve tests for the Image and File constraints| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | no| New feature? | no| Deprecations? | -| Tickets | -| License | MIT| Doc PR | -For#45090 but submitting it on the lowest branch possible.Commits-------1a82c71 [Validator] Improve tests for the Image and File constraints
2 parents7ce0ebe +1a82c71 commit392d88e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

‎src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ public function testMaxSizeExceeded($bytesWritten, $limit, $sizeAsString, $limit
185185
publicfunctionprovideMaxSizeNotExceededTests()
186186
{
187187
return [
188+
// 0 has no effect
189+
[100,0],
190+
188191
// limit in bytes
189192
[1000,1000],
190193
[1000000,1000000],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foobar

‎src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ImageValidatorTest extends ConstraintValidatorTestCase
3434
protected$imagePortrait;
3535
protected$image4By3;
3636
protected$imageCorrupted;
37+
protected$notAnImage;
3738

3839
protectedfunctioncreateValidator()
3940
{
@@ -50,6 +51,7 @@ protected function setUp(): void
5051
$this->image4By3 =__DIR__.'/Fixtures/test_4by3.gif';
5152
$this->image16By9 =__DIR__.'/Fixtures/test_16by9.gif';
5253
$this->imageCorrupted =__DIR__.'/Fixtures/test_corrupted.gif';
54+
$this->notAnImage =__DIR__.'/Fixtures/ccc.txt';
5355
}
5456

5557
publicfunctiontestNullIsValid()
@@ -416,4 +418,19 @@ public function testCorrupted()
416418
->setCode(Image::CORRUPTED_IMAGE_ERROR)
417419
->assertRaised();
418420
}
421+
422+
publicfunctiontestInvalidMimeType()
423+
{
424+
$this->validator->validate($this->notAnImage,$constraint =newImage());
425+
426+
$this->assertSame('image/*',$constraint->mimeTypes);
427+
428+
$this->buildViolation('This file is not a valid image.')
429+
->setParameter('{{ file }}',sprintf('"%s"',$this->notAnImage))
430+
->setParameter('{{ type }}','"text/plain"')
431+
->setParameter('{{ types }}','"image/*"')
432+
->setParameter('{{ name }}','"ccc.txt"')
433+
->setCode(Image::INVALID_MIME_TYPE_ERROR)
434+
->assertRaised();
435+
}
419436
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp