use Symfony\Component\Validator\Constraints\Image;
use Symfony\Component\Validator\Constraints\ImageValidator;
-use Symfony\Component\Validator\Validation;
+use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @requires extension fileinfo
*/
-class ImageValidatorTest extends AbstractConstraintValidatorTest
+class ImageValidatorTest extends ConstraintValidatorTestCase
{
protected $context;
protected $imageLandscape;
protected $imagePortrait;
protected $image4By3;
-
- protected function getApiVersion()
- {
- return Validation::API_VERSION_2_5;
- }
+ protected $imageCorrupted;
protected function createValidator()
{
$this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif';
$this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif';
$this->image4By3 = __DIR__.'/Fixtures/test_4by3.gif';
+ $this->imageCorrupted = __DIR__.'/Fixtures/test_corrupted.gif';
}
public function testNullIsValid()
->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
->assertRaised();
}
+
+ public function testCorrupted()
+ {
+ if (!function_exists('imagecreatefromstring')) {
+ $this->markTestSkipped('This test require GD extension');
+ }
+
+ $constraint = new Image(array(
+ 'detectCorrupted' => true,
+ 'corruptedMessage' => 'myMessage',
+ ));
+
+ $this->validator->validate($this->image, $constraint);
+
+ $this->assertNoViolation();
+
+ $this->validator->validate($this->imageCorrupted, $constraint);
+
+ $this->buildViolation('myMessage')
+ ->setCode(Image::CORRUPTED_IMAGE_ERROR)
+ ->assertRaised();
+ }
}