Skip to content

Commit

Permalink
Make TranslatorFactory::newInstance compatible with Aura 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Feb 4, 2017
1 parent 8258072 commit c9d2695
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/I18n/TranslatorFactory.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\I18n;

use Aura\Intl\FormatterInterface;
use Aura\Intl\Package;
use Aura\Intl\TranslatorFactory as BaseTranslatorFactory;
use Aura\Intl\TranslatorInterface;
use RuntimeException;
Expand All @@ -37,15 +38,15 @@ class TranslatorFactory extends BaseTranslatorFactory
* Returns a new Translator.
*
* @param string $locale The locale code for the translator.
* @param array $messages The localized messages for the translator.
* @param \Aura\Intl\Package $package The Package containing keys and translations.
* @param \Aura\Intl\FormatterInterface $formatter The formatter to use for interpolating token values.
* @param \Aura\Intl\TranslatorInterface $fallback A fallback translator to use, if any.
* @throws \Cake\Core\Exception\Exception If fallback class does not match Cake\I18n\Translator
* @return \Cake\I18n\Translator
*/
public function newInstance(
$locale,
array $messages,
Package $package,
FormatterInterface $formatter,
TranslatorInterface $fallback = null
) {
Expand All @@ -57,6 +58,6 @@ public function newInstance(
));
}

return new $class($locale, $messages, $formatter, $fallback);
return new $class($locale, $package, $formatter, $fallback);
}
}
6 changes: 4 additions & 2 deletions tests/TestCase/I18n/TranslatorFactoryTest.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Test\TestCase\I18n;

use Aura\Intl\Package;
use Aura\Intl\Translator as AuraTranslator;
use Cake\I18n\TranslatorFactory;
use Cake\TestSuite\TestCase;
Expand All @@ -32,8 +33,9 @@ class TranslatorFactoryTest extends TestCase
public function testNewInstanceErrorOnFallback()
{
$formatter = $this->getMockBuilder('Aura\Intl\FormatterInterface')->getMock();
$fallback = new AuraTranslator('en_CA', [], $formatter, null);
$package = $this->getMockBuilder(Package::class)->getMock();
$fallback = new AuraTranslator('en_CA', $package, $formatter, null);
$factory = new TranslatorFactory();
$factory->newInstance('en_CA', [], $formatter, $fallback);
$factory->newInstance('en_CA', $package, $formatter, $fallback);
}
}

0 comments on commit c9d2695

Please sign in to comment.