/**
  * Test that postRemove skips non uploadable entity.
  */
 public function testPostRemoveSkipsNonUploadable()
 {
     $obj = new DummyEntity();
     $class = new \ReflectionClass($obj);
     $args = $this->getMockBuilder('Doctrine\\Common\\EventArgs')->disableOriginalConstructor()->getMock();
     $this->adapter->expects($this->once())->method('getObjectFromArgs')->will($this->returnValue($obj));
     $this->adapter->expects($this->once())->method('getReflectionClass')->will($this->returnValue($class));
     $this->driver->expects($this->once())->method('readUploadable')->with($class)->will($this->returnValue(null));
     $this->storage->expects($this->never())->method('remove');
     $listener = new UploaderListener($this->adapter, $this->driver, $this->storage, $this->injector);
     $listener->postRemove($args);
 }
 public function testConfiguredNamerRetrievedFromContainer()
 {
     $obj = new DummyEntity();
     $class = new \ReflectionClass($obj);
     $mappings = array('dummy_file' => array('upload_dir' => '/tmp', 'delete_on_remove' => true, 'namer' => 'my.custom.namer', 'inject_on_load' => true));
     $uploadable = $this->getMockBuilder('Vich\\UploaderBundle\\Mapping\\Annotation\\Uploadable')->disableOriginalConstructor()->getMock();
     $fileField = $this->getMockBuilder('Vich\\UploaderBundle\\Mapping\\Annotation\\UploadableField')->disableOriginalConstructor()->getMock();
     $fileField->expects($this->any())->method('getMapping')->will($this->returnValue('dummy_file'));
     $fileField->expects($this->once())->method('getPropertyName')->will($this->returnValue('file'));
     $fileField->expects($this->once())->method('getFileNameProperty')->will($this->returnValue('fileName'));
     $namer = $this->getMock('Vich\\UploaderBundle\\Naming\\NamerInterface');
     $this->container->expects($this->once())->method('get')->with('my.custom.namer')->will($this->returnValue($namer));
     $this->adapter->expects($this->any())->method('getReflectionClass')->will($this->returnValue($class));
     $this->driver->expects($this->once())->method('readUploadable')->with($class)->will($this->returnValue($uploadable));
     $this->driver->expects($this->once())->method('readUploadableFields')->with($class)->will($this->returnValue(array($fileField)));
     $factory = new PropertyMappingFactory($this->container, $this->driver, $this->adapter, $mappings);
     $mappings = $factory->fromObject($obj);
     $this->assertEquals(1, count($mappings));
     if (count($mappings) > 0) {
         $mapping = $mappings[0];
         $this->assertEquals($namer, $mapping->getNamer());
         $this->assertTrue($mapping->hasNamer());
     }
 }
 /**
  * Test that the driver reads zero UploadableField
  * properties when none exist.
  */
 public function testReadNoUploadableFieldsWhenNoneExist()
 {
     $entity = new DummyEntity();
     $class = new \ReflectionClass($entity);
     $reader = $this->getMock('Doctrine\\Common\\Annotations\\Reader');
     $reader->expects($this->any())->method('getPropertyAnnotation')->will($this->returnValue(null));
     $driver = new AnnotationDriver($reader);
     $fields = $driver->readUploadableFields($class);
     $this->assertEquals(0, count($fields));
 }
 /**
  * Checks to see if the class is uploadable.
  *
  * @param \ReflectionClass $class The class.
  * @throws \InvalidArgumentException
  */
 protected function checkUploadable(\ReflectionClass $class)
 {
     if (null === $this->driver->readUploadable($class)) {
         throw new \InvalidArgumentException('The object is not uploadable.');
     }
 }
 /**
  * Tests if the object is Uploadable.
  *
  * @param  object  $obj The object.
  * @return boolean True if uploadable, false otherwise.
  */
 protected function isUploadable($obj)
 {
     $class = $this->adapter->getReflectionClass($obj);
     return null !== $this->driver->readUploadable($class);
 }