Skip to content

Commit

Permalink
BAP-15849: Upgrade 2.x LTS releases to latest Symfony 2.8.x version (…
Browse files Browse the repository at this point in the history
…#15379)
  • Loading branch information
vsoroka authored and alex-n-2k7 committed Dec 13, 2017
1 parent a98cb16 commit 22b7dc6
Show file tree
Hide file tree
Showing 35 changed files with 354 additions and 123 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/ActionBundle/Model/Parameter.php
Expand Up @@ -140,6 +140,6 @@ public function isRequired()
*/
public function __toString()
{
return $this->name;
return (string)$this->name;
}
}
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EmailBundle/Entity/Mailbox.php
Expand Up @@ -433,7 +433,7 @@ public function removeAuthorizedUser(User $user)
*/
public function __toString()
{
return $this->getLabel();
return (string)$this->getLabel();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EmailBundle/Form/Model/SmtpSettings.php
Expand Up @@ -61,7 +61,7 @@ public function __construct(
*/
public function __toString()
{
return $this->getHost();
return (string)$this->getHost();
}

/**
Expand Down
Expand Up @@ -357,7 +357,7 @@ public function setOrganization(OrganizationInterface $organization = null)
*/
public function __toString()
{
return $this->getDefaultLabel()->getString();
return (string)$this->getDefaultLabel()->getString();
}

/**
Expand Down
Expand Up @@ -161,6 +161,6 @@ public function getLocale()
*/
public function __toString()
{
return $this->name;
return (string)$this->name;
}
}
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/FormBundle/Form/Type/ChoiceListItem.php
Expand Up @@ -129,6 +129,6 @@ public function setAttributes(array $attributes)
*/
public function __toString()
{
return $this->label;
return (string)$this->label;
}
}
Expand Up @@ -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]
],
];
}
}
@@ -0,0 +1,134 @@
<?php

namespace Oro\Bundle\InstallerBundle\EventListener;

use Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* @todo temporary workaround. will be removed in BAP-16194
*/
class AssetsInstallCommandListener
{
/** @var Filesystem */
private $filesystem;

/** @var string */
private $kernelRootDir;

/**
* @param Filesystem $filesystem
* @param string $kernelRootDir
*/
public function __construct(Filesystem $filesystem, $kernelRootDir)
{
$this->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;
}
}
9 changes: 9 additions & 0 deletions src/Oro/Bundle/InstallerBundle/Resources/config/services.yml
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion src/Oro/Bundle/IntegrationBundle/Test/FakeRestResponse.php
Expand Up @@ -35,7 +35,7 @@ public function __construct($statusCode, array $headers = [], $body = '')
*/
public function __toString()
{
return $this->getMessage();
return (string)$this->getMessage();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/LocaleBundle/Entity/Localization.php
Expand Up @@ -140,7 +140,7 @@ public function __construct()
*/
public function __toString()
{
return $this->getName();
return (string)$this->getName();
}

/**
Expand Down
Expand Up @@ -2,14 +2,16 @@

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\FormattingCodeFormatter;
use Oro\Bundle\LocaleBundle\Formatter\LanguageCodeFormatter;

class FormattingCodeFormatterTest extends \PHPUnit_Framework_TestCase
class FormattingCodeFormatterTest extends TestCase
{
/** @var LanguageCodeFormatter */
protected $formatter;
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 22b7dc6

Please sign in to comment.