public function testBcDefaultFormatter() { $formatter = new RawFormatter(); $env = $this->getMock('\\Twig_Environment'); $pool = new Pool(); $pool->add('foo', $formatter, $env); $this->assertSame('foo', $pool->getDefaultFormatter()); }
public function testUnexpectedException() { $this->setExpectedException('RuntimeException'); $formatter = new RawFormatter(); $env = $this->getMock('\\Twig_Environment'); $env->expects($this->once())->method('render')->will($this->throwException(new \RuntimeException('Error'))); $pool = new Pool(); $pool->add('foo', $formatter, $env); $pool->transform('foo', 'Salut'); }
public function testWithValidFormatter() { $formatter = $this->getMock('Sonata\\FormatterBundle\\Formatter\\FormatterInterface'); $formatter->expects($this->once())->method('transform')->will($this->returnCallback(function ($text) { return strtoupper($text); })); $pool = new Pool(); $pool->add('myformat', $formatter); $listener = new FormatterListener($pool, '[format]', '[source]', '[target]'); $event = new FormEvent($this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'), array('format' => 'myformat', 'source' => 'data', 'target' => null)); $listener->postSubmit($event); $expected = array('format' => 'myformat', 'source' => 'data', 'target' => 'DATA'); $this->assertSame($expected, $event->getData()); }