Skip to content

Commit

Permalink
remove deprecated method & update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shady committed Jun 7, 2013
1 parent 56f378a commit 728c7f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions EventListener/BaseFileListener.php
Expand Up @@ -12,7 +12,7 @@
namespace Vlabs\MediaBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Event\DataEvent;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Form\FormFactoryInterface;
Expand Down Expand Up @@ -47,16 +47,16 @@ public static function getSubscribedEvents()
{
return array(
FormEvents::PRE_SET_DATA => 'preSetData',
FormEvents::BIND => 'bind'
FormEvents::SUBMIT => 'submit'
);
}

/**
* Add checkbox type if needed
*
* @param \Symfony\Component\Form\Event\DataEvent $event
* @param \Symfony\Component\Form\FormEvent $event
*/
public function preSetData(DataEvent $event)
public function preSetData(FormEvent $event)
{
$data = $event->getData();

Expand All @@ -75,9 +75,9 @@ public function preSetData(DataEvent $event)
/**
* Field logic : set actual object in form or handle new file creation
*
* @param \Symfony\Component\Form\Event\DataEvent $event
* @param \Symfony\Component\Form\FormEvent $event
*/
public function bind(DataEvent $event)
public function submit(FormEvent $event)
{
$form = $event->getForm();

Expand Down
18 changes: 9 additions & 9 deletions Tests/EventListener/BaseFileListenerTest.php
Expand Up @@ -54,7 +54,7 @@ protected function getFormConfigMock()
->method('getDataClass')
->will($this->returnValue('Vlabs\MediaBundle\Tests\DummyEntity'))
;

return $mock;
}

Expand Down Expand Up @@ -151,9 +151,9 @@ public function testGetSubscribedEvents()
$events = $listener->getSubscribedEvents();

$this->assertTrue(array_key_exists(FormEvents::PRE_SET_DATA, $events));
$this->assertTrue(array_key_exists(FormEvents::BIND, $events));
$this->assertTrue(array_key_exists(FormEvents::SUBMIT, $events));
$this->assertEquals($events[FormEvents::PRE_SET_DATA], 'preSetData');
$this->assertEquals($events[FormEvents::BIND], 'bind');
$this->assertEquals($events[FormEvents::SUBMIT], 'submit');
}

public function testPreSetData()
Expand All @@ -167,20 +167,20 @@ public function testPreSetData()
$listener->preSetData($event);
}

public function testBindHandleSameFile()
public function testSubmitHandleSameFile()
{
$data = '';
$form = $this->getFormWithData();

$event = new FormEvent($form, $data);

$listener = new BaseFileListener($this->handlerManager, $this->getFormFactoryMock());
$listener->bind($event);
$listener->submit($event);

$this->assertInstanceOf('Vlabs\MediaBundle\Entity\BaseFileInterface', $event->getData());
}

public function testBindHandleNewFileWithNonEmptyField()
public function testSubmitHandleNewFileWithNonEmptyField()
{
$data = $file = new UploadedFile(
__DIR__.'/../Fixtures/test.gif',
Expand All @@ -194,19 +194,19 @@ public function testBindHandleNewFileWithNonEmptyField()
$event = new FormEvent($form, $data);

$listener = new BaseFileListener($this->handlerManager, $this->getFormFactoryMock());
$listener->bind($event);
$listener->submit($event);

$this->assertInstanceOf('Vlabs\MediaBundle\Entity\BaseFileInterface', $event->getData());
$this->assertNotEquals($event->getData(), $form->getNormData());
}

public function testNullDatasOnBind()
public function testNullDatasOnSubmit()
{
$data = '';
$event = new FormEvent($this->form, $data);

$listener = new BaseFileListener($this->handlerManager, $this->getFormFactoryMock());
$listener->bind($event);
$listener->submit($event);

$this->assertNull($event->getData());
}
Expand Down

0 comments on commit 728c7f1

Please sign in to comment.