/**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof AttachmentInterface) {
         return;
     }
     if (!$constraint instanceof ImageConstraint) {
         throw new UnexpectedTypeException($constraint, ImageConstraint::class);
     }
     parent::validate($value->getFile()->getTmpPathname(), $constraint);
 }
 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();
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if ($value instanceof FSiFile) {
         $tmpFile = sys_get_temp_dir() . '/' . uniqid();
         file_put_contents($tmpFile, $value->getContent());
         try {
             parent::validate($tmpFile, $constraint);
         } catch (\Exception $e) {
             unlink($tmpFile);
             throw $e;
         }
         return;
     }
     parent::validate($value, $constraint);
 }
 public function testPortraitNotAllowed()
 {
     $constraint = new Image(array('allowPortrait' => false, 'allowPortraitMessage' => 'myMessage'));
     $this->validator->validate($this->imagePortrait, $constraint);
     $this->buildViolation('myMessage')->setParameter('{{ width }}', 1)->setParameter('{{ height }}', 2)->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)->assertRaised();
 }
 public function testPortraitNotAllowed()
 {
     $constraint = new Image(array('allowPortrait' => false, 'allowPortraitMessage' => 'myMessage'));
     $this->validator->validate($this->imagePortrait, $constraint);
     $this->assertViolation('myMessage', array('{{ width }}' => 1, '{{ height }}' => 2));
 }
 function it_saves_file_and_calls_symfony_validator(ImageValidator $imageValidator, File $constraint, FSiFile $file)
 {
     $file->getContent()->willReturn('file content');
     $imageValidator->validate(Argument::containingString('/tmp/'), $constraint)->shouldBeCalled();
     $this->validate($file, $constraint);
 }