Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'qa/130' into develop
Browse files Browse the repository at this point in the history
Forward port #130
  • Loading branch information
michalbundyra committed Dec 12, 2019
2 parents 0d94341 + 94f4b12 commit 774ac64
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 88 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ matrix:
- php: 7.3
env:
- DEPS=latest
- php: 7.4
env:
- DEPS=lowest
- php: 7.4
env:
- DEPS=locked
- php: 7.4
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- Nothing.
- [#130](https://github.com/zendframework/zend-i18n/pull/130) adds support for PHP 7.4.

### Changed

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"zendframework/zend-validator": "^2.6",
"zendframework/zend-view": "^2.6.3"
},
"conflict": {
"phpspec/prophecy": "<1.9.0"
},
"suggest": {
"zendframework/zend-cache": "Zend\\Cache component",
"zendframework/zend-config": "Zend\\Config component",
Expand Down
54 changes: 26 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 10 additions & 23 deletions test/Translator/TranslatorServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,27 @@ class TranslatorServiceFactoryTest extends TestCase
{
public function testCreateServiceWithNoTranslatorKeyDefined()
{
$pluginManagerMock = $this->createMock(LoaderPluginManager::class);
$slContents = [
['config', []],
['TranslatorPluginManager', $pluginManagerMock]
];
$pluginManagerMock = $this->prophesize(LoaderPluginManager::class)->reveal();

$serviceLocator = $this->createMock(ContainerInterface::class);
$serviceLocator
->expects($this->once())
->method('has')
->with($this->equalTo('TranslatorPluginManager'))
->willReturn(true);
$serviceLocator
->expects($this->exactly(2))
->method('get')
->willReturnMap($slContents);
$serviceLocator = $this->prophesize(ContainerInterface::class);
$serviceLocator->has('TranslatorPluginManager')->willReturn(true)->shouldBeCalledTimes(1);
$serviceLocator->get('TranslatorPluginManager')->willReturn($pluginManagerMock)->shouldBeCalledTimes(1);
$serviceLocator->get('config')->willReturn([])->shouldBeCalledTimes(1);

$factory = new TranslatorServiceFactory();
$translator = $factory($serviceLocator, Translator::class);
$translator = $factory($serviceLocator->reveal(), Translator::class);
$this->assertInstanceOf(Translator::class, $translator);
$this->assertSame($pluginManagerMock, $translator->getPluginManager());
}

public function testCreateServiceWithNoTranslatorPluginManagerDefined()
{
$serviceLocator = $this->createMock(ContainerInterface::class);
$serviceLocator
->expects($this->once())
->method('get')
->with($this->equalTo('config'))
->willReturn([]);
$serviceLocator = $this->prophesize(ContainerInterface::class);
$serviceLocator->has('TranslatorPluginManager')->willReturn(false)->shouldBeCalledTimes(1);
$serviceLocator->get('config')->willReturn([])->shouldBeCalledTimes(1);

$factory = new TranslatorServiceFactory();
$translator = $factory($serviceLocator, Translator::class);
$translator = $factory($serviceLocator->reveal(), Translator::class);
$this->assertInstanceOf(Translator::class, $translator);
}
}
35 changes: 11 additions & 24 deletions test/View/Helper/TranslatePluralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use PHPUnit\Framework\TestCase;
use Zend\I18n\View\Helper\TranslatePlural as TranslatePluralHelper;
use Zend\I18n\Translator\Translator;

/**
* @group Zend_View
Expand Down Expand Up @@ -56,19 +57,12 @@ public function testDefaultInvokeArguments()
$numberInput = 1;
$expected = 'translated';

$translatorMock = $this->createMock('Zend\I18n\Translator\Translator');
$translatorMock->expects($this->once())
->method('translatePlural')
->with(
$this->equalTo($singularInput),
$this->equalTo($pluralInput),
$this->equalTo($numberInput),
$this->equalTo('default'),
$this->equalTo(null)
)
->willReturn($expected);
$translatorMock = $this->prophesize(Translator::class);
$translatorMock->translatePlural($singularInput, $pluralInput, $numberInput, 'default', null)
->willReturn($expected)
->shouldBeCalledTimes(1);

$this->helper->setTranslator($translatorMock);
$this->helper->setTranslator($translatorMock->reveal());

$this->assertEquals($expected, $this->helper->__invoke($singularInput, $pluralInput, $numberInput));
}
Expand All @@ -82,19 +76,12 @@ public function testCustomInvokeArguments()
$textDomain = 'textDomain';
$locale = 'en_US';

$translatorMock = $this->createMock('Zend\I18n\Translator\Translator');
$translatorMock->expects($this->once())
->method('translatePlural')
->with(
$this->equalTo($singularInput),
$this->equalTo($pluralInput),
$this->equalTo($numberInput),
$this->equalTo($textDomain),
$this->equalTo($locale)
)
->willReturn($expected);
$translatorMock = $this->prophesize(Translator::class);
$translatorMock->translatePlural($singularInput, $pluralInput, $numberInput, $textDomain, $locale)
->willReturn($expected)
->shouldBeCalledTimes(1);

$this->helper->setTranslator($translatorMock);
$this->helper->setTranslator($translatorMock->reveal());

$this->assertEquals($expected, $this->helper->__invoke(
$singularInput,
Expand Down
23 changes: 11 additions & 12 deletions test/View/Helper/TranslateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use PHPUnit\Framework\TestCase;
use Zend\I18n\View\Helper\Translate as TranslateHelper;
use Zend\I18n\Translator\Translator;

/**
* @group Zend_View
Expand Down Expand Up @@ -54,13 +55,12 @@ public function testDefaultInvokeArguments()
$input = 'input';
$expected = 'translated';

$translatorMock = $this->createMock('Zend\I18n\Translator\Translator');
$translatorMock->expects($this->once())
->method('translate')
->with($this->equalTo($input), $this->equalTo('default'), $this->equalTo(null))
->willReturn($expected);
$translatorMock = $this->prophesize(Translator::class);
$translatorMock->translate($input, 'default', null)
->willReturn($expected)
->shouldBeCalledTimes(1);

$this->helper->setTranslator($translatorMock);
$this->helper->setTranslator($translatorMock->reveal());

$this->assertEquals($expected, $this->helper->__invoke($input));
}
Expand All @@ -72,13 +72,12 @@ public function testCustomInvokeArguments()
$textDomain = 'textDomain';
$locale = 'en_US';

$translatorMock = $this->createMock('Zend\I18n\Translator\Translator');
$translatorMock->expects($this->once())
->method('translate')
->with($this->equalTo($input), $this->equalTo($textDomain), $this->equalTo($locale))
->willReturn($expected);
$translatorMock = $this->prophesize(Translator::class);
$translatorMock->translate($input, $textDomain, $locale)
->willReturn($expected)
->shouldBeCalledTimes(1);

$this->helper->setTranslator($translatorMock);
$this->helper->setTranslator($translatorMock->reveal());

$this->assertEquals($expected, $this->helper->__invoke($input, $textDomain, $locale));
}
Expand Down

0 comments on commit 774ac64

Please sign in to comment.