diff --git a/.travis.yml b/.travis.yml index 82ffdaf3..c82b8018 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,29 +6,42 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 matrix: fast_finish: true + allow_failures: + - php: 7.2 + exclude: + - php: 5.6 + env: SYMFONY_VERSION=4.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha + - php: 7.0 + env: SYMFONY_VERSION=4.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha + - php: 7.2 + env: SYMFONY_VERSION=2.8.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha services: - mongodb env: - - SYMFONY_VERSION=2.8.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test - - SYMFONY_VERSION=3.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test - - SYMFONY_VERSION=3.1.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test - - SYMFONY_VERSION=3.2.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test - - SYMFONY_VERSION=3.3.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test - + - SYMFONY_VERSION=2.8.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha +# - SYMFONY_VERSION=3.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha +# - SYMFONY_VERSION=3.1.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha +# - SYMFONY_VERSION=3.2.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha +# - SYMFONY_VERSION=3.3.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha +# - SYMFONY_VERSION=3.4.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha + - SYMFONY_VERSION=4.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha cache: directories: - $HOME/.composer/cache before_install: + - if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi; + - if [ "$DEPENDENCIES" = "alpha" ]; then composer config minimum-stability alpha; fi; - if [ -x .travis/before_install.sh ]; then .travis/before_install.sh; fi; install: - if [ -x .travis/install.sh ]; then .travis/install.sh; fi; script: - - php vendor/bin/phpunit -v \ No newline at end of file + - php vendor/bin/phpunit -v diff --git a/.travis/before_install.sh b/.travis/before_install.sh index afc744df..6e3658aa 100755 --- a/.travis/before_install.sh +++ b/.travis/before_install.sh @@ -10,7 +10,7 @@ if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ]; then TRAVIS_INI_FILE="$PHP_INI_DIR/travis.ini" echo "memory_limit=3072M" >> "$TRAVIS_INI_FILE" - if [ "$TRAVIS_PHP_VERSION" '<' '7.0' ]; then + if [ "$TRAVIS_PHP_VERSION" '<' '7.0' ]; then echo "extension=mongo.so" >> "$TRAVIS_INI_FILE" else echo "extension=mongodb.so" >> "$TRAVIS_INI_FILE" diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php index 473432e4..9def8d06 100644 --- a/Command/ImportTranslationsCommand.php +++ b/Command/ImportTranslationsCommand.php @@ -9,6 +9,8 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Translation\TranslatorInterface; /** * Imports translation files content in the database. @@ -19,6 +21,21 @@ */ class ImportTranslationsCommand extends ContainerAwareCommand { + /** + * @var TranslatorInterface + */ + private $translator; + + /** + * @param TranslatorInterface $translator + */ + public function __construct(TranslatorInterface $translator) + { + parent::__construct(); + + $this->translator = $translator; + } + /** * @var \Symfony\Component\Console\Input\InputInterface */ @@ -71,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($bundleName) { $bundle = $this->getApplication()->getKernel()->getBundle($bundleName); - if (null !== $bundle->getParent()) { + if (Kernel::VERSION_ID < 40000 && null !== $bundle->getParent()) { // due to symfony's bundle inheritance if a bundle has a parent it is fetched first. // so we tell getBundle to NOT fetch the first if a parent is present $bundles = $this->getApplication()->getKernel()->getBundle($bundle->getParent(), false); @@ -114,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($this->input->getOption('cache-clear')) { $this->output->writeln('Removing translations cache files ...'); - $this->getContainer()->get('translator')->removeLocalesCacheFiles($locales); + $this->translator->removeLocalesCacheFiles($locales); } } diff --git a/DependencyInjection/LexikTranslationExtension.php b/DependencyInjection/LexikTranslationExtension.php index 08cd9e47..2ba0d3ef 100644 --- a/DependencyInjection/LexikTranslationExtension.php +++ b/DependencyInjection/LexikTranslationExtension.php @@ -76,7 +76,16 @@ public function buildTranslatorDefinition(ContainerBuilder $container) $translator = new Definition(); $translator->setClass('%lexik_translation.translator.class%'); - if (Kernel::VERSION_ID >= 30300) { + if (Kernel::VERSION_ID >= 40000) { + $arguments = [ + new Reference('service_container'), // Will be replaced by service locator + new Reference('translator.formatter.default'), + new Parameter('kernel.default_locale'), + [], // translation loaders + new Parameter('lexik_translation.translator.options') + ]; + $translator->setPublic(true); + } elseif (Kernel::VERSION_ID >= 30300) { $arguments = [ new Reference('service_container'), // Will be replaced by service locator new Reference('translator.selector'), diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 97f68f69..86f3de0b 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -1,8 +1,8 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> Lexik\Bundle\TranslationBundle\Translation\Translator @@ -45,6 +45,8 @@ Lexik\Bundle\TranslationBundle\Util\Profiler\TokenFinder + Lexik\Bundle\TranslationBundle\Command\ImportTranslationsCommand + false 15 @@ -62,7 +64,7 @@ - + %kernel.root_dir% @@ -73,12 +75,12 @@ %kernel.root_dir% - + %lexik_translation.managed_locales% - + @@ -89,7 +91,7 @@ - + @@ -110,12 +112,12 @@ - + %lexik_translation.storage.type% - + @@ -129,13 +131,13 @@ - + - + @@ -150,5 +152,9 @@ + + + + diff --git a/Tests/Command/ImportTranslationsCommandTest.php b/Tests/Command/ImportTranslationsCommandTest.php index beb1e7db..35ff592f 100644 --- a/Tests/Command/ImportTranslationsCommandTest.php +++ b/Tests/Command/ImportTranslationsCommandTest.php @@ -79,7 +79,7 @@ private static function runCommand($commandName, $options = array()) */ public function testExecute() { - static::$application->add(new ImportTranslationsCommand()); + static::$application->add(new ImportTranslationsCommand(self::$kernel->getContainer()->get('lexik_translation.translator'))); $command = static::$application->find("lexik:translations:import"); $command->setContainer(static::$kernel->getContainer()); diff --git a/Tests/Unit/Translation/Exporter/YamlExporterTest.php b/Tests/Unit/Translation/Exporter/YamlExporterTest.php index b0aed14b..31f9db1a 100644 --- a/Tests/Unit/Translation/Exporter/YamlExporterTest.php +++ b/Tests/Unit/Translation/Exporter/YamlExporterTest.php @@ -34,7 +34,7 @@ public function testExport() // export empty array $exporter->export($outFile, array()); $expectedContent = '{ }'; - $this->assertEquals($expectedContent, file_get_contents($outFile)); + $this->assertEquals($expectedContent, trim(file_get_contents($outFile))); // export array with values $exporter->export($outFile, array( diff --git a/Tests/Unit/Translation/TranslatorTest.php b/Tests/Unit/Translation/TranslatorTest.php index 4503b43d..3df5ec3b 100644 --- a/Tests/Unit/Translation/TranslatorTest.php +++ b/Tests/Unit/Translation/TranslatorTest.php @@ -7,6 +7,7 @@ use Lexik\Bundle\TranslationBundle\Tests\Unit\BaseUnitTestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Translation\Formatter\MessageFormatter; use Symfony\Component\Translation\MessageSelector; use Symfony\Component\DependencyInjection\Container; @@ -129,6 +130,10 @@ protected function createTranslator($em, $cacheDir) 'cache_dir' => $cacheDir, ); + if (Kernel::VERSION_ID >= 40000) { + return new TranslatorMock($container, new MessageFormatter(), 'en', $loaderIds, $options); + } + if (Kernel::VERSION_ID >= 30300) { return new TranslatorMock($container, new MessageSelector(), 'en', $loaderIds, $options); } diff --git a/Translation/Exporter/YamlExporter.php b/Translation/Exporter/YamlExporter.php index 3d07de08..1b65eade 100644 --- a/Translation/Exporter/YamlExporter.php +++ b/Translation/Exporter/YamlExporter.php @@ -32,9 +32,7 @@ public function export($file, $translations) $translations = $this->flattenArray($result); } - $ymlDumper = new Dumper(); - $ymlDumper->setIndentation(2); - $ymlContent = $ymlDumper->dump($translations, 10); + $ymlContent = (new Dumper())->dump($translations, 10, 0); $bytes = file_put_contents($file, $ymlContent); diff --git a/composer.json b/composer.json index 7ace3805..8f5e1f9f 100644 --- a/composer.json +++ b/composer.json @@ -18,14 +18,15 @@ ], "require": { "php": "^5.6 || ^7.0", - "symfony/framework-bundle": "~2.8|~3.0" + "symfony/framework-bundle": "~2.8|~3.0|~4.0" }, "require-dev": { "doctrine/orm": "^2.2.3", "doctrine/doctrine-bundle": "~1.2", "doctrine/data-fixtures": "~1.1", "doctrine/mongodb-odm-bundle": "~3.0", - "propel/propel-bundle": "~3.0@dev", + "propel/propel-bundle": "^3.0@dev|^4.0@dev", + "propel/propel": "@dev", "phpunit/phpunit": "^5.7" }, "suggest": { @@ -35,6 +36,11 @@ "autoload": { "psr-4": { "Lexik\\Bundle\\TranslationBundle\\": "" } }, + "autoload-dev": { + "classmap": [ + "Tests/app/AppKernel.php" + ] + }, "extra": { "branch-alias": { "dev-master": "4.x.x-dev" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8580414b..55619202 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,6 +19,7 @@ +