From 22b7dc6491c6fd6b638eb96bcf7e2c9573e2ce72 Mon Sep 17 00:00:00 2001 From: Vova Soroka Date: Wed, 13 Dec 2017 16:26:05 +0200 Subject: [PATCH] BAP-15849: Upgrade 2.x LTS releases to latest Symfony 2.8.x version (#15379) --- composer.json | 4 +- .../Bundle/ActionBundle/Model/Parameter.php | 2 +- src/Oro/Bundle/EmailBundle/Entity/Mailbox.php | 2 +- .../EmailBundle/Form/Model/SmtpSettings.php | 2 +- .../Attribute/Entity/AttributeFamily.php | 2 +- .../Entity/AbstractEnumValue.php | 2 +- .../PercentToLocalizedStringTransformer.php | 24 +++- .../FormBundle/Form/Type/ChoiceListItem.php | 2 +- .../Unit/Form/Type/OroPercentTypeTest.php | 68 +++++++++ .../AssetsInstallCommandListener.php | 134 ++++++++++++++++++ .../Resources/config/services.yml | 9 ++ .../Test/FakeRestResponse.php | 2 +- .../LocaleBundle/Entity/Localization.php | 2 +- .../Formatter/FormattingCodeFormatterTest.php | 4 +- .../Formatter/LanguageCodeFormatterTest.php | 4 +- .../Unit/Formatter/NumberFormatterTest.php | 4 +- .../Tests/Unit/Model/CalendarTest.php | 4 +- .../NotificationBundle/Entity/Event.php | 2 +- .../Tests/Unit/Stub/EntityStub.php | 2 +- .../Behat/Element/InputValue.php | 2 +- .../Tests/Stub/InputStub.php | 2 +- .../Test/Stub/ClassWithToString.php | 2 +- .../Unit/Translation/DebugTranslatorTest.php | 41 +++--- .../Tests/Unit/Translation/TranslatorTest.php | 106 +++++++------- .../Translation/Translator.php | 20 ++- src/Oro/Bundle/UIBundle/Model/TreeItem.php | 2 +- src/Oro/Bundle/UserBundle/Entity/Role.php | 8 +- .../WorkflowBundle/Entity/WorkflowStep.php | 2 +- .../WorkflowBundle/Model/Transition.php | 2 +- ...tionEventTriggerExpressionVerifierTest.php | 5 +- .../Component/Config/CumulativeResource.php | 2 +- .../ConfigExpression/CompiledPropertyPath.php | 2 +- .../Tests/Unit/Fixtures/Entity/Category.php | 2 +- .../Tests/Unit/Resolver/TestResource.php | 2 +- .../Testing/Unit/Command/Stub/InputStub.php | 2 +- 35 files changed, 354 insertions(+), 123 deletions(-) create mode 100644 src/Oro/Bundle/InstallerBundle/EventListener/AssetsInstallCommandListener.php diff --git a/composer.json b/composer.json index 6552501785e..e60e8468c06 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "ext-zip": "*", "ext-openssl": "*", "ext-mcrypt": "*", - "symfony/symfony": "2.8.*, !=2.8.10, <=2.8.13", - "twig/twig": "1.29.*", + "symfony/symfony": "2.8.*, !=2.8.10, <=2.8.32", + "twig/twig": "1.35.*", "doctrine/orm": "2.5.5", "doctrine/doctrine-bundle": "1.6.5", "doctrine/dbal": "2.5.5", diff --git a/src/Oro/Bundle/ActionBundle/Model/Parameter.php b/src/Oro/Bundle/ActionBundle/Model/Parameter.php index c15fd3658ff..d9d9ffd7b32 100644 --- a/src/Oro/Bundle/ActionBundle/Model/Parameter.php +++ b/src/Oro/Bundle/ActionBundle/Model/Parameter.php @@ -140,6 +140,6 @@ public function isRequired() */ public function __toString() { - return $this->name; + return (string)$this->name; } } diff --git a/src/Oro/Bundle/EmailBundle/Entity/Mailbox.php b/src/Oro/Bundle/EmailBundle/Entity/Mailbox.php index d648efa76ca..a342a6418e4 100644 --- a/src/Oro/Bundle/EmailBundle/Entity/Mailbox.php +++ b/src/Oro/Bundle/EmailBundle/Entity/Mailbox.php @@ -433,7 +433,7 @@ public function removeAuthorizedUser(User $user) */ public function __toString() { - return $this->getLabel(); + return (string)$this->getLabel(); } /** diff --git a/src/Oro/Bundle/EmailBundle/Form/Model/SmtpSettings.php b/src/Oro/Bundle/EmailBundle/Form/Model/SmtpSettings.php index ece39efa716..1e35badbcfb 100644 --- a/src/Oro/Bundle/EmailBundle/Form/Model/SmtpSettings.php +++ b/src/Oro/Bundle/EmailBundle/Form/Model/SmtpSettings.php @@ -61,7 +61,7 @@ public function __construct( */ public function __toString() { - return $this->getHost(); + return (string)$this->getHost(); } /** diff --git a/src/Oro/Bundle/EntityConfigBundle/Attribute/Entity/AttributeFamily.php b/src/Oro/Bundle/EntityConfigBundle/Attribute/Entity/AttributeFamily.php index 7c2fea97e49..aeee2dbc44f 100644 --- a/src/Oro/Bundle/EntityConfigBundle/Attribute/Entity/AttributeFamily.php +++ b/src/Oro/Bundle/EntityConfigBundle/Attribute/Entity/AttributeFamily.php @@ -357,7 +357,7 @@ public function setOrganization(OrganizationInterface $organization = null) */ public function __toString() { - return $this->getDefaultLabel()->getString(); + return (string)$this->getDefaultLabel()->getString(); } /** diff --git a/src/Oro/Bundle/EntityExtendBundle/Entity/AbstractEnumValue.php b/src/Oro/Bundle/EntityExtendBundle/Entity/AbstractEnumValue.php index 4e64ece48e9..657b0da52bd 100644 --- a/src/Oro/Bundle/EntityExtendBundle/Entity/AbstractEnumValue.php +++ b/src/Oro/Bundle/EntityExtendBundle/Entity/AbstractEnumValue.php @@ -161,6 +161,6 @@ public function getLocale() */ public function __toString() { - return $this->name; + return (string)$this->name; } } diff --git a/src/Oro/Bundle/FormBundle/Form/DataTransformer/PercentToLocalizedStringTransformer.php b/src/Oro/Bundle/FormBundle/Form/DataTransformer/PercentToLocalizedStringTransformer.php index 92dd763f2ce..c101f74f8d9 100644 --- a/src/Oro/Bundle/FormBundle/Form/DataTransformer/PercentToLocalizedStringTransformer.php +++ b/src/Oro/Bundle/FormBundle/Form/DataTransformer/PercentToLocalizedStringTransformer.php @@ -6,22 +6,37 @@ /** * Fix for standard transformer that supports precision = null + * and if the conversion type is "fractional", convert strings represent an integer value to float instead of integer. */ class PercentToLocalizedStringTransformer extends BaseTransformer { - /** - * @var int|null - */ + /** @var int|null */ private $precision; + /** @var string|null */ + private $type; + /** * {@inheritDoc} */ public function __construct($precision = null, $type = null) { parent::__construct($precision, $type); - $this->precision = $precision; + $this->type = $type; + } + + /** + * {@inheritDoc} + */ + public function reverseTransform($value) + { + $result = parent::reverseTransform($value); + if (is_int($result) && self::FRACTIONAL === $this->type) { + $result = (float)$result; + } + + return $result; } /** @@ -30,7 +45,6 @@ public function __construct($precision = null, $type = null) protected function getNumberFormatter() { $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL); - if (null !== $this->precision) { $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision); } diff --git a/src/Oro/Bundle/FormBundle/Form/Type/ChoiceListItem.php b/src/Oro/Bundle/FormBundle/Form/Type/ChoiceListItem.php index a09af6660a0..340a9485dec 100644 --- a/src/Oro/Bundle/FormBundle/Form/Type/ChoiceListItem.php +++ b/src/Oro/Bundle/FormBundle/Form/Type/ChoiceListItem.php @@ -129,6 +129,6 @@ public function setAttributes(array $attributes) */ public function __toString() { - return $this->label; + return (string)$this->label; } } diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/OroPercentTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/OroPercentTypeTest.php index 71d197ce7fd..2f06f1499c0 100644 --- a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/OroPercentTypeTest.php +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/OroPercentTypeTest.php @@ -89,4 +89,72 @@ public function buildFormDataProvider() ), ); } + + /** + * @param float $data + * @param array $expectedData + * @param array $options + * @dataProvider submitFormDataProvider + */ + public function testSubmitForm( + $data, + $expectedData, + array $options = array() + ) { + $form = $this->factory->create($this->formType, null, $options); + $form->submit($data); + self::assertTrue($form->isSynchronized()); + self::assertSame($expectedData, $form->getData()); + } + + /** + * @return array + */ + public function submitFormDataProvider() + { + return [ + 'unspecified precision, with numbers after decimal point' => [ + 'data' => (string)123.45, + 'expectedData' => 1.2345 + ], + 'unspecified precision, without numbers after decimal point' => [ + 'data' => (string)123, + 'expectedData' => 1.23 + ], + 'unspecified precision, without numbers after decimal point, value can be converted to integer' => [ + 'data' => (string)100, + 'expectedData' => (float)1 + ], + 'zero precision, with numbers after decimal point' => [ + 'data' => (string)123.45, + 'expectedData' => 1.2345, + 'options' => ['precision' => 0] + ], + 'zero precision, without numbers after decimal point' => [ + 'data' => (string)123, + 'expectedData' => 1.23, + 'options' => ['precision' => 0] + ], + 'zero precision, without numbers after decimal point, value can be converted to integer' => [ + 'data' => 100, + 'expectedData' => (float)1, + 'options' => ['precision' => 0] + ], + 'custom precision, with numbers after decimal point' => [ + 'data' => (string)123.45, + 'expectedData' => 1.2345, + 'options' => ['precision' => 1] + ], + 'custom precision, without numbers after decimal point' => [ + 'data' => (string)123, + 'expectedData' => 1.23, + 'options' => ['precision' => 1] + ], + 'custom precision, without numbers after decimal point, value can be converted to integer' => [ + 'data' => (string)100, + 'expectedData' => (float)1, + 'options' => ['precision' => 1] + ], + ]; + } } diff --git a/src/Oro/Bundle/InstallerBundle/EventListener/AssetsInstallCommandListener.php b/src/Oro/Bundle/InstallerBundle/EventListener/AssetsInstallCommandListener.php new file mode 100644 index 00000000000..01efd94caa3 --- /dev/null +++ b/src/Oro/Bundle/InstallerBundle/EventListener/AssetsInstallCommandListener.php @@ -0,0 +1,134 @@ +filesystem = $filesystem; + $this->kernelRootDir = $kernelRootDir; + } + + /** + * @param ConsoleCommandEvent $event + */ + public function beforeExecute(ConsoleCommandEvent $event) + { + if ($this->isAssetsInstallCommand($event->getCommand())) { + $this->moveAssets( + $event->getOutput(), + $this->getAssetsDir($event->getInput()), + $this->getTempDir($event->getInput()) + ); + } + } + + /** + * @param ConsoleTerminateEvent $event + */ + public function afterExecute(ConsoleTerminateEvent $event) + { + if ($this->isAssetsInstallCommand($event->getCommand())) { + $this->moveAssets( + $event->getOutput(), + $this->getTempDir($event->getInput()), + $this->getAssetsDir($event->getInput()) + ); + } + } + + /** + * @param Command $command + * + * @return bool + */ + private function isAssetsInstallCommand(Command $command) + { + return $command instanceof AssetsInstallCommand; + } + + /** + * @param OutputInterface $output + * @param string $srcDir + * @param string $targetDir + */ + private function moveAssets(OutputInterface $output, $srcDir, $targetDir) + { + foreach ($this->getAssets() as $assetDirName) { + $fromDir = $srcDir . $assetDirName; + $toDir = $targetDir . $assetDirName; + $output->writeln(sprintf('Move "%s" to "%s"', $fromDir, $toDir)); + if ($this->filesystem->exists($fromDir)) { + $this->filesystem->remove($toDir); + $this->filesystem->rename($fromDir, $toDir); + } else { + $output->writeln(sprintf('WARNING: The directory "%s" does not exist', $fromDir)); + } + } + } + + /** + * @return array + */ + private function getAssets() + { + return ['bowerassets', 'npmassets', 'components']; + } + + /** + * @param InputInterface $input + * + * @return string + */ + private function getAssetsDir(InputInterface $input) + { + return $this->getWebDir($input) . '/bundles/'; + } + + /** + * @param InputInterface $input + * + * @return string + */ + private function getTempDir(InputInterface $input) + { + return $this->getWebDir($input) . '/js/'; + } + + /** + * @param InputInterface $input + * + * @return string + */ + private function getWebDir(InputInterface $input) + { + $dir = rtrim($input->getArgument('target'), '/'); + if ('web' === $dir) { + $dir = $this->kernelRootDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $dir; + } + + return $dir; + } +} diff --git a/src/Oro/Bundle/InstallerBundle/Resources/config/services.yml b/src/Oro/Bundle/InstallerBundle/Resources/config/services.yml index 1183659a189..d94cb6f06dd 100644 --- a/src/Oro/Bundle/InstallerBundle/Resources/config/services.yml +++ b/src/Oro/Bundle/InstallerBundle/Resources/config/services.yml @@ -33,3 +33,12 @@ services: class: 'Oro\Bundle\InstallerBundle\CacheWarmer\NamespaceMigration' arguments: - '@doctrine' + + oro_installer.assets_install_command_listener: + class: Oro\Bundle\InstallerBundle\EventListener\AssetsInstallCommandListener + arguments: + - '@filesystem' + - '%kernel.root_dir%' + tags: + - { name: kernel.event_listener, event: console.command, method: beforeExecute } + - { name: kernel.event_listener, event: console.terminate, method: afterExecute } diff --git a/src/Oro/Bundle/IntegrationBundle/Test/FakeRestResponse.php b/src/Oro/Bundle/IntegrationBundle/Test/FakeRestResponse.php index f7753fed88d..88081eff82b 100644 --- a/src/Oro/Bundle/IntegrationBundle/Test/FakeRestResponse.php +++ b/src/Oro/Bundle/IntegrationBundle/Test/FakeRestResponse.php @@ -35,7 +35,7 @@ public function __construct($statusCode, array $headers = [], $body = '') */ public function __toString() { - return $this->getMessage(); + return (string)$this->getMessage(); } /** diff --git a/src/Oro/Bundle/LocaleBundle/Entity/Localization.php b/src/Oro/Bundle/LocaleBundle/Entity/Localization.php index 8ab2646b466..7bf2296bb62 100644 --- a/src/Oro/Bundle/LocaleBundle/Entity/Localization.php +++ b/src/Oro/Bundle/LocaleBundle/Entity/Localization.php @@ -140,7 +140,7 @@ public function __construct() */ public function __toString() { - return $this->getName(); + return (string)$this->getName(); } /** diff --git a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/FormattingCodeFormatterTest.php b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/FormattingCodeFormatterTest.php index 224fbf50839..e45704b337c 100644 --- a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/FormattingCodeFormatterTest.php +++ b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/FormattingCodeFormatterTest.php @@ -2,6 +2,8 @@ namespace Oro\Bundle\LocaleBundle\Tests\Unit\Formatter; +use PHPUnit\Framework\TestCase; + use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Translation\TranslatorInterface; @@ -9,7 +11,7 @@ use Oro\Bundle\LocaleBundle\Formatter\FormattingCodeFormatter; use Oro\Bundle\LocaleBundle\Formatter\LanguageCodeFormatter; -class FormattingCodeFormatterTest extends \PHPUnit_Framework_TestCase +class FormattingCodeFormatterTest extends TestCase { /** @var LanguageCodeFormatter */ protected $formatter; diff --git a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/LanguageCodeFormatterTest.php b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/LanguageCodeFormatterTest.php index 7a046277b5e..039f80fb1af 100644 --- a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/LanguageCodeFormatterTest.php +++ b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/LanguageCodeFormatterTest.php @@ -2,13 +2,15 @@ namespace Oro\Bundle\LocaleBundle\Tests\Unit\Formatter; +use PHPUnit\Framework\TestCase; + use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Translation\TranslatorInterface; use Oro\Bundle\ConfigBundle\Config\ConfigManager; use Oro\Bundle\LocaleBundle\Formatter\LanguageCodeFormatter; -class LanguageCodeFormatterTest extends \PHPUnit_Framework_TestCase +class LanguageCodeFormatterTest extends TestCase { /** @var LanguageCodeFormatter */ protected $formatter; diff --git a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/NumberFormatterTest.php b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/NumberFormatterTest.php index a76027cecaa..aa9c9b6c0d0 100644 --- a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/NumberFormatterTest.php +++ b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Formatter/NumberFormatterTest.php @@ -2,6 +2,8 @@ namespace Oro\Bundle\LocaleBundle\Tests\Unit\Formatter; +use PHPUnit\Framework\TestCase; + use Oro\Bundle\LocaleBundle\Formatter\NumberFormatter; use NumberFormatter as IntlNumberFormatter; use Symfony\Component\Intl\Util\IntlTestHelper; @@ -9,7 +11,7 @@ /** * @SuppressWarnings(PHPMD.TooManyMethods) */ -class NumberFormatterTest extends \PHPUnit_Framework_TestCase +class NumberFormatterTest extends TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject diff --git a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Model/CalendarTest.php b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Model/CalendarTest.php index 0c6055b013d..07bbe4fe943 100644 --- a/src/Oro/Bundle/LocaleBundle/Tests/Unit/Model/CalendarTest.php +++ b/src/Oro/Bundle/LocaleBundle/Tests/Unit/Model/CalendarTest.php @@ -2,11 +2,13 @@ namespace Oro\Bundle\LocaleBundle\Tests\Unit\Model; +use PHPUnit\Framework\TestCase; + use Oro\Bundle\LocaleBundle\Model\Calendar; use Symfony\Component\Intl\Util\IntlTestHelper; -class CalendarTest extends \PHPUnit_Framework_TestCase +class CalendarTest extends TestCase { /** * @var Calendar diff --git a/src/Oro/Bundle/NotificationBundle/Entity/Event.php b/src/Oro/Bundle/NotificationBundle/Entity/Event.php index a40cd9aa271..2e7ef13eebe 100644 --- a/src/Oro/Bundle/NotificationBundle/Entity/Event.php +++ b/src/Oro/Bundle/NotificationBundle/Entity/Event.php @@ -101,6 +101,6 @@ public function getDescription() public function __toString() { - return $this->name; + return (string)$this->name; } } diff --git a/src/Oro/Bundle/SearchBundle/Tests/Unit/Stub/EntityStub.php b/src/Oro/Bundle/SearchBundle/Tests/Unit/Stub/EntityStub.php index 40bea6019e3..d5bd6729aa8 100644 --- a/src/Oro/Bundle/SearchBundle/Tests/Unit/Stub/EntityStub.php +++ b/src/Oro/Bundle/SearchBundle/Tests/Unit/Stub/EntityStub.php @@ -29,7 +29,7 @@ public function __construct($id, $name = '') */ public function __toString() { - return $this->name; + return (string)$this->name; } /** diff --git a/src/Oro/Bundle/TestFrameworkBundle/Behat/Element/InputValue.php b/src/Oro/Bundle/TestFrameworkBundle/Behat/Element/InputValue.php index b650dfe9f55..d7ed015c55d 100644 --- a/src/Oro/Bundle/TestFrameworkBundle/Behat/Element/InputValue.php +++ b/src/Oro/Bundle/TestFrameworkBundle/Behat/Element/InputValue.php @@ -51,6 +51,6 @@ public function set($xpath, DriverInterface $driver) */ public function __toString() { - return $this->value; + return (string)$this->value; } } diff --git a/src/Oro/Bundle/TestFrameworkBundle/BehatStatisticExtension/Tests/Stub/InputStub.php b/src/Oro/Bundle/TestFrameworkBundle/BehatStatisticExtension/Tests/Stub/InputStub.php index 8311e047cec..106b5a62063 100644 --- a/src/Oro/Bundle/TestFrameworkBundle/BehatStatisticExtension/Tests/Stub/InputStub.php +++ b/src/Oro/Bundle/TestFrameworkBundle/BehatStatisticExtension/Tests/Stub/InputStub.php @@ -146,6 +146,6 @@ public function setInteractive($interactive) */ public function __toString() { - return $this->command; + return (string)$this->command; } } diff --git a/src/Oro/Bundle/TestFrameworkBundle/Test/Stub/ClassWithToString.php b/src/Oro/Bundle/TestFrameworkBundle/Test/Stub/ClassWithToString.php index 83167b468f7..1770b331088 100644 --- a/src/Oro/Bundle/TestFrameworkBundle/Test/Stub/ClassWithToString.php +++ b/src/Oro/Bundle/TestFrameworkBundle/Test/Stub/ClassWithToString.php @@ -20,6 +20,6 @@ public function __construct($representation = 'string representation') */ public function __toString() { - return $this->representation; + return (string)$this->representation; } } diff --git a/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/DebugTranslatorTest.php b/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/DebugTranslatorTest.php index 2f1d8275e4e..c0162f5e780 100644 --- a/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/DebugTranslatorTest.php +++ b/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/DebugTranslatorTest.php @@ -153,19 +153,13 @@ public function getCatalogue($locale, $dictionary) protected function getLoader() { $messages = $this->messages; - $obj = $this; - $loader = $this->createMock('Symfony\Component\Translation\Loader\LoaderInterface'); - $loader - ->expects($this->any()) + $loader = $this->createMock(LoaderInterface::class); + $loader->expects($this->any()) ->method('load') - ->will( - $this->returnCallback( - function () use ($obj, $messages) { - $locale = func_get_arg(1); - return $obj->getCatalogue($locale, $messages[$locale]); - } - ) - ); + ->willReturnCallback(function ($resource, $locale, $domain) use ($messages) { + return $this->getCatalogue($locale, $messages[$locale]); + }); + return $loader; } @@ -175,19 +169,21 @@ function () use ($obj, $messages) { */ protected function getStrategyProvider(array $fallbackLocales = []) { - /** @var TranslationStrategyInterface|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->createMock('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyInterface'); + $strategy = $this->createMock(TranslationStrategyInterface::class); + $strategyProvider = $this->createMock(TranslationStrategyProvider::class); - /** @var TranslationStrategyProvider|\PHPUnit_Framework_MockObject_MockObject $strategyProvider */ - $strategyProvider = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyProvider') - ->disableOriginalConstructor() - ->getMock(); $strategyProvider->expects($this->any()) ->method('getStrategy') ->willReturn($strategy); $strategyProvider->expects($this->any()) ->method('getFallbackLocales') - ->willReturn($fallbackLocales); + ->willReturnCallback(function ($strategy, $locale) use ($fallbackLocales) { + if ('en' !== $locale) { + return $fallbackLocales; + } + + return []; + }); return $strategyProvider; } @@ -197,7 +193,7 @@ protected function getStrategyProvider(array $fallbackLocales = []) * * @param LoaderInterface $loader * @param TranslationStrategyProvider $strategyProvider - * @return \PHPUnit_Framework_MockObject_MockObject + * @return ContainerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function getContainer($loader, $strategyProvider) { @@ -207,9 +203,8 @@ protected function getContainer($loader, $strategyProvider) ['oro_translation.strategy.provider', $exceptionFlag, $strategyProvider] ]; - $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $container - ->expects($this->any()) + $container = $this->createMock(ContainerInterface::class); + $container->expects($this->any()) ->method('get') ->willReturnMap($valueMap); diff --git a/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/TranslatorTest.php b/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/TranslatorTest.php index f855b187b11..46bc32b70d4 100644 --- a/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/TranslatorTest.php +++ b/src/Oro/Bundle/TranslationBundle/Tests/Unit/Translation/TranslatorTest.php @@ -10,6 +10,7 @@ use Oro\Bundle\TranslationBundle\Provider\TranslationDomainProvider; use Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyInterface; use Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyProvider; +use Oro\Bundle\TranslationBundle\Translation\DynamicTranslationMetadataCache; use Oro\Bundle\TranslationBundle\Translation\Translator; class TranslatorTest extends \PHPUnit_Framework_TestCase @@ -70,7 +71,10 @@ public function testGetTranslations($locale, array $expected) $locales = array_keys($this->messages); $_locale = !is_null($locale) ? $locale : reset($locales); $fallbackLocales = array_slice($locales, array_search($_locale, $locales) + 1); - $translator = $this->getTranslator($this->getLoader(), $this->getStrategyProvider($fallbackLocales)); + $translator = $this->getTranslator( + $this->getLoader(), + $this->getStrategyProvider($_locale, $fallbackLocales) + ); $translator->setLocale($_locale); $result = $translator->getTranslations(array('jsmessages', 'validators'), $locale); @@ -197,41 +201,38 @@ public function getCatalogue($locale, $dictionary) protected function getLoader() { $messages = $this->messages; - $obj = $this; - $loader = $this->createMock('Symfony\Component\Translation\Loader\LoaderInterface'); - $loader - ->expects($this->any()) + $loader = $this->createMock(LoaderInterface::class); + $loader->expects($this->any()) ->method('load') - ->will( - $this->returnCallback( - function () use ($obj, $messages) { - $locale = func_get_arg(1); - return $obj->getCatalogue($locale, $messages[$locale]); - } - ) - ); + ->willReturnCallback(function ($resource, $locale, $domain) use ($messages) { + return $this->getCatalogue($locale, $messages[$locale]); + }); + return $loader; } /** - * @param array $fallbackLocales + * @param string $locale + * @param array $fallbackLocales * @return TranslationStrategyProvider|\PHPUnit_Framework_MockObject_MockObject */ - protected function getStrategyProvider(array $fallbackLocales = []) + protected function getStrategyProvider($locale, array $fallbackLocales = []) { - /** @var TranslationStrategyInterface|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->createMock('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyInterface'); + $strategy = $this->createMock(TranslationStrategyInterface::class); + $strategyProvider = $this->createMock(TranslationStrategyProvider::class); - /** @var TranslationStrategyProvider|\PHPUnit_Framework_MockObject_MockObject $strategyProvider */ - $strategyProvider = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyProvider') - ->disableOriginalConstructor() - ->getMock(); $strategyProvider->expects($this->any()) ->method('getStrategy') ->willReturn($strategy); $strategyProvider->expects($this->any()) ->method('getFallbackLocales') - ->willReturn($fallbackLocales); + ->willReturnCallback(function ($strategy, $loc) use ($locale, $fallbackLocales) { + if ($loc === $locale) { + return $fallbackLocales; + } + + return []; + }); return $strategyProvider; } @@ -241,7 +242,7 @@ protected function getStrategyProvider(array $fallbackLocales = []) * * @param LoaderInterface $loader * @param TranslationStrategyProvider $strategyProvider - * @return \PHPUnit_Framework_MockObject_MockObject + * @return ContainerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function getContainer($loader, $strategyProvider) { @@ -251,9 +252,8 @@ protected function getContainer($loader, $strategyProvider) ['oro_translation.strategy.provider', $exceptionFlag, $strategyProvider] ]; - $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $container - ->expects($this->any()) + $container = $this->createMock(ContainerInterface::class); + $container->expects($this->any()) ->method('get') ->willReturnMap($valueMap); @@ -290,7 +290,7 @@ public function testHasTrans() { $locale = 'en'; $locales = array_keys($this->messages); - $translator = $this->getTranslator($this->getLoader(), $this->getStrategyProvider()); + $translator = $this->getTranslator($this->getLoader(), $this->getStrategyProvider($locale)); $translator->setLocale($locale); $translator->setFallbackLocales($locales); @@ -314,7 +314,7 @@ public function testGetFallbackTranslations() $translateKey = 'baz'; $message = $this->messages['en']['jsmessages'][$translateKey]; - $translator = $this->getTranslator($this->getLoader(), $this->getStrategyProvider($locales)); + $translator = $this->getTranslator($this->getLoader(), $this->getStrategyProvider($locale, $locales)); $translator->setLocale($locale); $result = $translator->trans($translateKey, [], 'jsmessages', $locale); @@ -325,11 +325,11 @@ public function testGetFallbackTranslations() public function testDynamicResourcesWithoutDatabaseTranslationMetadataCache() { $locale = 'en'; - $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container = $this->createMock(ContainerInterface::class); $container->expects($this->any()) ->method('get') - ->willReturn($this->getStrategyProvider()); - $translator = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Translation\Translator') + ->willReturn($this->getStrategyProvider($locale)); + $translator = $this->getMockBuilder(Translator::class) ->setConstructorArgs([$container, new MessageSelector(), [], ['resource_files' => []]]) ->setMethods(['addResource']) ->getMock(); @@ -348,26 +348,21 @@ public function testLoadingOfDynamicResources() ['code' => $locale, 'domain' => 'domain3'], ]; - $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container = $this->createMock(ContainerInterface::class); - $databaseCache = $this - ->getMockBuilder('Oro\Bundle\TranslationBundle\Translation\DynamicTranslationMetadataCache') - ->disableOriginalConstructor() - ->getMock(); - $translator = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Translation\Translator') + $databaseCache = $this->createMock(DynamicTranslationMetadataCache::class); + $translator = $this->getMockBuilder(Translator::class) ->setConstructorArgs([$container, new MessageSelector(), [], ['resource_files' => []]]) ->setMethods(['addResource']) ->getMock(); - $translationDomainProvider = $this->getMockBuilder(TranslationDomainProvider::class) - ->disableOriginalConstructor() - ->getMock(); + $translationDomainProvider = $this->createMock(TranslationDomainProvider::class); $translator->setLocale($locale); $translator->setDatabaseMetadataCache($databaseCache); $exceptionFlag = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE; $valueMap = [ - ['oro_translation.strategy.provider', $exceptionFlag, $this->getStrategyProvider()], + ['oro_translation.strategy.provider', $exceptionFlag, $this->getStrategyProvider($locale)], ['oro_translation.provider.translation_domain', $exceptionFlag, $translationDomainProvider], ]; @@ -398,19 +393,15 @@ public function testGetCatalogue() { $locale = 'en_US'; $strategyName = 'default'; - $allFallbackLocales = ['en_US', 'en']; + $allFallbackLocales = ['en']; $fallbackLocales = ['en']; - /** @var TranslationStrategyInterface|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->createMock('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyInterface'); + $strategy = $this->createMock(TranslationStrategyInterface::class); $strategy->expects($this->any()) ->method('getName') ->willReturn($strategyName); - /** @var TranslationStrategyProvider|\PHPUnit_Framework_MockObject_MockObject $strategyProvider */ - $strategyProvider = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyProvider') - ->disableOriginalConstructor() - ->getMock(); + $strategyProvider = $this->createMock(TranslationStrategyProvider::class); $strategyProvider->expects($this->any()) ->method('getStrategy') ->willReturn($strategy); @@ -420,8 +411,14 @@ public function testGetCatalogue() ->willReturn($allFallbackLocales); $strategyProvider->expects($this->any()) ->method('getFallbackLocales') - ->with($strategy, $locale) - ->willReturn($fallbackLocales); + ->with($strategy) + ->willReturnCallback(function ($strategy, $loc) use ($locale, $fallbackLocales) { + if ($loc === $locale) { + return $fallbackLocales; + } + + return []; + }); $translator = $this->getTranslator($this->getLoader(), $strategyProvider); @@ -441,20 +438,17 @@ public function testGetCatalogueStrategyChanged() $firstStrategyName = 'first'; $secondStrategyName = 'second'; - /** @var TranslationStrategyInterface|\PHPUnit_Framework_MockObject_MockObject $firstStrategy */ - $firstStrategy = $this->createMock('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyInterface'); + $firstStrategy = $this->createMock(TranslationStrategyInterface::class); $firstStrategy->expects($this->any()) ->method('getName') ->willReturn($firstStrategyName); - /** @var TranslationStrategyInterface|\PHPUnit_Framework_MockObject_MockObject $secondStrategy */ - $secondStrategy = $this->createMock('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyInterface'); + $secondStrategy = $this->createMock(TranslationStrategyInterface::class); $secondStrategy->expects($this->any()) ->method('getName') ->willReturn($secondStrategyName); - /** @var TranslationStrategyProvider|\PHPUnit_Framework_MockObject_MockObject $strategyProvider */ - $strategyProvider = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyProvider') + $strategyProvider = $this->getMockBuilder(TranslationStrategyProvider::class) ->disableOriginalConstructor() ->setMethods(['getAllFallbackLocales', 'getFallbackLocales']) ->getMock(); diff --git a/src/Oro/Bundle/TranslationBundle/Translation/Translator.php b/src/Oro/Bundle/TranslationBundle/Translation/Translator.php index 90942f94a25..9dcbe7aecb0 100644 --- a/src/Oro/Bundle/TranslationBundle/Translation/Translator.php +++ b/src/Oro/Bundle/TranslationBundle/Translation/Translator.php @@ -8,6 +8,7 @@ use Symfony\Bundle\FrameworkBundle\Translation\Translator as BaseTranslator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Loader\LoaderInterface; +use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\MessageSelector; use Oro\Bundle\TranslationBundle\Strategy\TranslationStrategyProvider; @@ -335,9 +336,22 @@ protected function loadCatalogue($locale) */ protected function initialize() { - parent::initialize(); - // add dynamic resources to the end to make sure that they override static translations + // add dynamic resources just before the initialization + // to be sure that they overrides static translations $this->registerDynamicResources(); + + parent::initialize(); + } + + /** + * {@inheritdoc} + */ + protected function initializeCatalogue($locale) + { + parent::initializeCatalogue($locale); + if (!isset($this->catalogues[$locale])) { + $this->catalogues[$locale] = new MessageCatalogue($locale); + } } /** @@ -395,7 +409,7 @@ protected function registerDynamicResources() } } - //prevents loding default locale many times (Default locale should be is default fallback locale) + // prevents loading default locale many times (Default locale should be in default fallback locale) if ($defaultLocale && !isset($this->catalogues[Translator::DEFAULT_LOCALE])) { $this->catalogues[Translator::DEFAULT_LOCALE] = $defaultLocale; } diff --git a/src/Oro/Bundle/UIBundle/Model/TreeItem.php b/src/Oro/Bundle/UIBundle/Model/TreeItem.php index 2e45223fa9c..9fb29c3166c 100644 --- a/src/Oro/Bundle/UIBundle/Model/TreeItem.php +++ b/src/Oro/Bundle/UIBundle/Model/TreeItem.php @@ -135,6 +135,6 @@ public function hasChildRecursive($key) */ public function __toString() { - return $this->label; + return (string)$this->label; } } diff --git a/src/Oro/Bundle/UserBundle/Entity/Role.php b/src/Oro/Bundle/UserBundle/Entity/Role.php index 056ff2cb69b..5f71f238d9d 100644 --- a/src/Oro/Bundle/UserBundle/Entity/Role.php +++ b/src/Oro/Bundle/UserBundle/Entity/Role.php @@ -93,15 +93,9 @@ public function __construct($role = '') $this->users = new ArrayCollection(); } - /** - * Unset the id on copy - */ public function __clone() { - if ($this->id) { - $this->id = null; - $this->setRole($this->role); - } + $this->id = null; } /** diff --git a/src/Oro/Bundle/WorkflowBundle/Entity/WorkflowStep.php b/src/Oro/Bundle/WorkflowBundle/Entity/WorkflowStep.php index 0b1d13bc90d..3838042cdcf 100644 --- a/src/Oro/Bundle/WorkflowBundle/Entity/WorkflowStep.php +++ b/src/Oro/Bundle/WorkflowBundle/Entity/WorkflowStep.php @@ -203,6 +203,6 @@ public function import(WorkflowStep $workflowStep) */ public function __toString() { - return $this->label; + return (string)$this->label; } } diff --git a/src/Oro/Bundle/WorkflowBundle/Model/Transition.php b/src/Oro/Bundle/WorkflowBundle/Model/Transition.php index d021697e222..8174cf98111 100644 --- a/src/Oro/Bundle/WorkflowBundle/Model/Transition.php +++ b/src/Oro/Bundle/WorkflowBundle/Model/Transition.php @@ -666,7 +666,7 @@ public function isScheduleCheckConditions() */ public function __toString() { - return $this->name; + return (string)$this->name; } /** diff --git a/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Model/TransitionTrigger/Verifier/TransitionEventTriggerExpressionVerifierTest.php b/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Model/TransitionTrigger/Verifier/TransitionEventTriggerExpressionVerifierTest.php index 07cff842e53..9cf3e7bd341 100644 --- a/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Model/TransitionTrigger/Verifier/TransitionEventTriggerExpressionVerifierTest.php +++ b/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Model/TransitionTrigger/Verifier/TransitionEventTriggerExpressionVerifierTest.php @@ -85,11 +85,12 @@ public function verifyFailures() return [ 'other' => [ 'Requirement field: "entity.a w < a.b" - syntax error: ' . - '"Unexpected token "name" of value "w" around position 10."', + '"Unexpected token "name" of value "w" around position 10 for expression `entity.a w < a.b`."', $this->buildEventTriggerWithExpression('entity.a w < a.b', EntityStub::class, EntityStub::class) ], 'variable' => [ - 'Requirement field: "e.a < a.b" - syntax error: "Variable "e" is not valid around position 1.". ' . + 'Requirement field: "e.a < a.b" - syntax error: ' . + '"Variable "e" is not valid around position 1 for expression `e.a < a.b`.". ' . 'Valid context variables are: ' . 'wd [Oro\Bundle\WorkflowBundle\Entity\WorkflowDefinition], ' . 'wi [Oro\Bundle\WorkflowBundle\Entity\WorkflowItem], ' . diff --git a/src/Oro/Component/Config/CumulativeResource.php b/src/Oro/Component/Config/CumulativeResource.php index 260f1ef0480..53cbd7368ac 100644 --- a/src/Oro/Component/Config/CumulativeResource.php +++ b/src/Oro/Component/Config/CumulativeResource.php @@ -147,7 +147,7 @@ public function getFound($bundleClass) */ public function __toString() { - return $this->resource; + return (string)$this->resource; } /** diff --git a/src/Oro/Component/ConfigExpression/CompiledPropertyPath.php b/src/Oro/Component/ConfigExpression/CompiledPropertyPath.php index 9cf71020cda..19e614b0819 100644 --- a/src/Oro/Component/ConfigExpression/CompiledPropertyPath.php +++ b/src/Oro/Component/ConfigExpression/CompiledPropertyPath.php @@ -44,7 +44,7 @@ public function __construct($path, array $elements, array $isIndex) */ public function __toString() { - return $this->path; + return (string)$this->path; } /** diff --git a/src/Oro/Component/EntitySerializer/Tests/Unit/Fixtures/Entity/Category.php b/src/Oro/Component/EntitySerializer/Tests/Unit/Fixtures/Entity/Category.php index 245c62ef6f2..683ab760b01 100644 --- a/src/Oro/Component/EntitySerializer/Tests/Unit/Fixtures/Entity/Category.php +++ b/src/Oro/Component/EntitySerializer/Tests/Unit/Fixtures/Entity/Category.php @@ -78,6 +78,6 @@ public function setLabel($label) */ public function __toString() { - return $this->name; + return (string)$this->name; } } diff --git a/src/Oro/Component/Routing/Tests/Unit/Resolver/TestResource.php b/src/Oro/Component/Routing/Tests/Unit/Resolver/TestResource.php index d74caddd637..53009b469a8 100644 --- a/src/Oro/Component/Routing/Tests/Unit/Resolver/TestResource.php +++ b/src/Oro/Component/Routing/Tests/Unit/Resolver/TestResource.php @@ -22,7 +22,7 @@ public function __construct($name) */ public function __toString() { - return $this->name; + return (string)$this->name; } /** diff --git a/src/Oro/Component/Testing/Unit/Command/Stub/InputStub.php b/src/Oro/Component/Testing/Unit/Command/Stub/InputStub.php index 37df64e71ae..3fd35b8390a 100644 --- a/src/Oro/Component/Testing/Unit/Command/Stub/InputStub.php +++ b/src/Oro/Component/Testing/Unit/Command/Stub/InputStub.php @@ -146,6 +146,6 @@ public function setInteractive($interactive) */ public function __toString() { - return $this->command; + return (string)$this->command; } }