forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8671d74
commit 544a0d5
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Sonata\AdminBundle\Tests\Fixtures\Entity\Form; | ||
|
||
class FooEntity | ||
{ | ||
private $values; | ||
|
||
public function __construct(array $values=array()) | ||
{ | ||
$this->values = $values; | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
Tests/Form/DataTransformer/ArrayToModelTransformerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata project. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\Form\DataTransformer; | ||
|
||
use Sonata\AdminBundle\Model\ModelManagerInterface; | ||
use Sonata\AdminBundle\Form\DataTransformer\ArrayToModelTransformer; | ||
use Sonata\AdminBundle\Tests\Fixtures\Entity\Form\FooEntity; | ||
|
||
/** | ||
* @author Andrej Hudec <[email protected]> | ||
*/ | ||
class ArrayToModelTransformerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $modelManager = null; | ||
|
||
public function setUp() | ||
{ | ||
$this->modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface'); | ||
} | ||
|
||
public function testReverseTransformEntity() | ||
{ | ||
$transformer = new ArrayToModelTransformer($this->modelManager, 'Sonata\AdminBundle\Tests\Fixtures\Entity\Form\FooEntity'); | ||
|
||
$entity = new FooEntity(); | ||
$this->assertEquals($entity, $transformer->reverseTransform($entity)); | ||
} | ||
|
||
/** | ||
* @dataProvider getReverseTransformTests | ||
*/ | ||
public function testReverseTransform($value) | ||
{ | ||
$transformer = new ArrayToModelTransformer($this->modelManager, 'Sonata\AdminBundle\Tests\Fixtures\Entity\Form\FooEntity'); | ||
|
||
$this->modelManager->expects($this->any()) | ||
->method('modelReverseTransform') | ||
->will($this->returnValue(new FooEntity())); | ||
|
||
$this->assertInstanceOf('Sonata\AdminBundle\Tests\Fixtures\Entity\Form\FooEntity', $transformer->reverseTransform($value)); | ||
} | ||
|
||
public function getReverseTransformTests() | ||
{ | ||
return array( | ||
array('Sonata\AdminBundle\Tests\Fixtures\Entity\Form\FooEntity'), | ||
array(array()), | ||
array(array('foo'=>'bar')), | ||
array('foo'), | ||
array(123), | ||
array(null), | ||
array(false), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider getTransformTests | ||
*/ | ||
public function testTransform($expected, $value) | ||
{ | ||
$transformer = new ArrayToModelTransformer($this->modelManager, 'Sonata\AdminBundle\Tests\Fixtures\Entity\Form\FooEntity'); | ||
|
||
$this->assertEquals($expected, $transformer->transform($value)); | ||
} | ||
|
||
public function getTransformTests() | ||
{ | ||
return array( | ||
array(123, 123), | ||
array('foo', 'foo'), | ||
array(false, false), | ||
array(null, null), | ||
array(0, 0), | ||
); | ||
} | ||
} |