Skip to content

Instantly share code, notes, and snippets.

@dwaligora
Created April 11, 2013 16:34
Show Gist options
  • Save dwaligora/5364952 to your computer and use it in GitHub Desktop.
Save dwaligora/5364952 to your computer and use it in GitHub Desktop.
<?php
namespace Acme\Bundle\TranslationBundle\Tests\PHPUnit\Form\Type;
use Acme\Bundle\TranslationBundle\Form\Type\LocaleType;
/**
* Description of LocaleTypeTest
*
* @author Daniel Waligóra <danielwaligora@gmail.com>
*/
class LocaleTypeTest extends \PHPUnit_Framework_TestCase
{
public function testSetLocale()
{
$data = array('en', 'pl');
$translator_stub = $this->getTranslatorMock();
$locale_type = new LocaleType($translator_stub);
$locale_type->setLocale($data);
$this->assertAttributeEquals($data, 'locale', $locale_type);
}
public function testConvertLocaleToCountryName()
{
$data = array('en', 'pl');
$translator_stub = $this->getTranslatorMock();
$locale_type = new LocaleType($translator_stub);
$reflection = new \ReflectionClass(get_class($locale_type));
$method = $reflection->getMethod('convertLocaleToCountryName');
$method->setAccessible(true);
$this->assertEquals(array('English', 'Polish'), $method->invokeArgs($locale_type, array($data)));
}
protected function getTranslatorMock()
{
$stub = $this->getMockBuilder('Acme\Component\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stub->expects($this->any())
->method('getLocale')
->will($this->returnValue('en'));
return $stub;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment