Skip to content

Commit

Permalink
throw exception if required attributes of UploadableField are not pre…
Browse files Browse the repository at this point in the history
…sent and tests
  • Loading branch information
dustin10 committed Jan 29, 2012
1 parent 85f4139 commit 0fe106a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Mapping/Annotation/UploadableField.php
Expand Up @@ -35,10 +35,14 @@ public function __construct(array $options)
{
if (isset($options['mapping'])) {
$this->mapping = $options['mapping'];
} else {
throw new \Exception('The "mapping" attribute of UploadableField is required.');
}

if (isset($options['fileNameProperty'])) {
$this->fileNameProperty = $options['fileNameProperty'];
} else {
throw new \Exception('The "fileNameProperty" attribute of UploadableField is required.');
}
}

Expand Down
33 changes: 33 additions & 0 deletions Tests/Mapping/Annotation/UploadableFieldTest.php
@@ -0,0 +1,33 @@
<?php

namespace Vich\UploaderBundle\Tests\Mapping\Annotation;

use Vich\UploaderBundle\Mapping\Annotation\UploadableField;

/**
* UploadableFieldTest.
*
* @author Dustin Dobervich <ddobervich@gmail.com>
*/
class UploadableFieldTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Exception
*/
public function testExceptionThrownWhenNoMappingAttribute()
{
new UploadableField(array(
'fileNameProperty' => 'fileName'
));
}

/**
* @expectedException \Exception
*/
public function testExceptionThrownWhenNoFileNamePropertyAttribute()
{
new UploadableField(array(
'mapping' => 'file'
));
}
}

0 comments on commit 0fe106a

Please sign in to comment.