4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer
;
14 use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain
;
16 class DataTransformerChainTest
extends \PHPUnit_Framework_TestCase
18 public function testTransform()
20 $transformer1 = $this->getMock('Symfony\Component\Form\DataTransformerInterface');
21 $transformer1->expects($this->once())
23 ->with($this->identicalTo('foo'))
24 ->will($this->returnValue('bar'));
25 $transformer2 = $this->getMock('Symfony\Component\Form\DataTransformerInterface');
26 $transformer2->expects($this->once())
28 ->with($this->identicalTo('bar'))
29 ->will($this->returnValue('baz'));
31 $chain = new DataTransformerChain(array($transformer1, $transformer2));
33 $this->assertEquals('baz', $chain->transform('foo'));
36 public function testReverseTransform()
38 $transformer2 = $this->getMock('Symfony\Component\Form\DataTransformerInterface');
39 $transformer2->expects($this->once())
40 ->method('reverseTransform')
41 ->with($this->identicalTo('foo'))
42 ->will($this->returnValue('bar'));
43 $transformer1 = $this->getMock('Symfony\Component\Form\DataTransformerInterface');
44 $transformer1->expects($this->once())
45 ->method('reverseTransform')
46 ->with($this->identicalTo('bar'))
47 ->will($this->returnValue('baz'));
49 $chain = new DataTransformerChain(array($transformer1, $transformer2));
51 $this->assertEquals('baz', $chain->reverseTransform('foo'));