From cc23db90bf23d995b4ce24976aeb8eca8c56ab6d Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Tue, 15 Nov 2016 12:30:09 +0100 Subject: [PATCH 01/13] Multi project translations --- Command/CheckTranslationProgressCommand.php | 9 ++++++--- Command/Command.php | 12 ++--------- DependencyInjection/Configuration.php | 3 +-- .../OpenClassroomsOneSkyExtension.php | 1 - Gateways/Impl/LanguageGatewayImpl.php | 20 +++++-------------- Gateways/LanguageGateway.php | 2 +- Model/FileFactory.php | 4 ++-- Model/Impl/FileFactoryImpl.php | 18 ++++------------- Model/Impl/LanguageFactoryImpl.php | 4 ++-- Model/Impl/LanguageImpl.php | 3 ++- Model/Language.php | 13 ++++++++++++ Model/LanguageFactory.php | 2 +- README.md | 4 ++-- Resources/config/services.xml | 6 ------ Services/Impl/LanguageServiceImpl.php | 4 ++-- Services/Impl/TranslationServiceImpl.php | 18 ++++++++++------- Services/LanguageService.php | 2 +- Tests/Command/CommandTestCase.php | 8 +------- .../Gateways/InMemoryLanguageGateway.php | 6 +++--- .../Doubles/Services/LanguageServiceMock.php | 9 ++++++--- Tests/Fixtures/Resources/config/config.yml | 6 ++++-- .../Gateways/Impl/LanguageGatewayImplTest.php | 9 +++++---- .../Services/Impl/LanguageServiceImplTest.php | 6 ++++-- .../Impl/TranslationServiceImplTest.php | 13 ++++++------ 24 files changed, 84 insertions(+), 98 deletions(-) diff --git a/Command/CheckTranslationProgressCommand.php b/Command/CheckTranslationProgressCommand.php index 7755c9f..1aae50a 100644 --- a/Command/CheckTranslationProgressCommand.php +++ b/Command/CheckTranslationProgressCommand.php @@ -46,17 +46,20 @@ protected function getCommandDescription() protected function execute(InputInterface $input, OutputInterface $output) { + $projectsIds = array_keys($this->getContainer()->getParameter('openclassrooms_onesky.file_paths')); $output->writeln('Check translations progress'); - $languages = $this->getContainer() + $languages = []; + foreach ($projectsIds as $projectId) + $languages += $this->getContainer() ->get('openclassrooms.onesky.services.language_service') - ->getLanguages($input->getOption('locale')); + ->getLanguages($projectId, $input->getOption('locale')); $table = new Table($output); $table ->setHeaders(['Locale', 'Progression']) ->setRows( array_map( function (Language $language) { - return [$language->getLocale(), $language->getTranslationProgress()]; + return [$language->getLocale()." ".$language->getProjectId(), $language->getTranslationProgress()]; }, $languages ) diff --git a/Command/Command.php b/Command/Command.php index 0718f88..4c30d34 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -49,7 +49,7 @@ protected function handlePullDisplay(OutputInterface $output) $dispatcher->addListener( TranslationPrePullEvent::getEventName(), function (TranslationPrePullEvent $event) use ($output) { - $output->writeln('Pulling for project id '.$this->getProjectId()."\n"); + $output->writeln("Pulling files \n"); $this->progressBar = new ProgressBar($output, $event->getExportFilesCount()); $this->progressBar->setFormat(PROGRESS_BAR_FORMAT); $this->getProgressBar()->start(); @@ -87,14 +87,6 @@ function (ExportFile $file) { ); } - /** - * @return string - */ - private function getProjectId() - { - return $this->getContainer()->getParameter('openclassrooms_onesky.project_id'); - } - /** * @return ProgressBar */ @@ -109,7 +101,7 @@ protected function handlePushDisplay(OutputInterface $output) $dispatcher->addListener( TranslationPrePushEvent::getEventName(), function (TranslationPrePushEvent $event) use ($output) { - $output->writeln('Pushing for project id '.$this->getProjectId()."\n"); + $output->writeln("Pushing files \n"); $this->progressBar = new ProgressBar($output, $event->getUploadFilesCount()); $this->progressBar->setFormat(PROGRESS_BAR_FORMAT); $this->getProgressBar()->start(); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d69afb8..cba0e03 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -20,11 +20,10 @@ public function getConfigTreeBuilder() $rootNode->children() ->scalarNode('api_key')->isRequired()->cannotBeEmpty()->end() ->scalarNode('api_secret')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('project_id')->isRequired()->cannotBeEmpty()->end() ->scalarNode('file_format')->cannotBeEmpty()->defaultValue('xliff')->end() ->scalarNode('source_locale')->cannotBeEmpty()->defaultValue('en')->end() ->arrayNode('locales')->isRequired()->cannotBeEmpty()->prototype('scalar')->end()->end() - ->arrayNode('file_paths')->isRequired()->cannotBeEmpty()->prototype('scalar')->end()->end() + ->arrayNode('file_paths')->isRequired()->cannotBeEmpty()->prototype('array')->prototype('scalar')->end()->end()->end() ->scalarNode('keep_all_strings')->cannotBeEmpty()->defaultValue(true)->end() ->end(); diff --git a/DependencyInjection/OpenClassroomsOneSkyExtension.php b/DependencyInjection/OpenClassroomsOneSkyExtension.php index d712834..8cb6cbd 100644 --- a/DependencyInjection/OpenClassroomsOneSkyExtension.php +++ b/DependencyInjection/OpenClassroomsOneSkyExtension.php @@ -27,7 +27,6 @@ private function processParameters(ContainerBuilder $container, array $config) { $container->setParameter('openclassrooms_onesky.api_key', $config['api_key']); $container->setParameter('openclassrooms_onesky.api_secret', $config['api_secret']); - $container->setParameter('openclassrooms_onesky.project_id', $config['project_id']); $container->setParameter('openclassrooms_onesky.source_locale', $config['source_locale']); $container->setParameter('openclassrooms_onesky.locales', $config['locales']); $container->setParameter('openclassrooms_onesky.file_format', $config['file_format']); diff --git a/Gateways/Impl/LanguageGatewayImpl.php b/Gateways/Impl/LanguageGatewayImpl.php index 45db21d..955b4d7 100644 --- a/Gateways/Impl/LanguageGatewayImpl.php +++ b/Gateways/Impl/LanguageGatewayImpl.php @@ -24,25 +24,20 @@ class LanguageGatewayImpl implements LanguageGateway */ private $languageFactory; - /** - * @var int - */ - private $projectId; - /** * @return \OpenClassrooms\Bundle\OneSkyBundle\Model\Language[] * * @throws LanguageException * @throws LanguageNotFoundException */ - public function findLanguages(array $locales) + public function findLanguages(array $locales, $projectId) { - $jsonResponse = $this->client->projects(self::LANGUAGES_METHOD, ['project_id' => $this->projectId]); + $jsonResponse = $this->client->projects(self::LANGUAGES_METHOD, ['project_id' => $projectId]); $response = json_decode($jsonResponse, true); $this->checkResponse($response, $jsonResponse); - $languages = $this->createLanguages($response); + $languages = $this->createLanguages($response, $projectId); $requestedLanguages = []; foreach ($locales as $locale) { if (isset($languages[$locale])) { @@ -68,9 +63,9 @@ private function checkResponse($response, $jsonResponse) /** * @return \OpenClassrooms\Bundle\OneSkyBundle\Model\Language[] */ - private function createLanguages($response) + private function createLanguages($response, $projectId) { - $languages = $this->languageFactory->createFromCollection($response['data']); + $languages = $this->languageFactory->createFromCollection($response['data'], $projectId); return $this->formatLanguages($languages); } @@ -99,9 +94,4 @@ public function setLanguageFactory(LanguageFactory $languageFactory) { $this->languageFactory = $languageFactory; } - - public function setProjectId($projectId) - { - $this->projectId = $projectId; - } } diff --git a/Gateways/LanguageGateway.php b/Gateways/LanguageGateway.php index dcae2a7..821655e 100644 --- a/Gateways/LanguageGateway.php +++ b/Gateways/LanguageGateway.php @@ -14,5 +14,5 @@ interface LanguageGateway * * @throws LanguageException */ - public function findLanguages(array $locales); + public function findLanguages(array $locales, $projectId); } diff --git a/Model/FileFactory.php b/Model/FileFactory.php index af8b76e..b3061e3 100644 --- a/Model/FileFactory.php +++ b/Model/FileFactory.php @@ -10,10 +10,10 @@ interface FileFactory /** * @return ExportFile */ - public function createExportFile($sourceFilePath, $requestedLocale); + public function createExportFile($sourceFilePath, $projectId, $requestedLocale); /** * @return UploadFile */ - public function createUploadFile($filePath, $locale = null); + public function createUploadFile($filePath, $projectId, $locale = null); } diff --git a/Model/Impl/FileFactoryImpl.php b/Model/Impl/FileFactoryImpl.php index 9e96347..72e4887 100644 --- a/Model/Impl/FileFactoryImpl.php +++ b/Model/Impl/FileFactoryImpl.php @@ -20,11 +20,6 @@ class FileFactoryImpl implements FileFactory */ private $kernelRootDir; - /** - * @var int - */ - private $projectId; - /** * @var string */ @@ -38,9 +33,9 @@ class FileFactoryImpl implements FileFactory /** * @return ExportFile */ - public function createExportFile($sourceFilePath, $requestedLocale) + public function createExportFile($sourceFilePath, $projectId, $requestedLocale) { - return new ExportFileImpl($this->projectId, $sourceFilePath, $this->getProjectDirectory(), $requestedLocale); + return new ExportFileImpl($projectId, $sourceFilePath, $this->getProjectDirectory(), $requestedLocale); } /** @@ -54,10 +49,10 @@ private function getProjectDirectory() /** * {@inheritdoc} */ - public function createUploadFile($filePath, $locale = null) + public function createUploadFile($filePath, $projectId, $locale = null) { $file = new UploadFileImpl( - $this->projectId, + $projectId, $filePath, $this->getProjectDirectory(), $this->fileFormat, @@ -84,11 +79,6 @@ public function setKernelRootDir($kernelRootDir) $this->kernelRootDir = $kernelRootDir; } - public function setProjectId($projectId) - { - $this->projectId = $projectId; - } - public function setSourceLocale($sourceLocale) { $this->sourceLocale = $sourceLocale; diff --git a/Model/Impl/LanguageFactoryImpl.php b/Model/Impl/LanguageFactoryImpl.php index f4d40ad..c2191a5 100644 --- a/Model/Impl/LanguageFactoryImpl.php +++ b/Model/Impl/LanguageFactoryImpl.php @@ -12,11 +12,11 @@ class LanguageFactoryImpl implements LanguageFactory /** * {@inheritdoc} */ - public function createFromCollection(array $data) + public function createFromCollection(array $data, $projectId) { $languages = []; foreach ($data as $item) { - $languages[] = new LanguageImpl($item); + $languages[] = new LanguageImpl($item, $projectId); } return $languages; diff --git a/Model/Impl/LanguageImpl.php b/Model/Impl/LanguageImpl.php index 519d792..a09d2aa 100644 --- a/Model/Impl/LanguageImpl.php +++ b/Model/Impl/LanguageImpl.php @@ -9,9 +9,10 @@ */ class LanguageImpl extends Language { - public function __construct(array $data) + public function __construct(array $data, $projectId) { $this->locale = $data['locale']; $this->translationProgress = $data['translation_progress']; + $this->projectId = $projectId; } } diff --git a/Model/Language.php b/Model/Language.php index 5f1cd58..5f050b3 100644 --- a/Model/Language.php +++ b/Model/Language.php @@ -7,6 +7,11 @@ */ abstract class Language { + /** + * @var string + */ + protected $projectId; + /** * @var string */ @@ -40,4 +45,12 @@ public function getTranslationProgress() { return $this->translationProgress; } + + /** + * @return string + */ + public function getProjectId() + { + return $this->projectId; + } } diff --git a/Model/LanguageFactory.php b/Model/LanguageFactory.php index dcfbfc6..fef7ca0 100644 --- a/Model/LanguageFactory.php +++ b/Model/LanguageFactory.php @@ -10,5 +10,5 @@ interface LanguageFactory /** * @return Language[] */ - public function createFromCollection(array $data); + public function createFromCollection(array $data, $projectId); } diff --git a/README.md b/README.md index 0d196d4..6e2b1a2 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,14 @@ $bundles = array( openclassrooms_onesky: api_key: %onesky.api_key% api_secret: %onesky.api_secret% - project_id: %onesky.project_id% source_locale: %source_locale% #optional, default en locales: - fr - es file_format: %onesky.file_format% #optional, default xliff file_paths: - - %path.to.translations.files.directory% + %onesky.project_id%: + - %path.to.translations.files.directory% keep_all_strings: false # default true ``` diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 16894ec..b396710 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -24,9 +24,6 @@ - - %openclassrooms_onesky.project_id% - @@ -38,9 +35,6 @@ %kernel.root_dir% - - %openclassrooms_onesky.project_id% - %openclassrooms_onesky.source_locale% diff --git a/Services/Impl/LanguageServiceImpl.php b/Services/Impl/LanguageServiceImpl.php index 3e5b28d..0f0a56d 100644 --- a/Services/Impl/LanguageServiceImpl.php +++ b/Services/Impl/LanguageServiceImpl.php @@ -23,13 +23,13 @@ class LanguageServiceImpl implements LanguageService /** * @return \OpenClassrooms\Bundle\OneSkyBundle\Model\Language[] */ - public function getLanguages(array $locales = []) + public function getLanguages($projectId, array $locales = []) { if (empty($locales)) { $locales = $this->requestedLocales; } - return $this->languageGateway->findLanguages($locales); + return $this->languageGateway->findLanguages($locales, $projectId); } public function setLanguageGateway(LanguageGateway $languageGateway) diff --git a/Services/Impl/TranslationServiceImpl.php b/Services/Impl/TranslationServiceImpl.php index e0943b1..e143acd 100644 --- a/Services/Impl/TranslationServiceImpl.php +++ b/Services/Impl/TranslationServiceImpl.php @@ -71,9 +71,11 @@ public function pull(array $filePaths, array $locales = []) { $exportFiles = []; /** @var SplFileInfo $file */ - foreach ($this->getFiles($filePaths, $this->getSourceLocales()) as $file) { - foreach ($this->getRequestedLocales($locales) as $locale) { - $exportFiles[] = $this->fileFactory->createExportFile($file->getRealPath(), $locale); + foreach ($this->getFilePaths($filePaths) as $projectId => &$paths) { + foreach ($this->getFiles($paths, $this->getSourceLocales()) as $file) { + foreach ($this->getRequestedLocales($locales) as $locale) { + $exportFiles[] = $this->fileFactory->createExportFile($file->getRealPath(), $projectId, $locale); + } } } @@ -95,11 +97,11 @@ public function pull(array $filePaths, array $locales = []) /** * @return Finder */ - private function getFiles(array $filePaths, array $locales) + private function getFiles(array $paths, array $locales) { return Finder::create() ->files() - ->in($this->getFilePaths($filePaths)) + ->in($paths) ->name('*.{'.implode(',', $locales).'}.'.$this->fileFormat); } @@ -135,8 +137,10 @@ public function push(array $filePaths, array $locales = []) $uploadFiles = []; /* @var SplFileInfo $file */ foreach ($this->getSourceLocales($locales) as $locale) { - foreach ($this->getFiles($filePaths, [$locale]) as $file) { - $uploadFiles[] = $this->fileFactory->createUploadFile($file->getRealPath(), $locale); + foreach ($filePaths as $projectId => &$paths) { + foreach ($this->getFiles($paths, [$locale]) as $file) { + $uploadFiles[] = $this->fileFactory->createUploadFile($file->getRealPath(), $projectId, $locale); + } } } diff --git a/Services/LanguageService.php b/Services/LanguageService.php index 1f79183..b30f399 100644 --- a/Services/LanguageService.php +++ b/Services/LanguageService.php @@ -10,5 +10,5 @@ interface LanguageService /** * @return \OpenClassrooms\Bundle\OneSkyBundle\Model\Language[] */ - public function getLanguages(array $locales = []); + public function getLanguages($projectId, array $locales = []); } diff --git a/Tests/Command/CommandTestCase.php b/Tests/Command/CommandTestCase.php index 74ebdab..0eb208d 100644 --- a/Tests/Command/CommandTestCase.php +++ b/Tests/Command/CommandTestCase.php @@ -23,11 +23,6 @@ trait CommandTestCase */ public static $locales = ['fr']; - /** - * @var int - */ - public static $projectId = 1; - /** * @return ContainerInterface */ @@ -37,9 +32,8 @@ protected function getContainer() return new ContainerForTest( [ - 'openclassrooms_onesky.file_paths' => [self::$filePaths], + 'openclassrooms_onesky.file_paths' => [ 1 => [self::$filePaths]], 'openclassrooms_onesky.requestedLocales' => self::$locales, - 'openclassrooms_onesky.project_id' => self::$projectId, 'kernel.root_dir' => __DIR__.'/../', ], [ diff --git a/Tests/Doubles/Gateways/InMemoryLanguageGateway.php b/Tests/Doubles/Gateways/InMemoryLanguageGateway.php index 5f6a5ff..f22ea02 100644 --- a/Tests/Doubles/Gateways/InMemoryLanguageGateway.php +++ b/Tests/Doubles/Gateways/InMemoryLanguageGateway.php @@ -24,14 +24,14 @@ public function __construct(array $languages = []) /** * {@inheritdoc} */ - public function findLanguages(array $locales = []) + public function findLanguages(array $locales = [], $projectId) { $languages = []; foreach ($locales as $locale) { - if (!isset(self::$languages[$locale])) { + if (!isset(self::$languages[$projectId][$locale])) { throw new LanguageNotFoundException(); } else { - $languages[] = self::$languages[$locale]; + $languages[] = self::$languages[$projectId][$locale]; } } diff --git a/Tests/Doubles/Services/LanguageServiceMock.php b/Tests/Doubles/Services/LanguageServiceMock.php index 0dcf533..655f16c 100644 --- a/Tests/Doubles/Services/LanguageServiceMock.php +++ b/Tests/Doubles/Services/LanguageServiceMock.php @@ -35,11 +35,14 @@ public function __construct() /** * {@inheritdoc} */ - public function getLanguages(array $locales = []) + public function getLanguages($projectId, array $locales = []) { self::$calledGetLanguages = true; - self::$locales = $locales; + self::$locales[$projectId] = $locales; - return self::$languages; + if(isset(self::$languages[$projectId])) + return self::$languages[$projectId]; + else + return array(); } } diff --git a/Tests/Fixtures/Resources/config/config.yml b/Tests/Fixtures/Resources/config/config.yml index d8fc163..b98dea8 100644 --- a/Tests/Fixtures/Resources/config/config.yml +++ b/Tests/Fixtures/Resources/config/config.yml @@ -1,11 +1,13 @@ openclassrooms_onesky: api_key: api_key api_secret: api_secret - project_id: 1 file_format: yml source_locale: en locales: - fr - es file_paths: - - / + 1: + - /1/ + 2: + - /2/ \ No newline at end of file diff --git a/Tests/Gateways/Impl/LanguageGatewayImplTest.php b/Tests/Gateways/Impl/LanguageGatewayImplTest.php index 7f9702a..6176bd8 100644 --- a/Tests/Gateways/Impl/LanguageGatewayImplTest.php +++ b/Tests/Gateways/Impl/LanguageGatewayImplTest.php @@ -20,6 +20,8 @@ class LanguageGatewayImplTest extends \PHPUnit_Framework_TestCase */ private $gateway; + const PROJECT_ID = 1; + /** * @test * @expectedException \OpenClassrooms\Bundle\OneSkyBundle\Gateways\LanguageException @@ -27,7 +29,7 @@ class LanguageGatewayImplTest extends \PHPUnit_Framework_TestCase public function ApiException_findLanguage_ThrowException() { ClientMock::$languagesContent = '{"meta": {"status": 400}}'; - $this->gateway->findLanguages([]); + $this->gateway->findLanguages([], self::PROJECT_ID); } /** @@ -36,7 +38,7 @@ public function ApiException_findLanguage_ThrowException() */ public function NonExistingLanguage_findLanguages_ThrowException() { - $this->gateway->findLanguages(['fr']); + $this->gateway->findLanguages(['fr'], self::PROJECT_ID); } /** @@ -44,7 +46,7 @@ public function NonExistingLanguage_findLanguages_ThrowException() */ public function findLanguages() { - $actualLanguages = $this->gateway->findLanguages([LanguageStub1::LOCALE, LanguageStub2::LOCALE]); + $actualLanguages = $this->gateway->findLanguages([LanguageStub1::LOCALE, LanguageStub2::LOCALE], self::PROJECT_ID); $expectedLanguages = [new LanguageStub1(), new LanguageStub2()]; $this->assertEquals(LanguageGateway::LANGUAGES_METHOD, ClientMock::$action); $this->assertEquals(['project_id' => 1], ClientMock::$parameters); @@ -67,6 +69,5 @@ protected function setUp() $this->gateway->setClient(new ClientMock()); ClientMock::$languagesContent = '{"meta": {"status": 200,"record_count": 3},"data": [{"code": "en-US","english_name": "English (United States)","local_name": "English (United States)","locale": "en","region": "US","is_base_language": true,"is_ready_to_publish": true,"translation_progress": "100%","uploaded_at": "2013-10-07T15:27:10+0000","uploaded_at_timestamp": 1381159630},{"code": "ja-JP","english_name": "Japanese","local_name": "日本語","locale": "ja","region": "JP","is_base_language": false,"is_ready_to_publish": true,"translation_progress": "98%","uploaded_at": "2013-10-07T15:27:10+0000","uploaded_at_timestamp": 1381159630},{"code": "ko-KR","english_name": "Korean","local_name": "한국어","locale": "ko","region": "KR","is_base_language": false,"is_ready_to_publish": true,"translation_progress": "56%","uploaded_at": "2013-10-07T15:27:10+0000","uploaded_at_timestamp": 1381159630}]}'; $this->gateway->setLanguageFactory(new LanguageFactoryImpl()); - $this->gateway->setProjectId(1); } } diff --git a/Tests/Services/Impl/LanguageServiceImplTest.php b/Tests/Services/Impl/LanguageServiceImplTest.php index 66c5288..a47b77a 100644 --- a/Tests/Services/Impl/LanguageServiceImplTest.php +++ b/Tests/Services/Impl/LanguageServiceImplTest.php @@ -18,12 +18,14 @@ class LanguageServiceImplTest extends \PHPUnit_Framework_TestCase */ private $service; + const PROJECT_ID = 1; + /** * @test */ public function WithoutLocales_getLanguage() { - $languages = $this->service->getLanguages(); + $languages = $this->service->getLanguages(self::PROJECT_ID); $this->assertEquals([new LanguageStub2()], $languages); } @@ -32,7 +34,7 @@ public function WithoutLocales_getLanguage() */ public function getLanguage() { - $languages = $this->service->getLanguages([LanguageStub1::LOCALE, LanguageStub2::LOCALE]); + $languages = $this->service->getLanguages(self::PROJECT_ID, [LanguageStub1::LOCALE, LanguageStub2::LOCALE]); $this->assertEquals([new LanguageStub1(), new LanguageStub2()], $languages); } diff --git a/Tests/Services/Impl/TranslationServiceImplTest.php b/Tests/Services/Impl/TranslationServiceImplTest.php index e459d7a..96d3aa5 100644 --- a/Tests/Services/Impl/TranslationServiceImplTest.php +++ b/Tests/Services/Impl/TranslationServiceImplTest.php @@ -19,8 +19,8 @@ class TranslationServiceImplTest extends \PHPUnit_Framework_TestCase const FILE_FORMAT = 'yml'; const KERNEL_ROOT_DIR = __DIR__.'/../../'; const PROJECT_DIRECTORY = __DIR__.'/../../../'; - const PROJECT_ID = 1; const SOURCE_LOCALE = 'en'; + const PROJECT_ID = 1; /** * @var TranslationService @@ -32,7 +32,7 @@ class TranslationServiceImplTest extends \PHPUnit_Framework_TestCase */ public function pull_with_locales() { - $this->service->pull([__DIR__.'/../../Fixtures/Resources/translations'], ['es']); + $this->service->pull([self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/translations']], ['es']); $this->assertEquals( [$this->buildExportFile1es(), $this->buildExportFile2es()], FileServiceMock::$downloadedFiles @@ -109,7 +109,7 @@ private function buildExportFile2fr() */ public function pull() { - $this->service->pull([__DIR__.'/../../Fixtures/Resources/translations/subDirectory']); + $this->service->pull([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/translations/subDirectory']]); $this->assertEquals( [ $this->buildExportFile2fr(), @@ -124,7 +124,7 @@ public function pull() */ public function WithoutFilePath_push() { - $this->service->push([]); + $this->service->push([self::PROJECT_ID => []]); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); } @@ -167,7 +167,7 @@ private function buildUploadFile2() */ public function push() { - $this->service->push([__DIR__.'/../../Fixtures/Resources/*']); + $this->service->push([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/*']]); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); } @@ -176,7 +176,7 @@ public function push() */ public function WithLocales_update_Update() { - $this->service->update([__DIR__.'/../../Fixtures/Resources/'], ['es']); + $this->service->update([self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/']], ['es']); $this->assertEquals( [$this->buildExportFile1es(), $this->buildExportFile2es()], FileServiceMock::$downloadedFiles @@ -194,7 +194,6 @@ protected function setUp() $fileFactory->setKeepingAllStrings(self::IS_KEEPING_ALL_STRINGS); $fileFactory->setFileFormat(self::FILE_FORMAT); $fileFactory->setKernelRootDir(self::KERNEL_ROOT_DIR); - $fileFactory->setProjectId(self::PROJECT_ID); $fileFactory->setSourceLocale(self::SOURCE_LOCALE); $this->service->setEventDispatcher(new EventDispatcher()); $this->service->setFileFactory($fileFactory); From 8ce41e1daca95a9151afc125865d8abbb3bf5ffd Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Tue, 15 Nov 2016 16:29:21 +0100 Subject: [PATCH 02/13] =?UTF-8?q?Update=20commands=20and=20tests=20for=20m?= =?UTF-8?q?ulti-projects=20onesky#=20Modifications=20qui=20seront=20valid?= =?UTF-8?q?=C3=A9es=20:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Command/CheckTranslationProgressCommand.php | 14 +++++----- Command/Command.php | 8 +++--- Command/PullCommand.php | 2 ++ Command/PushCommand.php | 4 ++- Model/File.php | 9 +++++++ Services/Impl/TranslationServiceImpl.php | 26 +++++++++++++------ Services/TranslationService.php | 9 ++++--- Tests/Command/CommandTestCase.php | 4 +++ Tests/Command/PullCommandTest.php | 2 +- Tests/Command/PushCommandTest.php | 2 +- .../Services/TranslationServiceMock.php | 12 ++++----- 11 files changed, 62 insertions(+), 30 deletions(-) diff --git a/Command/CheckTranslationProgressCommand.php b/Command/CheckTranslationProgressCommand.php index 1aae50a..3af82b8 100644 --- a/Command/CheckTranslationProgressCommand.php +++ b/Command/CheckTranslationProgressCommand.php @@ -49,17 +49,19 @@ protected function execute(InputInterface $input, OutputInterface $output) $projectsIds = array_keys($this->getContainer()->getParameter('openclassrooms_onesky.file_paths')); $output->writeln('Check translations progress'); $languages = []; - foreach ($projectsIds as $projectId) - $languages += $this->getContainer() - ->get('openclassrooms.onesky.services.language_service') - ->getLanguages($projectId, $input->getOption('locale')); + foreach ($projectsIds as $projectId) { + $projectLanguages = $this->getContainer() + ->get('openclassrooms.onesky.services.language_service') + ->getLanguages($projectId, $input->getOption('locale')); + $languages = array_merge($languages, $projectLanguages); + } $table = new Table($output); $table - ->setHeaders(['Locale', 'Progression']) + ->setHeaders(['Project', 'Locale', 'Progression']) ->setRows( array_map( function (Language $language) { - return [$language->getLocale()." ".$language->getProjectId(), $language->getTranslationProgress()]; + return [$language->getProjectId(), $language->getLocale(), $language->getTranslationProgress()]; }, $languages ) diff --git a/Command/Command.php b/Command/Command.php index 4c30d34..fe24df8 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -73,11 +73,11 @@ function (TranslationPostPullEvent $event) use ($output) { $output->writeln(''.count($event->getDownloadedFiles()).' files downloaded. '); $table = new Table($output); $table - ->setHeaders(['File', 'Locale']) + ->setHeaders(['Project', 'File', 'Locale']) ->setRows( array_map( function (ExportFile $file) { - return [$file->getSourceFilePathRelativeToProject(), $file->getRequestedLocale()]; + return [$file->getProjectId(), $file->getSourceFilePathRelativeToProject(), $file->getRequestedLocale()]; }, $event->getDownloadedFiles() ) @@ -124,11 +124,11 @@ function (TranslationPostPushEvent $event) use ($output) { $output->writeln(''.count($event->getUploadedFiles()).' files downloaded. '); $table = new Table($output); $table - ->setHeaders(['File', 'Locale']) + ->setHeaders(['Project', 'File', 'Locale']) ->setRows( array_map( function (UploadFile $file) { - return [$file->getSourceFilePathRelativeToProject(), $file->getSourceLocale()]; + return [$file->getProjectId(), $file->getSourceFilePathRelativeToProject(), $file->getSourceLocale()]; }, $event->getUploadedFiles() ) diff --git a/Command/PullCommand.php b/Command/PullCommand.php index 63066d0..dece07c 100644 --- a/Command/PullCommand.php +++ b/Command/PullCommand.php @@ -19,6 +19,7 @@ protected function configure() { $this->setName($this->getCommandName()) ->setDescription($this->getCommandDescription()) + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL, 'Project Id') ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File paths', []) ->addOption( 'locale', @@ -46,6 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->handlePullDisplay($output); $this->getContainer()->get('openclassrooms.onesky.services.translation_service')->pull( + $input->getOption('projectId'), $input->getOption('filePath'), $input->getOption('locale') ); diff --git a/Command/PushCommand.php b/Command/PushCommand.php index 92378e5..18ad574 100644 --- a/Command/PushCommand.php +++ b/Command/PushCommand.php @@ -19,7 +19,8 @@ protected function configure() { $this->setName($this->getCommandName()) ->setDescription($this->getCommandDescription()) - ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File path', []) + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL, 'Project Id') + ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File path ( Project id is required)', []) ->addOption( 'locale', null, @@ -46,6 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->handlePushDisplay($output); $this->getContainer()->get('openclassrooms.onesky.services.translation_service')->push( + $input->getOption('projectId'), $input->getOption('filePath'), $input->getOption('locale') ); diff --git a/Model/File.php b/Model/File.php index 531a80b..1c89a54 100644 --- a/Model/File.php +++ b/Model/File.php @@ -58,4 +58,13 @@ public function getEncodedSourceFileName() { return str_replace(DIRECTORY_SEPARATOR, self::FILENAME_SEPARATOR, $this->sourceFilePathRelativeToProject); } + + + /** + * @return int + */ + public function getProjectId() + { + return $this->projectId; + } } diff --git a/Services/Impl/TranslationServiceImpl.php b/Services/Impl/TranslationServiceImpl.php index e143acd..21233c4 100644 --- a/Services/Impl/TranslationServiceImpl.php +++ b/Services/Impl/TranslationServiceImpl.php @@ -57,21 +57,21 @@ class TranslationServiceImpl implements TranslationService /** * {@inheritdoc} */ - public function update(array $filePaths = [], array $locales = []) + public function update($projectId, array $filePaths = [], array $locales = []) { $this->eventDispatcher->dispatch(TranslationUpdateEvent::getEventName(), new TranslationUpdateEvent()); - return [$this->pull($filePaths, $locales), $this->push($filePaths)]; + return [$this->pull($projectId, $filePaths, $locales), $this->push($projectId, $filePaths)]; } /** * {@inheritdoc} */ - public function pull(array $filePaths, array $locales = []) + public function pull($projectId, array $filePaths, array $locales = []) { $exportFiles = []; /** @var SplFileInfo $file */ - foreach ($this->getFilePaths($filePaths) as $projectId => &$paths) { + foreach ($this->getFilePaths($filePaths, $projectId) as $projectId => &$paths) { foreach ($this->getFiles($paths, $this->getSourceLocales()) as $file) { foreach ($this->getRequestedLocales($locales) as $locale) { $exportFiles[] = $this->fileFactory->createExportFile($file->getRealPath(), $projectId, $locale); @@ -108,9 +108,18 @@ private function getFiles(array $paths, array $locales) /** * @return string[] */ - private function getFilePaths(array $filePaths) + private function getFilePaths(array $filePaths, $projectId) { - return empty($filePaths) ? $this->filePaths : $filePaths; + if(empty($filePaths)) { + if($projectId && isset($this->filePaths[$projectId])) + return array($projectId => $this->filePaths[$projectId]); + else + return $this->filePaths; + } + elseif ($projectId) + return array($projectId => $filePaths); + else + return $this->filePaths; } /** @@ -132,12 +141,13 @@ private function getRequestedLocales(array $locales) /** * {@inheritdoc} */ - public function push(array $filePaths, array $locales = []) + public function push($projectId, array $filePaths, array $locales = []) { + $uploadFiles = []; /* @var SplFileInfo $file */ foreach ($this->getSourceLocales($locales) as $locale) { - foreach ($filePaths as $projectId => &$paths) { + foreach ($this->getFilePaths($filePaths, $projectId) as $projectId => &$paths) { foreach ($this->getFiles($paths, [$locale]) as $file) { $uploadFiles[] = $this->fileFactory->createUploadFile($file->getRealPath(), $projectId, $locale); } diff --git a/Services/TranslationService.php b/Services/TranslationService.php index 5e829cc..c684ca0 100644 --- a/Services/TranslationService.php +++ b/Services/TranslationService.php @@ -11,24 +11,27 @@ interface TranslationService { /** + * @param integer $projectId * @param string[] $filePaths * @param string[] $locales * * @return ExportFile[] $files */ - public function pull(array $filePaths, array $locales = []); + public function pull($projectId, array $filePaths, array $locales = []); /** + * @param integer $projectId * @param string[] $filePaths * * @return UploadFile[] $files */ - public function push(array $filePaths, array $locales = []); + public function push($projectId, array $filePaths, array $locales = []); /** + * @param integer $projectId * @param string[] $filePaths * * @return [ExportFile[], UploadFile[]] $files */ - public function update(array $filePaths, array $locales = []); + public function update($projectId, array $filePaths, array $locales = []); } diff --git a/Tests/Command/CommandTestCase.php b/Tests/Command/CommandTestCase.php index 0eb208d..604c2db 100644 --- a/Tests/Command/CommandTestCase.php +++ b/Tests/Command/CommandTestCase.php @@ -17,6 +17,10 @@ trait CommandTestCase * @var string */ public static $filePaths = 'Tests/Fixtures/Resources/translations'; + /** + * @var integer + */ + public static $projectId = 1; /** * @var string[] diff --git a/Tests/Command/PullCommandTest.php b/Tests/Command/PullCommandTest.php index a93892b..d879e62 100644 --- a/Tests/Command/PullCommandTest.php +++ b/Tests/Command/PullCommandTest.php @@ -51,7 +51,7 @@ public function without_filePaths_execute() */ public function with_filePath_execute() { - $this->commandTester->execute(['command' => PullCommand::COMMAND_NAME, '--filePath' => [self::$filePaths]]); + $this->commandTester->execute(['command' => PullCommand::COMMAND_NAME, '--projectId' => [self::$projectId], '--filePath' => [self::$filePaths]]); $this->assertEquals([self::$filePaths], TranslationServiceMock::$pulledFilePaths); } diff --git a/Tests/Command/PushCommandTest.php b/Tests/Command/PushCommandTest.php index 2fec952..b3cf561 100644 --- a/Tests/Command/PushCommandTest.php +++ b/Tests/Command/PushCommandTest.php @@ -51,7 +51,7 @@ public function without_filePaths_execute() */ public function with_filePath_execute() { - $this->commandTester->execute(['command' => PushCommand::COMMAND_NAME, '--filePath' => [self::$filePaths]]); + $this->commandTester->execute(['command' => PushCommand::COMMAND_NAME, '--projectId' => [self::$projectId], '--filePath' => [self::$filePaths]]); $this->assertEquals([self::$filePaths], TranslationServiceMock::$pushedFilePaths); } diff --git a/Tests/Doubles/Services/TranslationServiceMock.php b/Tests/Doubles/Services/TranslationServiceMock.php index 88069f6..6af3250 100644 --- a/Tests/Doubles/Services/TranslationServiceMock.php +++ b/Tests/Doubles/Services/TranslationServiceMock.php @@ -73,7 +73,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher) /** * {@inheritdoc} */ - public function pull(array $filePaths, array $locales = []) + public function pull($projectId, array $filePaths, array $locales = []) { $this->eventDispatcher->dispatch( TranslationPrePullEvent::getEventName(), @@ -88,14 +88,14 @@ public function pull(array $filePaths, array $locales = []) new TranslationPostPullEvent([new ExportFileStub1()]) ); self::$pullCalled = true; - self::$pulledFilePaths = $filePaths; + self::$pulledFilePaths = array($projectId => $filePaths); self::$locales = $locales; } /** * {@inheritdoc} */ - public function push(array $filePaths, array $locales = []) + public function push($projectId, array $filePaths, array $locales = []) { $this->eventDispatcher->dispatch( TranslationPrePushEvent::getEventName(), @@ -110,17 +110,17 @@ public function push(array $filePaths, array $locales = []) new TranslationPostPushEvent([new UploadFileStub1()]) ); self::$pushCalled = true; - self::$pushedFilePaths = $filePaths; + self::$pushedFilePaths = array($projectId => $filePaths); self::$locales = $locales; } /** * {@inheritdoc} */ - public function update(array $filePaths = [], array $locales = []) + public function update($projectId, array $filePaths = [], array $locales = []) { self::$updateCalled = true; - self::$updatedFilePaths = $filePaths; + self::$updatedFilePaths = array($projectId => $filePaths); self::$locales = $locales; } } From 8f146bbf0001a36b165aa75ece88ccdb72cd84d7 Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Wed, 16 Nov 2016 11:38:54 +0100 Subject: [PATCH 03/13] [TESTS][BUGFIX] Fix tests errors --- Command/UpdateCommand.php | 6 ++- Gateways/Impl/FileGatewayImpl.php | 4 +- Gateways/Impl/LanguageGatewayImpl.php | 1 - Services/Impl/LanguageServiceImpl.php | 1 - Services/Impl/TranslationServiceImpl.php | 3 +- .../CheckTranslationProgressCommandTest.php | 10 ++--- .../DependencyInjection/ContainerForTest.php | 44 ++++++++++++++++++- .../Gateways/InMemoryLanguageGateway.php | 2 +- .../Services/TranslationServiceMock.php | 10 ++--- Tests/Gateways/Impl/FileGatewayImplTest.php | 12 ++++- .../Services/Impl/LanguageServiceImplTest.php | 6 +-- .../Impl/TranslationServiceImplTest.php | 14 +++--- 12 files changed, 82 insertions(+), 31 deletions(-) diff --git a/Command/UpdateCommand.php b/Command/UpdateCommand.php index 79ecc73..52dfecc 100644 --- a/Command/UpdateCommand.php +++ b/Command/UpdateCommand.php @@ -3,6 +3,7 @@ namespace OpenClassrooms\Bundle\OneSkyBundle\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -17,7 +18,8 @@ class UpdateCommand extends Command protected function configure() { $this->setName($this->getCommandName()) - ->setDescription($this->getCommandDescription()); + ->setDescription($this->getCommandDescription()) + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL, 'Project Id'); } /** @@ -38,6 +40,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln("Updating translations\n"); $this->handlePullDisplay($output); $this->handlePushDisplay($output); - $this->getContainer()->get('openclassrooms.onesky.services.translation_service')->update(); + $this->getContainer()->get('openclassrooms.onesky.services.translation_service')->update($input->getOption('projectId')); } } diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index 5891323..69b5e13 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -2,7 +2,6 @@ namespace OpenClassrooms\Bundle\OneSkyBundle\Gateways\Impl; -use Guzzle\Http\Exception\ServerErrorResponseException; use Onesky\Api\Client; use OpenClassrooms\Bundle\OneSkyBundle\EventListener\TranslationDownloadTranslationEvent; use OpenClassrooms\Bundle\OneSkyBundle\EventListener\TranslationUploadTranslationEvent; @@ -12,6 +11,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\ExportFile; use OpenClassrooms\Bundle\OneSkyBundle\Model\UploadFile; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * @author Romain Kuzniak @@ -75,7 +75,7 @@ private function checkTranslation($downloadedContent, ExportFile $file) throw new NonExistingTranslationException($file->getTargetFilePath()); } if (500 === $json['meta']['status']) { - throw new ServerErrorResponseException($file->getTargetFilePath()); + throw new HttpException(500, "Got 500 error receiving ".$file->getTargetFilePath()); } throw new InvalidContentException($downloadedContent); } diff --git a/Gateways/Impl/LanguageGatewayImpl.php b/Gateways/Impl/LanguageGatewayImpl.php index 955b4d7..011fcef 100644 --- a/Gateways/Impl/LanguageGatewayImpl.php +++ b/Gateways/Impl/LanguageGatewayImpl.php @@ -46,7 +46,6 @@ public function findLanguages(array $locales, $projectId) throw new LanguageNotFoundException($locale); } } - return $requestedLanguages; } diff --git a/Services/Impl/LanguageServiceImpl.php b/Services/Impl/LanguageServiceImpl.php index 0f0a56d..a1454fa 100644 --- a/Services/Impl/LanguageServiceImpl.php +++ b/Services/Impl/LanguageServiceImpl.php @@ -28,7 +28,6 @@ public function getLanguages($projectId, array $locales = []) if (empty($locales)) { $locales = $this->requestedLocales; } - return $this->languageGateway->findLanguages($locales, $projectId); } diff --git a/Services/Impl/TranslationServiceImpl.php b/Services/Impl/TranslationServiceImpl.php index 21233c4..8de0da4 100644 --- a/Services/Impl/TranslationServiceImpl.php +++ b/Services/Impl/TranslationServiceImpl.php @@ -116,8 +116,9 @@ private function getFilePaths(array $filePaths, $projectId) else return $this->filePaths; } - elseif ($projectId) + elseif ($projectId) { return array($projectId => $filePaths); + } else return $this->filePaths; } diff --git a/Tests/Command/CheckTranslationProgressCommandTest.php b/Tests/Command/CheckTranslationProgressCommandTest.php index 0d38e50..ad61a2f 100644 --- a/Tests/Command/CheckTranslationProgressCommandTest.php +++ b/Tests/Command/CheckTranslationProgressCommandTest.php @@ -27,7 +27,7 @@ class CheckTranslationProgressCommandTest extends \PHPUnit_Framework_TestCase public function without_locales_execute() { $this->commandTester->execute(['command' => CheckTranslationProgressCommand::COMMAND_NAME]); - $this->assertEquals([], LanguageServiceMock::$locales); + $this->assertEquals([ self::$projectId => []], LanguageServiceMock::$locales); $this->assertTrue(LanguageServiceMock::$calledGetLanguages); } @@ -36,11 +36,11 @@ public function without_locales_execute() */ public function with_locales_execute() { - LanguageServiceMock::$languages = [new LanguageStub1(), new LanguageStub2()]; + LanguageServiceMock::$languages = [self::$projectId => [new LanguageStub1(), new LanguageStub2()]]; $exitCode = $this->commandTester->execute( ['command' => CheckTranslationProgressCommand::COMMAND_NAME, '--locale' => [LanguageStub2::LOCALE]] ); - $this->assertEquals([LanguageStub2::LOCALE], LanguageServiceMock::$locales); + $this->assertEquals([ self::$projectId => [LanguageStub2::LOCALE]], LanguageServiceMock::$locales); $this->assertTrue(LanguageServiceMock::$calledGetLanguages); $this->assertEquals(1, $exitCode); } @@ -50,11 +50,11 @@ public function with_locales_execute() */ public function WithFullProgression() { - LanguageServiceMock::$languages = [new LanguageStub1()]; + LanguageServiceMock::$languages = [ self::$projectId => [new LanguageStub1()]]; $exitCode = $this->commandTester->execute( ['command' => CheckTranslationProgressCommand::COMMAND_NAME, '--locale' => [LanguageStub1::LOCALE]] ); - $this->assertEquals([LanguageStub1::LOCALE], LanguageServiceMock::$locales); + $this->assertEquals([ self::$projectId => [LanguageStub1::LOCALE]], LanguageServiceMock::$locales); $this->assertTrue(LanguageServiceMock::$calledGetLanguages); $this->assertEquals(0, $exitCode); } diff --git a/Tests/Doubles/Framework/DependencyInjection/ContainerForTest.php b/Tests/Doubles/Framework/DependencyInjection/ContainerForTest.php index 20281a4..a431463 100644 --- a/Tests/Doubles/Framework/DependencyInjection/ContainerForTest.php +++ b/Tests/Doubles/Framework/DependencyInjection/ContainerForTest.php @@ -3,6 +3,7 @@ namespace OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Framework\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ScopeInterface; /** * @author Romain Kuzniak @@ -28,7 +29,7 @@ public function __construct(array $parameters = [], array $services = []) /** * {@inheritdoc} */ - public function set($id, $service) + public function set($id, $service, $scope = self::SCOPE_CONTAINER) { return; } @@ -80,4 +81,45 @@ public function setParameter($name, $value) { return; } + + /** + * {@inheritdoc} + */ + public function enterScope($name) + { + return; + } + + /** + * {@inheritdoc} + */ + public function leaveScope($name) + { + return; + } + + /** + * {@inheritdoc} + */ + public function addScope(ScopeInterface $scope) + { + return; + } + + /** + * {@inheritdoc} + */ + public function hasScope($name) + { + return; + } + + /** + * {@inheritdoc} + */ + public function isScopeActive($name) + { + return; + } } + diff --git a/Tests/Doubles/Gateways/InMemoryLanguageGateway.php b/Tests/Doubles/Gateways/InMemoryLanguageGateway.php index f22ea02..3583a5b 100644 --- a/Tests/Doubles/Gateways/InMemoryLanguageGateway.php +++ b/Tests/Doubles/Gateways/InMemoryLanguageGateway.php @@ -31,7 +31,7 @@ public function findLanguages(array $locales = [], $projectId) if (!isset(self::$languages[$projectId][$locale])) { throw new LanguageNotFoundException(); } else { - $languages[] = self::$languages[$projectId][$locale]; + $languages[$projectId][] = self::$languages[$projectId][$locale]; } } diff --git a/Tests/Doubles/Services/TranslationServiceMock.php b/Tests/Doubles/Services/TranslationServiceMock.php index 6af3250..c2ba94f 100644 --- a/Tests/Doubles/Services/TranslationServiceMock.php +++ b/Tests/Doubles/Services/TranslationServiceMock.php @@ -73,7 +73,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher) /** * {@inheritdoc} */ - public function pull($projectId, array $filePaths, array $locales = []) + public function pull($projectId, array $filePaths = [], array $locales = []) { $this->eventDispatcher->dispatch( TranslationPrePullEvent::getEventName(), @@ -88,14 +88,14 @@ public function pull($projectId, array $filePaths, array $locales = []) new TranslationPostPullEvent([new ExportFileStub1()]) ); self::$pullCalled = true; - self::$pulledFilePaths = array($projectId => $filePaths); + self::$pulledFilePaths = $filePaths; self::$locales = $locales; } /** * {@inheritdoc} */ - public function push($projectId, array $filePaths, array $locales = []) + public function push($projectId, array $filePaths = [], array $locales = []) { $this->eventDispatcher->dispatch( TranslationPrePushEvent::getEventName(), @@ -110,7 +110,7 @@ public function push($projectId, array $filePaths, array $locales = []) new TranslationPostPushEvent([new UploadFileStub1()]) ); self::$pushCalled = true; - self::$pushedFilePaths = array($projectId => $filePaths); + self::$pushedFilePaths = $filePaths; self::$locales = $locales; } @@ -120,7 +120,7 @@ public function push($projectId, array $filePaths, array $locales = []) public function update($projectId, array $filePaths = [], array $locales = []) { self::$updateCalled = true; - self::$updatedFilePaths = array($projectId => $filePaths); + self::$updatedFilePaths = $filePaths; self::$locales = $locales; } } diff --git a/Tests/Gateways/Impl/FileGatewayImplTest.php b/Tests/Gateways/Impl/FileGatewayImplTest.php index ccf4337..5329a14 100644 --- a/Tests/Gateways/Impl/FileGatewayImplTest.php +++ b/Tests/Gateways/Impl/FileGatewayImplTest.php @@ -12,6 +12,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\UploadFileStub2; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\OneSky\Api\ClientMock; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * @author Romain Kuzniak @@ -112,12 +113,19 @@ public function WithFileNotOnApiException_download_DoNothing() /** * @test - * @expectedException \Guzzle\Http\Exception\ServerErrorResponseException + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException; */ public function ApiServerError_download_ThrowException() { + $exception = null; ClientMock::$downloadedContent = '{"meta":{"status":500,"message":"Something went wrong. Please try again or contact us at support@oneskyapp.com"},"data":{}}'; - $this->gateway->downloadTranslations([new ExportFileStub1()]); + try { + $this->gateway->downloadTranslations([new ExportFileStub1()]); + } catch (HttpException $e) { + $exception = $e; + } + $this->assertNotNull($exception); + $this->assertEquals(500, $exception->getStatusCode()); } /** diff --git a/Tests/Services/Impl/LanguageServiceImplTest.php b/Tests/Services/Impl/LanguageServiceImplTest.php index a47b77a..5455d11 100644 --- a/Tests/Services/Impl/LanguageServiceImplTest.php +++ b/Tests/Services/Impl/LanguageServiceImplTest.php @@ -26,7 +26,7 @@ class LanguageServiceImplTest extends \PHPUnit_Framework_TestCase public function WithoutLocales_getLanguage() { $languages = $this->service->getLanguages(self::PROJECT_ID); - $this->assertEquals([new LanguageStub2()], $languages); + $this->assertEquals([self::PROJECT_ID => [new LanguageStub2()]], $languages); } /** @@ -35,7 +35,7 @@ public function WithoutLocales_getLanguage() public function getLanguage() { $languages = $this->service->getLanguages(self::PROJECT_ID, [LanguageStub1::LOCALE, LanguageStub2::LOCALE]); - $this->assertEquals([new LanguageStub1(), new LanguageStub2()], $languages); + $this->assertEquals([self::PROJECT_ID => [new LanguageStub1(), new LanguageStub2()]], $languages); } /** @@ -46,7 +46,7 @@ protected function setUp() $this->service = new LanguageServiceImpl(); $this->service->setLanguageGateway( new InMemoryLanguageGateway( - [LanguageStub1::LOCALE => new LanguageStub1(), LanguageStub2::LOCALE => new LanguageStub2()] + [self::PROJECT_ID => [LanguageStub1::LOCALE => new LanguageStub1(), LanguageStub2::LOCALE => new LanguageStub2()]] ) ); $this->service->setRequestedLocales(['ja']); diff --git a/Tests/Services/Impl/TranslationServiceImplTest.php b/Tests/Services/Impl/TranslationServiceImplTest.php index 96d3aa5..1d59257 100644 --- a/Tests/Services/Impl/TranslationServiceImplTest.php +++ b/Tests/Services/Impl/TranslationServiceImplTest.php @@ -32,7 +32,7 @@ class TranslationServiceImplTest extends \PHPUnit_Framework_TestCase */ public function pull_with_locales() { - $this->service->pull([self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/translations']], ['es']); + $this->service->pull(self::PROJECT_ID , [__DIR__.'/../../Fixtures/Resources/translations'], ['es']); $this->assertEquals( [$this->buildExportFile1es(), $this->buildExportFile2es()], FileServiceMock::$downloadedFiles @@ -68,7 +68,7 @@ private function buildExportFile2es() */ public function WithoutFilePaths_pull() { - $this->service->pull([]); + $this->service->pull(self::PROJECT_ID, []); $this->assertEquals( [ $this->buildExportFile1fr(), @@ -109,7 +109,7 @@ private function buildExportFile2fr() */ public function pull() { - $this->service->pull([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/translations/subDirectory']]); + $this->service->pull(self::PROJECT_ID, [__DIR__.'/../../Fixtures/Resources/translations/subDirectory']); $this->assertEquals( [ $this->buildExportFile2fr(), @@ -124,7 +124,7 @@ public function pull() */ public function WithoutFilePath_push() { - $this->service->push([self::PROJECT_ID => []]); + $this->service->push(self::PROJECT_ID, []); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); } @@ -167,7 +167,7 @@ private function buildUploadFile2() */ public function push() { - $this->service->push([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/*']]); + $this->service->push(self::PROJECT_ID, [__DIR__.'/../../Fixtures/Resources/*']); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); } @@ -176,7 +176,7 @@ public function push() */ public function WithLocales_update_Update() { - $this->service->update([self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/']], ['es']); + $this->service->update(self::PROJECT_ID, [__DIR__.'/../../Fixtures/Resources/'], ['es']); $this->assertEquals( [$this->buildExportFile1es(), $this->buildExportFile2es()], FileServiceMock::$downloadedFiles @@ -198,7 +198,7 @@ protected function setUp() $this->service->setEventDispatcher(new EventDispatcher()); $this->service->setFileFactory($fileFactory); $this->service->setFileFormat(self::FILE_FORMAT); - $this->service->setFilePaths([__DIR__.'/../../Fixtures/Resources/*']); + $this->service->setFilePaths([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/*']]); $this->service->setFileService(new FileServiceMock()); $this->service->setRequestedLocales(['fr', 'es']); $this->service->setSourceLocale(self::SOURCE_LOCALE); From 299fcc0a9f69f06eb36fc2643ef465e5ef42e92f Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Mon, 21 Nov 2016 15:08:23 +0100 Subject: [PATCH 04/13] Complex YAML bridge for symfony --- Gateways/Impl/FileGatewayImpl.php | 10 +++++++++- README.md | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index 5891323..8d781b2 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -12,6 +12,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\ExportFile; use OpenClassrooms\Bundle\OneSkyBundle\Model\UploadFile; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\Yaml\Yaml as SFYaml; /** * @author Romain Kuzniak @@ -58,7 +59,14 @@ private function downloadTranslation(ExportFile $file) ); $downloadedContent = $this->client->translations(self::DOWNLOAD_METHOD, $file->format()); $this->checkTranslation($downloadedContent, $file); - file_put_contents($file->getTargetFilePath(), $downloadedContent); + if(!empty($downloadedContent)) { + if (is_callable("yaml_parse")) + file_put_contents($file->getTargetFilePath(), SFYaml::dump(yaml_parse($downloadedContent))); + else + throw new HttpException(500, "PHP YAML extension is missing ( https://pecl.php.net/package/yaml )"); + } + else + file_put_contents($file->getTargetFilePath(), $downloadedContent); return $file; } diff --git a/README.md b/README.md index 0d196d4..8b74a6d 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,24 @@ or by adding the package to the composer.json file directly: } ``` +This bundle need the YAML extension : https://pecl.php.net/package/yaml + +#### PHP 7 +``` +apt-get install php-pear libyaml-dev +pecl install yaml-2.0.0 +``` +Add "extension=yaml.so" to php.ini for CLI + +#### PHP 5 +``` +apt-get install php-pear libyaml-dev +pecl install yaml +``` +Add "extension=yaml.so" to php.ini for CLI + + + After the package has been installed, add the bundle to the AppKernel.php file: ```php // in AppKernel::registerBundles() From a0c7230b65c5b0b8520b43da4d41dfe46de60eb0 Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Mon, 21 Nov 2016 15:26:25 +0100 Subject: [PATCH 05/13] Fix missing use --- Gateways/Impl/FileGatewayImpl.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index 8d781b2..ffd15b3 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -13,6 +13,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\UploadFile; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Yaml\Yaml as SFYaml; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * @author Romain Kuzniak From e684e906d429068c6b5d4c2fa55eda46f62519f0 Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Wed, 22 Feb 2017 17:07:09 +0100 Subject: [PATCH 06/13] Multiple file formats --- DependencyInjection/Configuration.php | 1 + Model/Impl/FileFactoryImpl.php | 9 +++++++-- Resources/config/services.xml | 1 + Services/Impl/TranslationServiceImpl.php | 16 +++++++++++----- .../Services/Impl/TranslationServiceImplTest.php | 5 +++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cba0e03..c1de805 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -24,6 +24,7 @@ public function getConfigTreeBuilder() ->scalarNode('source_locale')->cannotBeEmpty()->defaultValue('en')->end() ->arrayNode('locales')->isRequired()->cannotBeEmpty()->prototype('scalar')->end()->end() ->arrayNode('file_paths')->isRequired()->cannotBeEmpty()->prototype('array')->prototype('scalar')->end()->end()->end() + ->arrayNode('file_formats')->prototype('array')->prototype('scalar')->end()->end()->end() ->scalarNode('keep_all_strings')->cannotBeEmpty()->defaultValue(true)->end() ->end(); diff --git a/Model/Impl/FileFactoryImpl.php b/Model/Impl/FileFactoryImpl.php index 72e4887..9891fab 100644 --- a/Model/Impl/FileFactoryImpl.php +++ b/Model/Impl/FileFactoryImpl.php @@ -14,6 +14,10 @@ class FileFactoryImpl implements FileFactory * @var string */ private $fileFormat; + /** + * @var array + */ + private $fileFormats; /** * @var string @@ -55,7 +59,7 @@ public function createUploadFile($filePath, $projectId, $locale = null) $projectId, $filePath, $this->getProjectDirectory(), - $this->fileFormat, + isset($this->fileFormats[$projectId])?$this->fileFormats[$projectId]:$this->fileFormat, empty($locale) ? $this->sourceLocale : $locale ); @@ -69,9 +73,10 @@ public function setKeepingAllStrings($isKeepingAllStrings) $this->isKeepingAllStrings = $isKeepingAllStrings; } - public function setFileFormat($fileFormat) + public function setFileFormat($fileFormat, $fileFormats) { $this->fileFormat = $fileFormat; + $this->fileFormats = $fileFormats; } public function setKernelRootDir($kernelRootDir) diff --git a/Resources/config/services.xml b/Resources/config/services.xml index b396710..1b75c15 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -62,6 +62,7 @@ %openclassrooms_onesky.file_format% + %openclassrooms_onesky.file_formats% %openclassrooms_onesky.file_paths% diff --git a/Services/Impl/TranslationServiceImpl.php b/Services/Impl/TranslationServiceImpl.php index 8de0da4..65edeb9 100644 --- a/Services/Impl/TranslationServiceImpl.php +++ b/Services/Impl/TranslationServiceImpl.php @@ -39,6 +39,11 @@ class TranslationServiceImpl implements TranslationService */ private $fileFormat; + /** + * @var array + */ + private $fileFormats; + /** * @var FileService */ @@ -72,7 +77,7 @@ public function pull($projectId, array $filePaths, array $locales = []) $exportFiles = []; /** @var SplFileInfo $file */ foreach ($this->getFilePaths($filePaths, $projectId) as $projectId => &$paths) { - foreach ($this->getFiles($paths, $this->getSourceLocales()) as $file) { + foreach ($this->getFiles($paths, $this->getSourceLocales(), $projectId) as $file) { foreach ($this->getRequestedLocales($locales) as $locale) { $exportFiles[] = $this->fileFactory->createExportFile($file->getRealPath(), $projectId, $locale); } @@ -97,12 +102,12 @@ public function pull($projectId, array $filePaths, array $locales = []) /** * @return Finder */ - private function getFiles(array $paths, array $locales) + private function getFiles(array $paths, array $locales, $projectId) { return Finder::create() ->files() ->in($paths) - ->name('*.{'.implode(',', $locales).'}.'.$this->fileFormat); + ->name('*.{'.implode(',', $locales).'}.'.isset($this->fileFormats[$projectId])?$this->fileFormats[$projectId]:$this->fileFormat); } /** @@ -149,7 +154,7 @@ public function push($projectId, array $filePaths, array $locales = []) /* @var SplFileInfo $file */ foreach ($this->getSourceLocales($locales) as $locale) { foreach ($this->getFilePaths($filePaths, $projectId) as $projectId => &$paths) { - foreach ($this->getFiles($paths, [$locale]) as $file) { + foreach ($this->getFiles($paths, [$locale], $projectId) as $file) { $uploadFiles[] = $this->fileFactory->createUploadFile($file->getRealPath(), $projectId, $locale); } } @@ -180,9 +185,10 @@ public function setFileFactory(FileFactory $fileFactory) $this->fileFactory = $fileFactory; } - public function setFileFormat($fileFormat) + public function setFileFormat($fileFormat, $fileFormats) { $this->fileFormat = $fileFormat; + $this->fileFormats = $fileFormats; } public function setFilePaths(array $filePaths) diff --git a/Tests/Services/Impl/TranslationServiceImplTest.php b/Tests/Services/Impl/TranslationServiceImplTest.php index 1d59257..7cbd902 100644 --- a/Tests/Services/Impl/TranslationServiceImplTest.php +++ b/Tests/Services/Impl/TranslationServiceImplTest.php @@ -17,6 +17,7 @@ class TranslationServiceImplTest extends \PHPUnit_Framework_TestCase { const IS_KEEPING_ALL_STRINGS = false; const FILE_FORMAT = 'yml'; + const FILE_FORMATS = [1 => 'yml']; const KERNEL_ROOT_DIR = __DIR__.'/../../'; const PROJECT_DIRECTORY = __DIR__.'/../../../'; const SOURCE_LOCALE = 'en'; @@ -192,12 +193,12 @@ protected function setUp() $this->service = new TranslationServiceImpl(); $fileFactory = new FileFactoryImpl(); $fileFactory->setKeepingAllStrings(self::IS_KEEPING_ALL_STRINGS); - $fileFactory->setFileFormat(self::FILE_FORMAT); + $fileFactory->setFileFormat(self::FILE_FORMAT, self::FILE_FORMATS); $fileFactory->setKernelRootDir(self::KERNEL_ROOT_DIR); $fileFactory->setSourceLocale(self::SOURCE_LOCALE); $this->service->setEventDispatcher(new EventDispatcher()); $this->service->setFileFactory($fileFactory); - $this->service->setFileFormat(self::FILE_FORMAT); + $this->service->setFileFormat(self::FILE_FORMAT, self::FILE_FORMATS); $this->service->setFilePaths([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/*']]); $this->service->setFileService(new FileServiceMock()); $this->service->setRequestedLocales(['fr', 'es']); From 4c48dabf2d092980d24068476cea7600cec520da Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Wed, 22 Feb 2017 17:11:40 +0100 Subject: [PATCH 07/13] Fix config --- DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index c1de805..607eb50 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -24,7 +24,7 @@ public function getConfigTreeBuilder() ->scalarNode('source_locale')->cannotBeEmpty()->defaultValue('en')->end() ->arrayNode('locales')->isRequired()->cannotBeEmpty()->prototype('scalar')->end()->end() ->arrayNode('file_paths')->isRequired()->cannotBeEmpty()->prototype('array')->prototype('scalar')->end()->end()->end() - ->arrayNode('file_formats')->prototype('array')->prototype('scalar')->end()->end()->end() + ->arrayNode('file_formats')->prototype('scalar')->end()->end() ->scalarNode('keep_all_strings')->cannotBeEmpty()->defaultValue(true)->end() ->end(); From d3b21a0886038b067721c9905f2d547bc5627e62 Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Wed, 22 Feb 2017 18:11:01 +0100 Subject: [PATCH 08/13] Fix missing config --- DependencyInjection/OpenClassroomsOneSkyExtension.php | 1 + README.md | 6 ++++-- Resources/config/services.xml | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/OpenClassroomsOneSkyExtension.php b/DependencyInjection/OpenClassroomsOneSkyExtension.php index 8cb6cbd..5fbf704 100644 --- a/DependencyInjection/OpenClassroomsOneSkyExtension.php +++ b/DependencyInjection/OpenClassroomsOneSkyExtension.php @@ -30,6 +30,7 @@ private function processParameters(ContainerBuilder $container, array $config) $container->setParameter('openclassrooms_onesky.source_locale', $config['source_locale']); $container->setParameter('openclassrooms_onesky.locales', $config['locales']); $container->setParameter('openclassrooms_onesky.file_format', $config['file_format']); + $container->setParameter('openclassrooms_onesky.file_formats', $config['file_formats']); $container->setParameter('openclassrooms_onesky.file_paths', $config['file_paths']); $container->setParameter('openclassrooms_onesky.keep_all_strings', $config['keep_all_strings']); } diff --git a/README.md b/README.md index d2afd7a..9b3fc94 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,10 @@ openclassrooms_onesky: - es file_format: %onesky.file_format% #optional, default xliff file_paths: - %onesky.project_id%: - - %path.to.translations.files.directory% + project_id: + - path.to.translations.files.directory% + file_formats: + project_id: format keep_all_strings: false # default true ``` diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 1b75c15..214cb4e 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -31,6 +31,7 @@ %openclassrooms_onesky.file_format% + %openclassrooms_onesky.file_formats% %kernel.root_dir% From c87e394a8f0aad555c5a579e37daa99b16031107 Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Thu, 30 Mar 2017 11:52:45 +0200 Subject: [PATCH 09/13] New config to handle multi projects with different parameters --- Command/CheckTranslationProgressCommand.php | 53 +++++-- Command/PullCommand.php | 10 +- Command/PushCommand.php | 12 +- Command/UpdateCommand.php | 10 +- DependencyInjection/Configuration.php | 19 ++- .../OpenClassroomsOneSkyExtension.php | 7 +- Gateways/Impl/FileGatewayImpl.php | 7 +- Gateways/Impl/LanguageGatewayImpl.php | 6 +- Gateways/LanguageGateway.php | 2 +- Model/ExportFile.php | 8 +- Model/File.php | 21 ++- Model/FileFactory.php | 4 +- Model/Impl/FileFactoryImpl.php | 46 +----- Model/UploadFile.php | 18 +-- README.md | 49 ++++-- Resources/config/services.xml | 27 +--- Services/Impl/LanguageServiceImpl.php | 17 +- Services/Impl/TranslationServiceImpl.php | 126 +++++++-------- Services/LanguageService.php | 2 +- Services/TranslationService.php | 6 +- .../CheckTranslationProgressCommandTest.php | 16 +- Tests/Command/CommandTestCase.php | 12 +- Tests/Command/PullCommandTest.php | 6 +- Tests/Command/PushCommandTest.php | 6 +- .../OpenClassroomsOneSkyExtensionTest.php | 3 +- .../Gateways/InMemoryLanguageGateway.php | 6 +- Tests/Doubles/Model/ExportFileStub.php | 11 +- Tests/Doubles/Model/ExportFileStub1.php | 2 +- Tests/Doubles/Model/ExportFileStub2.php | 2 +- Tests/Doubles/Model/LanguageStub1.php | 1 + Tests/Doubles/Model/LanguageStub2.php | 1 + Tests/Doubles/Model/LanguageStub3.php | 22 +++ Tests/Doubles/Model/ProjectsStub.php | 33 ++++ Tests/Doubles/Model/UploadFileStub.php | 13 +- Tests/Doubles/Model/UploadFileStub1.php | 6 +- Tests/Doubles/Model/UploadFileStub2.php | 7 +- .../Doubles/Services/LanguageServiceMock.php | 17 +- .../Services/TranslationServiceMock.php | 6 +- Tests/Fixtures/Resources/config/config.yml | 21 ++- .../Resources/translations/messages.ja.yml | 0 .../translations/subDirectory/messages.ja.yml | 0 Tests/Gateways/Impl/FileGatewayImplTest.php | 33 ++-- .../Gateways/Impl/LanguageGatewayImplTest.php | 9 +- .../Services/Impl/LanguageServiceImplTest.php | 14 +- .../Impl/TranslationServiceImplTest.php | 149 ++++++++++++------ 45 files changed, 467 insertions(+), 379 deletions(-) create mode 100644 Tests/Doubles/Model/LanguageStub3.php create mode 100644 Tests/Doubles/Model/ProjectsStub.php create mode 100644 Tests/Fixtures/Resources/translations/messages.ja.yml create mode 100644 Tests/Fixtures/Resources/translations/subDirectory/messages.ja.yml diff --git a/Command/CheckTranslationProgressCommand.php b/Command/CheckTranslationProgressCommand.php index 3af82b8..4ccbd2f 100644 --- a/Command/CheckTranslationProgressCommand.php +++ b/Command/CheckTranslationProgressCommand.php @@ -2,6 +2,7 @@ namespace OpenClassrooms\Bundle\OneSkyBundle\Command; +use OpenClassrooms\Bundle\OneSkyBundle\Gateways\LanguageNotFoundException; use OpenClassrooms\Bundle\OneSkyBundle\Model\Language; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Helper\Table; @@ -22,13 +23,8 @@ protected function configure() { $this->setName($this->getCommandName()) ->setDescription($this->getCommandDescription()) - ->addOption( - 'locale', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'Requested locales', - [] - ); + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Requested projectsIds', []) + ->addOption('locale', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Source locale', []); } /** @@ -44,17 +40,47 @@ protected function getCommandDescription() return self::COMMAND_DESCRIPTION; } + private function getLocales($project, array $locales) + { + if(empty($locales)) + return $project["locales"]; + else + return $locales; + } + + private function getProjects(array $projects, array $projectsIds) + { + if(empty($projectsIds)) + return $projects; + else + { + foreach ($projects as $projectId => &$project) + if(!in_array($projectId, $projectsIds)) + unset($projects[$projectId]); + return $projects; + } + } + protected function execute(InputInterface $input, OutputInterface $output) { - $projectsIds = array_keys($this->getContainer()->getParameter('openclassrooms_onesky.file_paths')); + $projects = $this->getProjects($this->getContainer()->getParameter('openclassrooms_onesky.projects'), $input->getOption('projectId')); $output->writeln('Check translations progress'); $languages = []; - foreach ($projectsIds as $projectId) { - $projectLanguages = $this->getContainer() - ->get('openclassrooms.onesky.services.language_service') - ->getLanguages($projectId, $input->getOption('locale')); - $languages = array_merge($languages, $projectLanguages); + foreach ($projects as $projectId => &$project) { + try { + $projectLanguages = $this->getContainer() + ->get('openclassrooms.onesky.services.language_service') + ->getLanguages($project, $this->getLocales($project, $input->getOption('locale'))); + $languages = array_merge($languages, $projectLanguages); + } catch(LanguageNotFoundException $e) { + if(!empty($input->getOption('locale'))) + $output->writeln('Language '.$input->getOption('locale').' not found for project '.$projectId.''); + else + throw $e; + } } + if(empty($languages)) + throw new LanguageNotFoundException(); $table = new Table($output); $table ->setHeaders(['Project', 'Locale', 'Progression']) @@ -73,7 +99,6 @@ function (Language $language) { return 1; } } - return 0; } } diff --git a/Command/PullCommand.php b/Command/PullCommand.php index dece07c..312c08c 100644 --- a/Command/PullCommand.php +++ b/Command/PullCommand.php @@ -19,15 +19,9 @@ protected function configure() { $this->setName($this->getCommandName()) ->setDescription($this->getCommandDescription()) - ->addOption('projectId', null, InputOption::VALUE_OPTIONAL, 'Project Id') + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Requested projectsIds', []) ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File paths', []) - ->addOption( - 'locale', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'Requested requestedLocale', - [] - ); + ->addOption('locale', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Requested requestedLocale', []); } /** diff --git a/Command/PushCommand.php b/Command/PushCommand.php index 18ad574..d26abb5 100644 --- a/Command/PushCommand.php +++ b/Command/PushCommand.php @@ -19,15 +19,9 @@ protected function configure() { $this->setName($this->getCommandName()) ->setDescription($this->getCommandDescription()) - ->addOption('projectId', null, InputOption::VALUE_OPTIONAL, 'Project Id') - ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File path ( Project id is required)', []) - ->addOption( - 'locale', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'Source locale', - [] - ); + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Requested projectsIds', []) + ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File paths', []) + ->addOption('locale', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Source locale', []); } /** diff --git a/Command/UpdateCommand.php b/Command/UpdateCommand.php index 52dfecc..d86c323 100644 --- a/Command/UpdateCommand.php +++ b/Command/UpdateCommand.php @@ -19,7 +19,9 @@ protected function configure() { $this->setName($this->getCommandName()) ->setDescription($this->getCommandDescription()) - ->addOption('projectId', null, InputOption::VALUE_OPTIONAL, 'Project Id'); + ->addOption('projectId', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Requested projectsIds', []) + ->addOption('filePath', 'dir', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'File paths', []) + ->addOption('locale', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Source locale', []); } /** @@ -40,6 +42,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln("Updating translations\n"); $this->handlePullDisplay($output); $this->handlePushDisplay($output); - $this->getContainer()->get('openclassrooms.onesky.services.translation_service')->update($input->getOption('projectId')); + $this->getContainer()->get('openclassrooms.onesky.services.translation_service')->update( + $input->getOption('projectId'), + $input->getOption('filePath'), + $input->getOption('locale') + ); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 607eb50..f626341 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -20,13 +20,18 @@ public function getConfigTreeBuilder() $rootNode->children() ->scalarNode('api_key')->isRequired()->cannotBeEmpty()->end() ->scalarNode('api_secret')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('file_format')->cannotBeEmpty()->defaultValue('xliff')->end() - ->scalarNode('source_locale')->cannotBeEmpty()->defaultValue('en')->end() - ->arrayNode('locales')->isRequired()->cannotBeEmpty()->prototype('scalar')->end()->end() - ->arrayNode('file_paths')->isRequired()->cannotBeEmpty()->prototype('array')->prototype('scalar')->end()->end()->end() - ->arrayNode('file_formats')->prototype('scalar')->end()->end() - ->scalarNode('keep_all_strings')->cannotBeEmpty()->defaultValue(true)->end() - ->end(); + ->arrayNode('projects') + ->prototype('array') + ->children() + ->scalarNode('file_format')->cannotBeEmpty()->defaultValue('xliff')->end() + ->scalarNode('source_locale')->cannotBeEmpty()->defaultValue('en')->end() + ->arrayNode('file_paths')->cannotBeEmpty()->prototype('scalar')->end()->end() + ->arrayNode('locales')->cannotBeEmpty()->prototype('scalar')->end()->end() + ->scalarNode('keep_all_strings')->cannotBeEmpty()->defaultValue(true)->end() + ->end() + ->end() + ->end() + ->end(); return $treeBuilder; } diff --git a/DependencyInjection/OpenClassroomsOneSkyExtension.php b/DependencyInjection/OpenClassroomsOneSkyExtension.php index 5fbf704..43c8650 100644 --- a/DependencyInjection/OpenClassroomsOneSkyExtension.php +++ b/DependencyInjection/OpenClassroomsOneSkyExtension.php @@ -27,12 +27,7 @@ private function processParameters(ContainerBuilder $container, array $config) { $container->setParameter('openclassrooms_onesky.api_key', $config['api_key']); $container->setParameter('openclassrooms_onesky.api_secret', $config['api_secret']); - $container->setParameter('openclassrooms_onesky.source_locale', $config['source_locale']); - $container->setParameter('openclassrooms_onesky.locales', $config['locales']); - $container->setParameter('openclassrooms_onesky.file_format', $config['file_format']); - $container->setParameter('openclassrooms_onesky.file_formats', $config['file_formats']); - $container->setParameter('openclassrooms_onesky.file_paths', $config['file_paths']); - $container->setParameter('openclassrooms_onesky.keep_all_strings', $config['keep_all_strings']); + $container->setParameter('openclassrooms_onesky.projects', $config['projects']); } /** diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index a2ee234..eb8fc00 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -60,10 +60,12 @@ private function downloadTranslation(ExportFile $file) $downloadedContent = $this->client->translations(self::DOWNLOAD_METHOD, $file->format()); $this->checkTranslation($downloadedContent, $file); if(!empty($downloadedContent)) { - if (is_callable("yaml_parse")) + if ($file->getFormat() != "yml") + file_put_contents($file->getTargetFilePath(), $downloadedContent); + else if (is_callable("yaml_parse")) file_put_contents($file->getTargetFilePath(), SFYaml::dump(yaml_parse($downloadedContent))); else - throw new HttpException(500, "PHP YAML extension is missing ( https://pecl.php.net/package/yaml )"); + throw new HttpException(500, "PHP YAML extension is needed for YAML files ( https://pecl.php.net/package/yaml )"); } else file_put_contents($file->getTargetFilePath(), $downloadedContent); @@ -111,6 +113,7 @@ private function uploadTranslation(UploadFile $file) TranslationUploadTranslationEvent::getEventName(), new TranslationUploadTranslationEvent($file) ); + $this->client->files(self::UPLOAD_METHOD, $file->format()); return $file; diff --git a/Gateways/Impl/LanguageGatewayImpl.php b/Gateways/Impl/LanguageGatewayImpl.php index 011fcef..14957bb 100644 --- a/Gateways/Impl/LanguageGatewayImpl.php +++ b/Gateways/Impl/LanguageGatewayImpl.php @@ -30,14 +30,14 @@ class LanguageGatewayImpl implements LanguageGateway * @throws LanguageException * @throws LanguageNotFoundException */ - public function findLanguages(array $locales, $projectId) + public function findLanguages(array $locales, array $project) { - $jsonResponse = $this->client->projects(self::LANGUAGES_METHOD, ['project_id' => $projectId]); + $jsonResponse = $this->client->projects(self::LANGUAGES_METHOD, ['project_id' => $project["id"]]); $response = json_decode($jsonResponse, true); $this->checkResponse($response, $jsonResponse); - $languages = $this->createLanguages($response, $projectId); + $languages = $this->createLanguages($response, $project["id"]); $requestedLanguages = []; foreach ($locales as $locale) { if (isset($languages[$locale])) { diff --git a/Gateways/LanguageGateway.php b/Gateways/LanguageGateway.php index 821655e..14ccf2e 100644 --- a/Gateways/LanguageGateway.php +++ b/Gateways/LanguageGateway.php @@ -14,5 +14,5 @@ interface LanguageGateway * * @throws LanguageException */ - public function findLanguages(array $locales, $projectId); + public function findLanguages(array $locales, array $project); } diff --git a/Model/ExportFile.php b/Model/ExportFile.php index 23f17ea..24b3671 100644 --- a/Model/ExportFile.php +++ b/Model/ExportFile.php @@ -16,10 +16,9 @@ abstract class ExportFile extends File */ protected $requestedLocale; - public function __construct($projectId, $sourceFilePath, $projectDirectory, $requestedLocale) + public function __construct($project, $sourceFilePath, $projectDirectory, $requestedLocale) { - parent::__construct($projectId, $sourceFilePath, $projectDirectory); - $this->projectId = $projectId; + parent::__construct($project, $sourceFilePath, $projectDirectory); $this->requestedLocale = $requestedLocale; } @@ -59,9 +58,12 @@ public function getTargetFilePathRelativeToProject() public function format() { return [ + self::FILE_FORMAT => $this->fileFormat, self::PROJECT_ID => $this->projectId, self::REQUESTED_LOCALE => $this->requestedLocale, self::REQUESTED_SOURCE_FILE_NAME => $this->getEncodedSourceFileName(), ]; } + + } diff --git a/Model/File.php b/Model/File.php index 1c89a54..d4ecb16 100644 --- a/Model/File.php +++ b/Model/File.php @@ -11,6 +11,8 @@ abstract class File const PROJECT_ID = 'project_id'; + const FILE_FORMAT = 'file_format'; + const SOURCE_FILE_PATH = 'file'; /** @@ -28,12 +30,19 @@ abstract class File */ protected $sourceFilePathRelativeToProject; + + /** + * @var string + */ + protected $fileFormat; + /** * {@inheritdoc} */ - public function __construct($projectId, $sourceFilePath, $projectDirectory) + public function __construct($project, $sourceFilePath, $projectDirectory) { - $this->projectId = $projectId; + $this->fileFormat = $project["file_format"]; + $this->projectId = $project["id"]; $this->sourceFilePath = realpath($sourceFilePath); $this->sourceFilePathRelativeToProject = str_replace(realpath($projectDirectory), '', $this->sourceFilePath); } @@ -67,4 +76,12 @@ public function getProjectId() { return $this->projectId; } + + /** + * @return mixed + */ + public function getFormat() + { + return $this->fileFormat; + } } diff --git a/Model/FileFactory.php b/Model/FileFactory.php index b3061e3..506b0b6 100644 --- a/Model/FileFactory.php +++ b/Model/FileFactory.php @@ -10,10 +10,10 @@ interface FileFactory /** * @return ExportFile */ - public function createExportFile($sourceFilePath, $projectId, $requestedLocale); + public function createExportFile($sourceFilePath, $project, $requestedLocale); /** * @return UploadFile */ - public function createUploadFile($filePath, $projectId, $locale = null); + public function createUploadFile($filePath, $project, $locale); } diff --git a/Model/Impl/FileFactoryImpl.php b/Model/Impl/FileFactoryImpl.php index 9891fab..a7f4d45 100644 --- a/Model/Impl/FileFactoryImpl.php +++ b/Model/Impl/FileFactoryImpl.php @@ -10,36 +10,18 @@ */ class FileFactoryImpl implements FileFactory { - /** - * @var string - */ - private $fileFormat; - /** - * @var array - */ - private $fileFormats; /** * @var string */ private $kernelRootDir; - /** - * @var string - */ - private $sourceLocale; - - /** - * @var bool - */ - private $isKeepingAllStrings; - /** * @return ExportFile */ - public function createExportFile($sourceFilePath, $projectId, $requestedLocale) + public function createExportFile($sourceFilePath, $project, $requestedLocale) { - return new ExportFileImpl($projectId, $sourceFilePath, $this->getProjectDirectory(), $requestedLocale); + return new ExportFileImpl($project, $sourceFilePath, $this->getProjectDirectory(), $requestedLocale); } /** @@ -53,39 +35,21 @@ private function getProjectDirectory() /** * {@inheritdoc} */ - public function createUploadFile($filePath, $projectId, $locale = null) + public function createUploadFile($filePath, $project, $locale) { $file = new UploadFileImpl( - $projectId, + $project, $filePath, $this->getProjectDirectory(), - isset($this->fileFormats[$projectId])?$this->fileFormats[$projectId]:$this->fileFormat, - empty($locale) ? $this->sourceLocale : $locale + $locale ); - $file->setKeepingAllStrings($this->isKeepingAllStrings); - return $file; } - public function setKeepingAllStrings($isKeepingAllStrings) - { - $this->isKeepingAllStrings = $isKeepingAllStrings; - } - - public function setFileFormat($fileFormat, $fileFormats) - { - $this->fileFormat = $fileFormat; - $this->fileFormats = $fileFormats; - } - public function setKernelRootDir($kernelRootDir) { $this->kernelRootDir = $kernelRootDir; } - public function setSourceLocale($sourceLocale) - { - $this->sourceLocale = $sourceLocale; - } } diff --git a/Model/UploadFile.php b/Model/UploadFile.php index 10eec67..cb936c8 100644 --- a/Model/UploadFile.php +++ b/Model/UploadFile.php @@ -9,15 +9,8 @@ abstract class UploadFile extends File { const IS_KEEPING_ALL_STRINGS = 'is_keeping_all_strings'; - const FILE_FORMAT = 'file_format'; - const SOURCE_LOCALE = 'locale'; - /** - * @var string - */ - protected $fileFormat; - /** * @var string */ @@ -33,14 +26,13 @@ abstract class UploadFile extends File */ protected $isKeepingAllStrings = true; - public function __construct($projectId, $sourceFilePath, $projectDirectory, $fileFormat, $sourceLocale) + public function __construct($project, $sourceFilePath, $projectDirectory, $sourceLocale) { - parent::__construct($projectId, $sourceFilePath, $projectDirectory); + parent::__construct($project, $sourceFilePath, $projectDirectory); $this->formattedSourceFilePath = sys_get_temp_dir().'/'.$this->getEncodedSourceFileName(); copy($sourceFilePath, $this->formattedSourceFilePath); - - $this->fileFormat = $fileFormat; $this->sourceLocale = $sourceLocale; + $this->isKeepingAllStrings = $project["keep_all_strings"]; } /** @@ -65,8 +57,4 @@ public function getSourceLocale() return $this->sourceLocale; } - public function setKeepingAllStrings($isKeepingAllStrings) - { - $this->isKeepingAllStrings = $isKeepingAllStrings; - } } diff --git a/README.md b/README.md index 9b3fc94..55d550f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ or by adding the package to the composer.json file directly: } ``` -This bundle need the YAML extension : https://pecl.php.net/package/yaml +If you want to use YAML files, you need the PECL YAML extension : https://pecl.php.net/package/yaml #### PHP 7 ``` @@ -54,19 +54,23 @@ $bundles = array( # app/config/config.yml openclassrooms_onesky: - api_key: %onesky.api_key% + api_key: %onesky.api_key% api_secret: %onesky.api_secret% - source_locale: %source_locale% #optional, default en - locales: - - fr - - es - file_format: %onesky.file_format% #optional, default xliff - file_paths: - project_id: - - path.to.translations.files.directory% - file_formats: - project_id: format - keep_all_strings: false # default true + projects: + 1: + file_format: yml + source_locale: en + locales: [en,fr,ja] + keep_all_strings: 0 + file_paths: + - "%kernel.root_dir%/../src/Bundle/DemoBundle/Resources/translations" + 2: + file_format: xliff + source_locale: fr + locales: [fr,es] + keep_all_strings: 1 + file_paths: + - "%kernel.root_dir%/../app/Resources/translations/" ``` @@ -92,6 +96,12 @@ Locale can be set as an option. php app/console openclassrooms:one-sky:pull --locale=fr php app/console openclassrooms:one-sky:pull --locale=fr --locale=es ``` +##### Project id + Project id can be set as an option. +```bash +php app/console openclassrooms:one-sky:pull --projectId=1 +php app/console openclassrooms:one-sky:pull --projectId=1 --projectId=2 +``` ### Push Push the translations from the OneSky API using the default configuration. @@ -114,6 +124,12 @@ Locale can be set as an option. php app/console openclassrooms:one-sky:push --locale=en php app/console openclassrooms:one-sky:push --locale=en --locale=fr ``` +##### Project id + Project id can be set as an option. +```bash +php app/console openclassrooms:one-sky:push --projectId=1 +php app/console openclassrooms:one-sky:push --projectId=1 --projectId=2 +``` ### Update Pull then push translations from the OneSky API using the default configuration. @@ -138,3 +154,10 @@ Locale can be set as an option. php app/console openclassrooms:one-sky:check-translation-progress --locale=en php app/console openclassrooms:one-sky:check-translation-progress --locale=en --locale=fr ``` +##### Project id + Project id can be set as an option. +```bash +php app/console openclassrooms:one-sky:check-translation-progress --projectId=1 +php app/console openclassrooms:one-sky:check-translation-progress --projectId=1 --projectId=2 +``` + diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 214cb4e..45f18e2 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -26,19 +26,9 @@ - - %openclassrooms_onesky.keep_all_strings% - - - %openclassrooms_onesky.file_format% - %openclassrooms_onesky.file_formats% - %kernel.root_dir% - - %openclassrooms_onesky.source_locale% - @@ -50,9 +40,6 @@ - - %openclassrooms_onesky.locales% - @@ -61,22 +48,12 @@ - - %openclassrooms_onesky.file_format% - %openclassrooms_onesky.file_formats% - - - %openclassrooms_onesky.file_paths% + + %openclassrooms_onesky.projects% - - %openclassrooms_onesky.locales% - - - %openclassrooms_onesky.source_locale% - diff --git a/Services/Impl/LanguageServiceImpl.php b/Services/Impl/LanguageServiceImpl.php index a1454fa..b5bdf68 100644 --- a/Services/Impl/LanguageServiceImpl.php +++ b/Services/Impl/LanguageServiceImpl.php @@ -15,29 +15,16 @@ class LanguageServiceImpl implements LanguageService */ private $languageGateway; - /** - * @var string[] - */ - private $requestedLocales; - /** * @return \OpenClassrooms\Bundle\OneSkyBundle\Model\Language[] */ - public function getLanguages($projectId, array $locales = []) + public function getLanguages(array $project, array $locales) { - if (empty($locales)) { - $locales = $this->requestedLocales; - } - return $this->languageGateway->findLanguages($locales, $projectId); + return $this->languageGateway->findLanguages($locales, $project); } public function setLanguageGateway(LanguageGateway $languageGateway) { $this->languageGateway = $languageGateway; } - - public function setRequestedLocales(array $requestedLocales) - { - $this->requestedLocales = $requestedLocales; - } } diff --git a/Services/Impl/TranslationServiceImpl.php b/Services/Impl/TranslationServiceImpl.php index 65edeb9..5b77fa5 100644 --- a/Services/Impl/TranslationServiceImpl.php +++ b/Services/Impl/TranslationServiceImpl.php @@ -27,63 +27,41 @@ class TranslationServiceImpl implements TranslationService /** * @var string[] */ - private $filePaths; + private $projects; /** * @var FileFactory */ private $fileFactory; - /** - * @var string - */ - private $fileFormat; - - /** - * @var array - */ - private $fileFormats; - /** * @var FileService */ private $fileService; - /** - * @var string[] - */ - private $requestedLocales; - - /** - * @var string - */ - private $sourceLocale; - /** * {@inheritdoc} */ - public function update($projectId, array $filePaths = [], array $locales = []) + public function update(array $projectsIds, array $filePaths = [], array $locales = []) { $this->eventDispatcher->dispatch(TranslationUpdateEvent::getEventName(), new TranslationUpdateEvent()); - return [$this->pull($projectId, $filePaths, $locales), $this->push($projectId, $filePaths)]; + return [$this->push($projectsIds, $filePaths), $this->pull($projectsIds, $filePaths, $locales)]; } /** * {@inheritdoc} */ - public function pull($projectId, array $filePaths, array $locales = []) + public function pull(array $projectsIds, array $filePaths, array $locales = []) { $exportFiles = []; - /** @var SplFileInfo $file */ - foreach ($this->getFilePaths($filePaths, $projectId) as $projectId => &$paths) { - foreach ($this->getFiles($paths, $this->getSourceLocales(), $projectId) as $file) { - foreach ($this->getRequestedLocales($locales) as $locale) { - $exportFiles[] = $this->fileFactory->createExportFile($file->getRealPath(), $projectId, $locale); + foreach ($this->getProjectsIds($projectsIds) as $projectId) { + foreach ($this->getFiles($this->getFilePaths($filePaths, $projectId), $this->projects[$projectId]["source_locale"], $projectId) as $file) { + foreach ($this->getRequestedLocales($locales, $projectId) as $locale) { + $exportFiles[] = $this->fileFactory->createExportFile($file->getRealPath(), $this->projects[$projectId], $locale); } } } - $this->eventDispatcher->dispatch( TranslationPrePullEvent::getEventName(), new TranslationPrePullEvent($exportFiles) @@ -100,14 +78,17 @@ public function pull($projectId, array $filePaths, array $locales = []) } /** - * @return Finder + * @return */ - private function getFiles(array $paths, array $locales, $projectId) + private function getFiles(array $paths, string $locale, $projectId) { - return Finder::create() - ->files() - ->in($paths) - ->name('*.{'.implode(',', $locales).'}.'.isset($this->fileFormats[$projectId])?$this->fileFormats[$projectId]:$this->fileFormat); + if(empty($paths)) + return array(); + else + return Finder::create() + ->files() + ->in($paths) + ->name('*.'.$locale.'.'.$this->projects[$projectId]["file_format"]); } /** @@ -115,47 +96,61 @@ private function getFiles(array $paths, array $locales, $projectId) */ private function getFilePaths(array $filePaths, $projectId) { - if(empty($filePaths)) { - if($projectId && isset($this->filePaths[$projectId])) - return array($projectId => $this->filePaths[$projectId]); - else - return $this->filePaths; - } - elseif ($projectId) { - return array($projectId => $filePaths); + if(empty($filePaths)) + return $this->projects[$projectId]["file_paths"]; + else { + foreach ($filePaths as $key => &$filePath) { + $pathFound = false; + foreach ($this->projects[$projectId]["file_paths"] as $projectFilePath) + if (strpos($filePath, $projectFilePath) === 0) + $pathFound = true; + if(!$pathFound) + unset($filePaths[$key]); + } + return $filePaths; } + } + /** + * @return string[] + */ + private function getProjectsIds($projectsIds) + { + if(empty($projectsIds)) + return array_keys($this->projects); else - return $this->filePaths; + return $projectsIds; } /** * @return string[] */ - private function getSourceLocales(array $locales = []) + private function getSourceLocales(array $locales = [], $projectId) { - return empty($locales) ? [$this->sourceLocale] : $locales; + if(empty($locales)) + return [$this->projects[$projectId]["source_locale"]]; + else + return $locales; } /** * @return string[] */ - private function getRequestedLocales(array $locales) + private function getRequestedLocales(array $locales, $projectId) { - return empty($locales) ? $this->requestedLocales : $locales; + return empty($locales) ? $this->projects[$projectId]["locales"] : $locales; } /** * {@inheritdoc} */ - public function push($projectId, array $filePaths, array $locales = []) + public function push(array $projectsIds, array $filePaths, array $locales = []) { - $uploadFiles = []; /* @var SplFileInfo $file */ - foreach ($this->getSourceLocales($locales) as $locale) { - foreach ($this->getFilePaths($filePaths, $projectId) as $projectId => &$paths) { - foreach ($this->getFiles($paths, [$locale], $projectId) as $file) { - $uploadFiles[] = $this->fileFactory->createUploadFile($file->getRealPath(), $projectId, $locale); + foreach ($this->getProjectsIds($projectsIds) as $projectId) { + foreach ($this->getSourceLocales($locales, $projectId) as $locale) { + foreach ($this->getFiles($this->getFilePaths($filePaths, $projectId), $locale, $projectId) as $file) { + $uploadFiles[] = $this->fileFactory->createUploadFile($file->getRealPath(), $this->projects[$projectId], $locale); } } } @@ -185,29 +180,18 @@ public function setFileFactory(FileFactory $fileFactory) $this->fileFactory = $fileFactory; } - public function setFileFormat($fileFormat, $fileFormats) - { - $this->fileFormat = $fileFormat; - $this->fileFormats = $fileFormats; - } - - public function setFilePaths(array $filePaths) - { - $this->filePaths = $filePaths; - } public function setFileService(FileService $fileService) { $this->fileService = $fileService; } - public function setRequestedLocales(array $requestedLocales) + public function setProjects($projects) { - $this->requestedLocales = $requestedLocales; + foreach ($projects as $projectId => &$project) + $project["id"] = $projectId; + $this->projects = $projects; } - public function setSourceLocale($sourceLocale) - { - $this->sourceLocale = $sourceLocale; - } } + diff --git a/Services/LanguageService.php b/Services/LanguageService.php index b30f399..5bc6a5c 100644 --- a/Services/LanguageService.php +++ b/Services/LanguageService.php @@ -10,5 +10,5 @@ interface LanguageService /** * @return \OpenClassrooms\Bundle\OneSkyBundle\Model\Language[] */ - public function getLanguages($projectId, array $locales = []); + public function getLanguages(array $project, array $locales); } diff --git a/Services/TranslationService.php b/Services/TranslationService.php index c684ca0..0aa712c 100644 --- a/Services/TranslationService.php +++ b/Services/TranslationService.php @@ -17,7 +17,7 @@ interface TranslationService * * @return ExportFile[] $files */ - public function pull($projectId, array $filePaths, array $locales = []); + public function pull(array $projectsIds, array $filePaths, array $locales = []); /** * @param integer $projectId @@ -25,7 +25,7 @@ public function pull($projectId, array $filePaths, array $locales = []); * * @return UploadFile[] $files */ - public function push($projectId, array $filePaths, array $locales = []); + public function push(array $projectsIds, array $filePaths, array $locales = []); /** * @param integer $projectId @@ -33,5 +33,5 @@ public function push($projectId, array $filePaths, array $locales = []); * * @return [ExportFile[], UploadFile[]] $files */ - public function update($projectId, array $filePaths, array $locales = []); + public function update(array $projectsIds, array $filePaths, array $locales = []); } diff --git a/Tests/Command/CheckTranslationProgressCommandTest.php b/Tests/Command/CheckTranslationProgressCommandTest.php index ad61a2f..a092506 100644 --- a/Tests/Command/CheckTranslationProgressCommandTest.php +++ b/Tests/Command/CheckTranslationProgressCommandTest.php @@ -5,6 +5,8 @@ use OpenClassrooms\Bundle\OneSkyBundle\Command\CheckTranslationProgressCommand; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub1; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub2; +use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub3; +use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\ProjectsStub; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Services\LanguageServiceMock; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -26,8 +28,12 @@ class CheckTranslationProgressCommandTest extends \PHPUnit_Framework_TestCase */ public function without_locales_execute() { + LanguageServiceMock::$languages = [1 => [new LanguageStub1(), new LanguageStub2()], 2 => [new LanguageStub3()]]; $this->commandTester->execute(['command' => CheckTranslationProgressCommand::COMMAND_NAME]); - $this->assertEquals([ self::$projectId => []], LanguageServiceMock::$locales); + $wantedLocales = array(); + foreach (ProjectsStub::$projects as $projectId => $project) + $wantedLocales[$projectId] = $project["locales"]; + $this->assertEquals($wantedLocales, LanguageServiceMock::$locales); $this->assertTrue(LanguageServiceMock::$calledGetLanguages); } @@ -36,11 +42,11 @@ public function without_locales_execute() */ public function with_locales_execute() { - LanguageServiceMock::$languages = [self::$projectId => [new LanguageStub1(), new LanguageStub2()]]; + LanguageServiceMock::$languages = [1 => [new LanguageStub1(), new LanguageStub2()], 2 => [new LanguageStub3()]]; $exitCode = $this->commandTester->execute( ['command' => CheckTranslationProgressCommand::COMMAND_NAME, '--locale' => [LanguageStub2::LOCALE]] ); - $this->assertEquals([ self::$projectId => [LanguageStub2::LOCALE]], LanguageServiceMock::$locales); + $this->assertEquals([ 1 => [LanguageStub2::LOCALE], 2 => [LanguageStub3::LOCALE]], LanguageServiceMock::$locales); $this->assertTrue(LanguageServiceMock::$calledGetLanguages); $this->assertEquals(1, $exitCode); } @@ -50,11 +56,11 @@ public function with_locales_execute() */ public function WithFullProgression() { - LanguageServiceMock::$languages = [ self::$projectId => [new LanguageStub1()]]; + LanguageServiceMock::$languages = [ 1 => [new LanguageStub1()], 2 => [new LanguageStub3()]]; $exitCode = $this->commandTester->execute( ['command' => CheckTranslationProgressCommand::COMMAND_NAME, '--locale' => [LanguageStub1::LOCALE]] ); - $this->assertEquals([ self::$projectId => [LanguageStub1::LOCALE]], LanguageServiceMock::$locales); + $this->assertEquals([ 1 => [LanguageStub1::LOCALE]], LanguageServiceMock::$locales); $this->assertTrue(LanguageServiceMock::$calledGetLanguages); $this->assertEquals(0, $exitCode); } diff --git a/Tests/Command/CommandTestCase.php b/Tests/Command/CommandTestCase.php index 604c2db..a513a94 100644 --- a/Tests/Command/CommandTestCase.php +++ b/Tests/Command/CommandTestCase.php @@ -3,6 +3,7 @@ namespace OpenClassrooms\Bundle\OneSkyBundle\Tests\Command; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Framework\DependencyInjection\ContainerForTest; +use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\ProjectsStub; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Services\LanguageServiceMock; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Services\TranslationServiceMock; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -17,15 +18,7 @@ trait CommandTestCase * @var string */ public static $filePaths = 'Tests/Fixtures/Resources/translations'; - /** - * @var integer - */ - public static $projectId = 1; - /** - * @var string[] - */ - public static $locales = ['fr']; /** * @return ContainerInterface @@ -36,8 +29,7 @@ protected function getContainer() return new ContainerForTest( [ - 'openclassrooms_onesky.file_paths' => [ 1 => [self::$filePaths]], - 'openclassrooms_onesky.requestedLocales' => self::$locales, + 'openclassrooms_onesky.projects' => ProjectsStub::$projects, 'kernel.root_dir' => __DIR__.'/../', ], [ diff --git a/Tests/Command/PullCommandTest.php b/Tests/Command/PullCommandTest.php index d879e62..c4ed232 100644 --- a/Tests/Command/PullCommandTest.php +++ b/Tests/Command/PullCommandTest.php @@ -33,8 +33,8 @@ public function without_locales_execute() */ public function with_locales_execute() { - $this->commandTester->execute(['command' => PullCommand::COMMAND_NAME, '--locale' => ['es']]); - $this->assertEquals(['es'], TranslationServiceMock::$locales); + $this->commandTester->execute(['command' => PullCommand::COMMAND_NAME, '--locale' => ['ja']]); + $this->assertEquals(['ja'], TranslationServiceMock::$locales); } /** @@ -51,7 +51,7 @@ public function without_filePaths_execute() */ public function with_filePath_execute() { - $this->commandTester->execute(['command' => PullCommand::COMMAND_NAME, '--projectId' => [self::$projectId], '--filePath' => [self::$filePaths]]); + $this->commandTester->execute(['command' => PullCommand::COMMAND_NAME, '--projectId' => [1], '--filePath' => [self::$filePaths]]); $this->assertEquals([self::$filePaths], TranslationServiceMock::$pulledFilePaths); } diff --git a/Tests/Command/PushCommandTest.php b/Tests/Command/PushCommandTest.php index b3cf561..fe8d101 100644 --- a/Tests/Command/PushCommandTest.php +++ b/Tests/Command/PushCommandTest.php @@ -33,8 +33,8 @@ public function without_locales_execute() */ public function with_locales_execute() { - $this->commandTester->execute(['command' => PushCommand::COMMAND_NAME, '--locale' => ['es']]); - $this->assertEquals(['es'], TranslationServiceMock::$locales); + $this->commandTester->execute(['command' => PushCommand::COMMAND_NAME, '--locale' => ['ja']]); + $this->assertEquals(['ja'], TranslationServiceMock::$locales); } /** @@ -51,7 +51,7 @@ public function without_filePaths_execute() */ public function with_filePath_execute() { - $this->commandTester->execute(['command' => PushCommand::COMMAND_NAME, '--projectId' => [self::$projectId], '--filePath' => [self::$filePaths]]); + $this->commandTester->execute(['command' => PushCommand::COMMAND_NAME, '--projectId' => [1], '--filePath' => [self::$filePaths]]); $this->assertEquals([self::$filePaths], TranslationServiceMock::$pushedFilePaths); } diff --git a/Tests/DependencyInjection/OpenClassroomsOneSkyExtensionTest.php b/Tests/DependencyInjection/OpenClassroomsOneSkyExtensionTest.php index 5e7010a..23df918 100644 --- a/Tests/DependencyInjection/OpenClassroomsOneSkyExtensionTest.php +++ b/Tests/DependencyInjection/OpenClassroomsOneSkyExtensionTest.php @@ -19,7 +19,8 @@ public function container_compile() { $container = new ContainerBuilder(); $bundle = new OpenClassroomsOneSkyBundle(); - $container->registerExtension($bundle->getContainerExtension()); + $extension = $bundle->getContainerExtension(); + $container->registerExtension($extension); $container->loadFromExtension('openclassrooms_onesky'); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Fixtures/Resources/config')); diff --git a/Tests/Doubles/Gateways/InMemoryLanguageGateway.php b/Tests/Doubles/Gateways/InMemoryLanguageGateway.php index 3583a5b..8b915fe 100644 --- a/Tests/Doubles/Gateways/InMemoryLanguageGateway.php +++ b/Tests/Doubles/Gateways/InMemoryLanguageGateway.php @@ -24,14 +24,14 @@ public function __construct(array $languages = []) /** * {@inheritdoc} */ - public function findLanguages(array $locales = [], $projectId) + public function findLanguages(array $locales = [], array $project) { $languages = []; foreach ($locales as $locale) { - if (!isset(self::$languages[$projectId][$locale])) { + if (!isset(self::$languages[$project["id"]][$locale])) { throw new LanguageNotFoundException(); } else { - $languages[$projectId][] = self::$languages[$projectId][$locale]; + $languages[$project["id"]][] = self::$languages[$project["id"]][$locale]; } } diff --git a/Tests/Doubles/Model/ExportFileStub.php b/Tests/Doubles/Model/ExportFileStub.php index d3e3310..674b2cd 100644 --- a/Tests/Doubles/Model/ExportFileStub.php +++ b/Tests/Doubles/Model/ExportFileStub.php @@ -9,7 +9,14 @@ */ abstract class ExportFileStub extends ExportFileImpl { - const PROJECT_ID = 1; - + const PROJECT = + [ + "id" => 1, + "file_format" => "yml", + "source_locale" => "en", + "locales" => ["en","fr","ja"], + "keep_all_strings" => 0, + "file_paths" => [ "__DIR__.'/../'Tests/Fixtures/Resources/translations/"] + ]; const PROJECT_DIRECTORY = __DIR__.'/../../../'; } diff --git a/Tests/Doubles/Model/ExportFileStub1.php b/Tests/Doubles/Model/ExportFileStub1.php index 781edd9..db15cb9 100644 --- a/Tests/Doubles/Model/ExportFileStub1.php +++ b/Tests/Doubles/Model/ExportFileStub1.php @@ -13,6 +13,6 @@ class ExportFileStub1 extends ExportFileStub public function __construct() { - parent::__construct(self::PROJECT_ID, self::SOURCE_FILE_PATH, self::PROJECT_DIRECTORY, self::REQUESTED_LOCALE); + parent::__construct(self::PROJECT, self::SOURCE_FILE_PATH, self::PROJECT_DIRECTORY, self::REQUESTED_LOCALE); } } diff --git a/Tests/Doubles/Model/ExportFileStub2.php b/Tests/Doubles/Model/ExportFileStub2.php index 0236b40..a9962c0 100644 --- a/Tests/Doubles/Model/ExportFileStub2.php +++ b/Tests/Doubles/Model/ExportFileStub2.php @@ -13,6 +13,6 @@ class ExportFileStub2 extends ExportFileStub public function __construct() { - parent::__construct(self::PROJECT_ID, self::SOURCE_FILE_PATH, self::PROJECT_DIRECTORY, self::REQUESTED_LOCALE); + parent::__construct(self::PROJECT, self::SOURCE_FILE_PATH, self::PROJECT_DIRECTORY, self::REQUESTED_LOCALE); } } diff --git a/Tests/Doubles/Model/LanguageStub1.php b/Tests/Doubles/Model/LanguageStub1.php index 3d23a49..0e38c89 100644 --- a/Tests/Doubles/Model/LanguageStub1.php +++ b/Tests/Doubles/Model/LanguageStub1.php @@ -17,5 +17,6 @@ class LanguageStub1 extends LanguageImpl public function __construct() { + $this->projectId = ProjectsStub::$projects[1]["id"]; } } diff --git a/Tests/Doubles/Model/LanguageStub2.php b/Tests/Doubles/Model/LanguageStub2.php index 4ca34ba..fa7fc90 100644 --- a/Tests/Doubles/Model/LanguageStub2.php +++ b/Tests/Doubles/Model/LanguageStub2.php @@ -17,5 +17,6 @@ class LanguageStub2 extends LanguageImpl public function __construct() { + $this->projectId = ProjectsStub::$projects[1]["id"]; } } diff --git a/Tests/Doubles/Model/LanguageStub3.php b/Tests/Doubles/Model/LanguageStub3.php new file mode 100644 index 0000000..d710697 --- /dev/null +++ b/Tests/Doubles/Model/LanguageStub3.php @@ -0,0 +1,22 @@ + + */ +class LanguageStub3 extends LanguageImpl +{ + const LOCALE = 'ja'; + + protected $locale = self::LOCALE; + + protected $translationProgress = '98%'; + + public function __construct() + { + $this->projectId = ProjectsStub::$projects[2]["id"]; + } +} diff --git a/Tests/Doubles/Model/ProjectsStub.php b/Tests/Doubles/Model/ProjectsStub.php new file mode 100644 index 0000000..6d076ca --- /dev/null +++ b/Tests/Doubles/Model/ProjectsStub.php @@ -0,0 +1,33 @@ + [ + "id" => 1, + "file_format" => "yml", + "source_locale" => "en", + "locales" => ["en","ja"], + "keep_all_strings" => 0, + "file_paths" => [ __DIR__.'/../../Fixtures/Resources/translations/'] + ], + 2 => [ + "id" => 2, + "file_format" => "yml", + "source_locale" => "ja", + "locales" => ["ja"], + "keep_all_strings" => 0, + "file_paths" => [ __DIR__.'/../../Fixtures/Resources/translations/subDirectory' ] + ] + ]; + +} \ No newline at end of file diff --git a/Tests/Doubles/Model/UploadFileStub.php b/Tests/Doubles/Model/UploadFileStub.php index c77c3ce..89384d5 100644 --- a/Tests/Doubles/Model/UploadFileStub.php +++ b/Tests/Doubles/Model/UploadFileStub.php @@ -9,13 +9,18 @@ */ abstract class UploadFileStub extends UploadFileImpl { - const FILE_FORMAT = 'yaml'; const PROJECT_DIRECTORY = __DIR__.'/../../../'; - const PROJECT_ID = 1; - - const SOURCE_LOCALE = 'en'; + const PROJECT = + [ + "id" => 1, + "file_format" => "yml", + "source_locale" => "en", + "locales" => ["en","fr","ja"], + "keep_all_strings" => 0, + "file_paths" => [ "__DIR__.'/../'Tests/Fixtures/Resources/translations/"] + ]; /** * @return string diff --git a/Tests/Doubles/Model/UploadFileStub1.php b/Tests/Doubles/Model/UploadFileStub1.php index 3bdd429..371c24d 100644 --- a/Tests/Doubles/Model/UploadFileStub1.php +++ b/Tests/Doubles/Model/UploadFileStub1.php @@ -7,19 +7,15 @@ */ class UploadFileStub1 extends UploadFileStub { - const IS_KEEPING_ALL_STRINGS = true; const SOURCE_FILE_PATH = __DIR__.'/../../Fixtures/Resources/translations/messages.en.yml'; - protected $isKeepingAllStrings = self::IS_KEEPING_ALL_STRINGS; - public function __construct() { parent::__construct( - self::PROJECT_ID, + self::PROJECT, self::SOURCE_FILE_PATH, self::PROJECT_DIRECTORY, - self::FILE_FORMAT, self::SOURCE_LOCALE ); } diff --git a/Tests/Doubles/Model/UploadFileStub2.php b/Tests/Doubles/Model/UploadFileStub2.php index 1c956c3..5feb8bc 100644 --- a/Tests/Doubles/Model/UploadFileStub2.php +++ b/Tests/Doubles/Model/UploadFileStub2.php @@ -7,19 +7,14 @@ */ class UploadFileStub2 extends UploadFileStub { - const IS_KEEPING_ALL_STRINGS = false; - const SOURCE_FILE_PATH = __DIR__.'/../../Fixtures/Resources/translations/subDirectory/messages.en.yml'; - protected $isKeepingAllStrings = self::IS_KEEPING_ALL_STRINGS; - public function __construct() { parent::__construct( - self::PROJECT_ID, + self::PROJECT, self::SOURCE_FILE_PATH, self::PROJECT_DIRECTORY, - self::FILE_FORMAT, self::SOURCE_LOCALE ); } diff --git a/Tests/Doubles/Services/LanguageServiceMock.php b/Tests/Doubles/Services/LanguageServiceMock.php index 655f16c..bdcb8c4 100644 --- a/Tests/Doubles/Services/LanguageServiceMock.php +++ b/Tests/Doubles/Services/LanguageServiceMock.php @@ -35,13 +35,20 @@ public function __construct() /** * {@inheritdoc} */ - public function getLanguages($projectId, array $locales = []) + public function getLanguages(array $project, array $locales) { self::$calledGetLanguages = true; - self::$locales[$projectId] = $locales; - - if(isset(self::$languages[$projectId])) - return self::$languages[$projectId]; + foreach ($locales as $locale) { + if(in_array($locale, $project["locales"])) + self::$locales[$project["id"]][] = $locale; + } + if(isset(self::$languages[$project["id"]]) && isset(self::$locales[$project["id"]])) { + $languages = array(); + foreach (self::$languages[$project["id"]] as $language) + if(in_array($language->getLocale(), self::$locales[$project["id"]])) + $languages[] = $language; + return $languages; + } else return array(); } diff --git a/Tests/Doubles/Services/TranslationServiceMock.php b/Tests/Doubles/Services/TranslationServiceMock.php index c2ba94f..de5346e 100644 --- a/Tests/Doubles/Services/TranslationServiceMock.php +++ b/Tests/Doubles/Services/TranslationServiceMock.php @@ -73,7 +73,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher) /** * {@inheritdoc} */ - public function pull($projectId, array $filePaths = [], array $locales = []) + public function pull(array $projectsIds, array $filePaths = [], array $locales = []) { $this->eventDispatcher->dispatch( TranslationPrePullEvent::getEventName(), @@ -95,7 +95,7 @@ public function pull($projectId, array $filePaths = [], array $locales = []) /** * {@inheritdoc} */ - public function push($projectId, array $filePaths = [], array $locales = []) + public function push(array $projectsIds, array $filePaths = [], array $locales = []) { $this->eventDispatcher->dispatch( TranslationPrePushEvent::getEventName(), @@ -117,7 +117,7 @@ public function push($projectId, array $filePaths = [], array $locales = []) /** * {@inheritdoc} */ - public function update($projectId, array $filePaths = [], array $locales = []) + public function update(array $projectsIds, array $filePaths = [], array $locales = []) { self::$updateCalled = true; self::$updatedFilePaths = $filePaths; diff --git a/Tests/Fixtures/Resources/config/config.yml b/Tests/Fixtures/Resources/config/config.yml index b98dea8..52de664 100644 --- a/Tests/Fixtures/Resources/config/config.yml +++ b/Tests/Fixtures/Resources/config/config.yml @@ -1,13 +1,18 @@ openclassrooms_onesky: api_key: api_key api_secret: api_secret - file_format: yml - source_locale: en - locales: - - fr - - es - file_paths: + projects: 1: - - /1/ + file_format: yml + source_locale: en + locales: [en,fr,ja] + keep_all_strings: 0 + file_paths: + - "%kernel.root_dir%/Tests/Fixtures/Resources/translations/" 2: - - /2/ \ No newline at end of file + file_format: yml + source_locale: en + locales: [en,fr,es] + keep_all_strings: 0 + file_paths: + - "%kernel.root_dir%/Tests/Fixtures/Resources/translations/subDirectory/" \ No newline at end of file diff --git a/Tests/Fixtures/Resources/translations/messages.ja.yml b/Tests/Fixtures/Resources/translations/messages.ja.yml new file mode 100644 index 0000000..e69de29 diff --git a/Tests/Fixtures/Resources/translations/subDirectory/messages.ja.yml b/Tests/Fixtures/Resources/translations/subDirectory/messages.ja.yml new file mode 100644 index 0000000..e69de29 diff --git a/Tests/Gateways/Impl/FileGatewayImplTest.php b/Tests/Gateways/Impl/FileGatewayImplTest.php index 5329a14..0f4b891 100644 --- a/Tests/Gateways/Impl/FileGatewayImplTest.php +++ b/Tests/Gateways/Impl/FileGatewayImplTest.php @@ -49,11 +49,11 @@ public function OneFile_upload() $this->assertEquals( [ [ - UploadFile::PROJECT_ID => UploadFileStub1::PROJECT_ID, + UploadFile::PROJECT_ID => UploadFileStub1::PROJECT["id"], UploadFile::SOURCE_FILE_PATH => $uploadFileStub1->getFormattedFilePath(), - UploadFile::FILE_FORMAT => UploadFileStub1::FILE_FORMAT, + UploadFile::FILE_FORMAT => UploadFileStub1::PROJECT["file_format"], UploadFile::SOURCE_LOCALE => UploadFileStub1::SOURCE_LOCALE, - UploadFile::IS_KEEPING_ALL_STRINGS => UploadFileStub1::IS_KEEPING_ALL_STRINGS, + UploadFile::IS_KEEPING_ALL_STRINGS => UploadFileStub1::PROJECT["keep_all_strings"], ], ], ClientMock::$parameters @@ -73,18 +73,18 @@ public function ManyFiles_upload_Upload() $this->assertEquals( [ [ - UploadFile::PROJECT_ID => UploadFileStub1::PROJECT_ID, + UploadFile::PROJECT_ID => UploadFileStub1::PROJECT["id"], UploadFile::SOURCE_FILE_PATH => $uploadFileStub1->getFormattedFilePath(), - UploadFile::FILE_FORMAT => UploadFileStub1::FILE_FORMAT, + UploadFile::FILE_FORMAT => UploadFileStub1::PROJECT["file_format"], UploadFile::SOURCE_LOCALE => UploadFileStub1::SOURCE_LOCALE, - UploadFile::IS_KEEPING_ALL_STRINGS => UploadFileStub1::IS_KEEPING_ALL_STRINGS, + UploadFile::IS_KEEPING_ALL_STRINGS => UploadFileStub1::PROJECT["keep_all_strings"], ], [ - UploadFile::PROJECT_ID => UploadFileStub2::PROJECT_ID, + UploadFile::PROJECT_ID => UploadFileStub1::PROJECT["id"], UploadFile::SOURCE_FILE_PATH => $uploadFileStub2->getFormattedFilePath(), - UploadFile::FILE_FORMAT => UploadFileStub2::FILE_FORMAT, + UploadFile::FILE_FORMAT => UploadFileStub1::PROJECT["file_format"], UploadFile::SOURCE_LOCALE => UploadFileStub2::SOURCE_LOCALE, - UploadFile::IS_KEEPING_ALL_STRINGS => UploadFileStub2::IS_KEEPING_ALL_STRINGS + UploadFile::IS_KEEPING_ALL_STRINGS => UploadFileStub1::PROJECT["keep_all_strings"], ], ], ClientMock::$parameters @@ -150,13 +150,14 @@ public function WithOneFile_download_Download() ClientMock::$parameters, [ [ - ExportFile::PROJECT_ID => ExportFileStub1::PROJECT_ID, + ExportFile::PROJECT_ID => ExportFileStub1::PROJECT["id"], ExportFile::REQUESTED_LOCALE => ExportFileStub1::REQUESTED_LOCALE, ExportFile::REQUESTED_SOURCE_FILE_NAME => $exportFileStub1->getEncodedSourceFileName(), + ExportFile::FILE_FORMAT => ExportFileStub1::PROJECT["file_format"], ], ] ); - $this->assertStringEqualsFile(self::EXPECTED_DOWNLOADED_FILE_1, 'Download : 1'); + $this->assertStringEqualsFile(self::EXPECTED_DOWNLOADED_FILE_1, "Download: 1\n"); $this->assertEquals([new ExportFileStub1()], $downloadedTranslations); } @@ -173,19 +174,21 @@ public function WithManyFiles_upload_Upload() ClientMock::$parameters, [ [ - ExportFile::PROJECT_ID => ExportFileStub1::PROJECT_ID, + ExportFile::PROJECT_ID => ExportFileStub1::PROJECT["id"], ExportFile::REQUESTED_LOCALE => ExportFileStub1::REQUESTED_LOCALE, ExportFile::REQUESTED_SOURCE_FILE_NAME => $exportFileStub1->getEncodedSourceFileName(), + ExportFile::FILE_FORMAT => ExportFileStub1::PROJECT["file_format"], ], [ - ExportFile::PROJECT_ID => ExportFileStub2::PROJECT_ID, + ExportFile::PROJECT_ID => ExportFileStub2::PROJECT["id"], ExportFile::REQUESTED_LOCALE => ExportFileStub2::REQUESTED_LOCALE, ExportFile::REQUESTED_SOURCE_FILE_NAME => $exportFileStub2->getEncodedSourceFileName(), + ExportFile::FILE_FORMAT => ExportFileStub1::PROJECT["file_format"], ], ] ); - $this->assertStringEqualsFile(self::EXPECTED_DOWNLOADED_FILE_1, 'Download : 1'); - $this->assertStringEqualsFile(self::EXPECTED_DOWNLOADED_FILE_2, 'Download : 2'); + $this->assertStringEqualsFile(self::EXPECTED_DOWNLOADED_FILE_1, "Download: 1\n"); + $this->assertStringEqualsFile(self::EXPECTED_DOWNLOADED_FILE_2, "Download: 2\n"); $this->assertEquals([new ExportFileStub1(), new ExportFileStub2()], $downloadedTranslations); } diff --git a/Tests/Gateways/Impl/LanguageGatewayImplTest.php b/Tests/Gateways/Impl/LanguageGatewayImplTest.php index 6176bd8..7231ab3 100644 --- a/Tests/Gateways/Impl/LanguageGatewayImplTest.php +++ b/Tests/Gateways/Impl/LanguageGatewayImplTest.php @@ -8,6 +8,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\Language; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub1; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub2; +use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\ProjectsStub; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\OneSky\Api\ClientMock; /** @@ -20,8 +21,6 @@ class LanguageGatewayImplTest extends \PHPUnit_Framework_TestCase */ private $gateway; - const PROJECT_ID = 1; - /** * @test * @expectedException \OpenClassrooms\Bundle\OneSkyBundle\Gateways\LanguageException @@ -29,7 +28,7 @@ class LanguageGatewayImplTest extends \PHPUnit_Framework_TestCase public function ApiException_findLanguage_ThrowException() { ClientMock::$languagesContent = '{"meta": {"status": 400}}'; - $this->gateway->findLanguages([], self::PROJECT_ID); + $this->gateway->findLanguages([], ProjectsStub::$projects[1]); } /** @@ -38,7 +37,7 @@ public function ApiException_findLanguage_ThrowException() */ public function NonExistingLanguage_findLanguages_ThrowException() { - $this->gateway->findLanguages(['fr'], self::PROJECT_ID); + $this->gateway->findLanguages(['fr'], ProjectsStub::$projects[1]); } /** @@ -46,7 +45,7 @@ public function NonExistingLanguage_findLanguages_ThrowException() */ public function findLanguages() { - $actualLanguages = $this->gateway->findLanguages([LanguageStub1::LOCALE, LanguageStub2::LOCALE], self::PROJECT_ID); + $actualLanguages = $this->gateway->findLanguages([LanguageStub1::LOCALE, LanguageStub2::LOCALE], ProjectsStub::$projects[1]); $expectedLanguages = [new LanguageStub1(), new LanguageStub2()]; $this->assertEquals(LanguageGateway::LANGUAGES_METHOD, ClientMock::$action); $this->assertEquals(['project_id' => 1], ClientMock::$parameters); diff --git a/Tests/Services/Impl/LanguageServiceImplTest.php b/Tests/Services/Impl/LanguageServiceImplTest.php index 5455d11..a4e72f7 100644 --- a/Tests/Services/Impl/LanguageServiceImplTest.php +++ b/Tests/Services/Impl/LanguageServiceImplTest.php @@ -7,6 +7,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Gateways\InMemoryLanguageGateway; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub1; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\LanguageStub2; +use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\ProjectsStub; /** * @author Romain Kuzniak @@ -18,15 +19,13 @@ class LanguageServiceImplTest extends \PHPUnit_Framework_TestCase */ private $service; - const PROJECT_ID = 1; - /** * @test */ public function WithoutLocales_getLanguage() { - $languages = $this->service->getLanguages(self::PROJECT_ID); - $this->assertEquals([self::PROJECT_ID => [new LanguageStub2()]], $languages); + $languages = $this->service->getLanguages(ProjectsStub::$projects[1], ProjectsStub::$projects[1]['locales']); + $this->assertEquals([ProjectsStub::$projects[1]["id"] => [new LanguageStub1(), new LanguageStub2()]], $languages); } /** @@ -34,8 +33,8 @@ public function WithoutLocales_getLanguage() */ public function getLanguage() { - $languages = $this->service->getLanguages(self::PROJECT_ID, [LanguageStub1::LOCALE, LanguageStub2::LOCALE]); - $this->assertEquals([self::PROJECT_ID => [new LanguageStub1(), new LanguageStub2()]], $languages); + $languages = $this->service->getLanguages(ProjectsStub::$projects[1], [LanguageStub1::LOCALE]); + $this->assertEquals([ProjectsStub::$projects[1]["id"] => [new LanguageStub1()]], $languages); } /** @@ -46,9 +45,8 @@ protected function setUp() $this->service = new LanguageServiceImpl(); $this->service->setLanguageGateway( new InMemoryLanguageGateway( - [self::PROJECT_ID => [LanguageStub1::LOCALE => new LanguageStub1(), LanguageStub2::LOCALE => new LanguageStub2()]] + [ProjectsStub::$projects[1]["id"] => [LanguageStub1::LOCALE => new LanguageStub1(), LanguageStub2::LOCALE => new LanguageStub2()]] ) ); - $this->service->setRequestedLocales(['ja']); } } diff --git a/Tests/Services/Impl/TranslationServiceImplTest.php b/Tests/Services/Impl/TranslationServiceImplTest.php index 7cbd902..1423397 100644 --- a/Tests/Services/Impl/TranslationServiceImplTest.php +++ b/Tests/Services/Impl/TranslationServiceImplTest.php @@ -7,6 +7,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\Impl\UploadFileImpl; use OpenClassrooms\Bundle\OneSkyBundle\Services\Impl\TranslationServiceImpl; use OpenClassrooms\Bundle\OneSkyBundle\Services\TranslationService; +use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Model\ProjectsStub; use OpenClassrooms\Bundle\OneSkyBundle\Tests\Doubles\Services\FileServiceMock; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -15,13 +16,8 @@ */ class TranslationServiceImplTest extends \PHPUnit_Framework_TestCase { - const IS_KEEPING_ALL_STRINGS = false; - const FILE_FORMAT = 'yml'; - const FILE_FORMATS = [1 => 'yml']; const KERNEL_ROOT_DIR = __DIR__.'/../../'; const PROJECT_DIRECTORY = __DIR__.'/../../../'; - const SOURCE_LOCALE = 'en'; - const PROJECT_ID = 1; /** * @var TranslationService @@ -33,9 +29,21 @@ class TranslationServiceImplTest extends \PHPUnit_Framework_TestCase */ public function pull_with_locales() { - $this->service->pull(self::PROJECT_ID , [__DIR__.'/../../Fixtures/Resources/translations'], ['es']); + $this->service->pull([] , ProjectsStub::$projects[1]["file_paths"], ['ja']); $this->assertEquals( - [$this->buildExportFile1es(), $this->buildExportFile2es()], + [$this->buildExportFile1ja(), $this->buildExportFile2ja()], + FileServiceMock::$downloadedFiles + ); + } + + /** + * @test + */ + public function pull_with_locales_and_projects() + { + $this->service->pull([1] , ProjectsStub::$projects[1]["file_paths"], ['ja']); + $this->assertEquals( + [$this->buildExportFile1ja(), $this->buildExportFile2ja()], FileServiceMock::$downloadedFiles ); } @@ -43,24 +51,24 @@ public function pull_with_locales() /** * @return ExportFileImpl */ - private function buildExportFile1es() + private function buildExportFile1ja() { return new ExportFileImpl( - self::PROJECT_ID, __DIR__.'/../../Fixtures/Resources/translations/messages.en.yml', + ProjectsStub::$projects[1], ProjectsStub::$projects[1]["file_paths"][0].'messages.en.yml', self::PROJECT_DIRECTORY, - 'es' + 'ja' ); } /** * @return ExportFileImpl */ - private function buildExportFile2es() + private function buildExportFile2ja() { return new ExportFileImpl( - self::PROJECT_ID, __DIR__.'/../../Fixtures/Resources/translations/subDirectory/messages.en.yml', + ProjectsStub::$projects[1], ProjectsStub::$projects[1]["file_paths"][0].'subDirectory/messages.en.yml', self::PROJECT_DIRECTORY, - 'es' + 'ja' ); } @@ -69,13 +77,13 @@ private function buildExportFile2es() */ public function WithoutFilePaths_pull() { - $this->service->pull(self::PROJECT_ID, []); + $this->service->pull([], []); $this->assertEquals( [ - $this->buildExportFile1fr(), - $this->buildExportFile1es(), - $this->buildExportFile2fr(), - $this->buildExportFile2es(), + $this->buildExportFile1en(), + $this->buildExportFile1ja(), + $this->buildExportFile2en(), + $this->buildExportFile2ja(), ], FileServiceMock::$downloadedFiles ); @@ -84,24 +92,24 @@ public function WithoutFilePaths_pull() /** * @return ExportFileImpl */ - private function buildExportFile1fr() + private function buildExportFile1en() { return new ExportFileImpl( - self::PROJECT_ID, __DIR__.'/../../Fixtures/Resources/translations/messages.en.yml', + ProjectsStub::$projects[1], ProjectsStub::$projects[1]["file_paths"][0].'messages.en.yml', self::PROJECT_DIRECTORY, - 'fr' + 'en' ); } /** * @return ExportFileImpl */ - private function buildExportFile2fr() + private function buildExportFile2en() { return new ExportFileImpl( - self::PROJECT_ID, __DIR__.'/../../Fixtures/Resources/translations/subDirectory/messages.en.yml', + ProjectsStub::$projects[1], ProjectsStub::$projects[1]["file_paths"][0].'subDirectory/messages.en.yml', self::PROJECT_DIRECTORY, - 'fr' + 'en' ); } @@ -110,11 +118,26 @@ private function buildExportFile2fr() */ public function pull() { - $this->service->pull(self::PROJECT_ID, [__DIR__.'/../../Fixtures/Resources/translations/subDirectory']); + $this->service->pull([], [ProjectsStub::$projects[1]["file_paths"][0].'subDirectory']); + $this->assertEquals( + [ + $this->buildExportFile2en(), + $this->buildExportFile2ja(), + ], + FileServiceMock::$downloadedFiles + ); + } + + /** + * @test + */ + public function pull_with_projects() + { + $this->service->pull([1], [ProjectsStub::$projects[1]["file_paths"][0].'subDirectory']); $this->assertEquals( [ - $this->buildExportFile2fr(), - $this->buildExportFile2es(), + $this->buildExportFile2en(), + $this->buildExportFile2ja(), ], FileServiceMock::$downloadedFiles ); @@ -125,7 +148,7 @@ public function pull() */ public function WithoutFilePath_push() { - $this->service->push(self::PROJECT_ID, []); + $this->service->push([], []); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); } @@ -135,13 +158,11 @@ public function WithoutFilePath_push() private function buildUploadFile1() { $file = new UploadFileImpl( - self::PROJECT_ID, - __DIR__.'/../../Fixtures/Resources/translations/messages.en.yml', + ProjectsStub::$projects[1], + ProjectsStub::$projects[1]["file_paths"][0].'messages.en.yml', self::PROJECT_DIRECTORY, - self::FILE_FORMAT, - self::SOURCE_LOCALE + 'en' ); - $file->setKeepingAllStrings(self::IS_KEEPING_ALL_STRINGS); return $file; } @@ -152,13 +173,11 @@ private function buildUploadFile1() private function buildUploadFile2() { $file = new UploadFileImpl( - self::PROJECT_ID, - __DIR__.'/../../Fixtures/Resources/translations/subDirectory/messages.en.yml', + ProjectsStub::$projects[1], + ProjectsStub::$projects[1]["file_paths"][0].'subDirectory/messages.en.yml', self::PROJECT_DIRECTORY, - self::FILE_FORMAT, - self::SOURCE_LOCALE + 'en' ); - $file->setKeepingAllStrings(self::IS_KEEPING_ALL_STRINGS); return $file; } @@ -168,7 +187,34 @@ private function buildUploadFile2() */ public function push() { - $this->service->push(self::PROJECT_ID, [__DIR__.'/../../Fixtures/Resources/*']); + $this->service->push([], ProjectsStub::$projects[1]["file_paths"]); + $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); + } + + /** + * @test + */ + public function push_with_projects() + { + $this->service->push([1], ProjectsStub::$projects[1]["file_paths"]); + $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); + } + + /** + * @test + */ + public function push_with_locales() + { + $this->service->push([], ProjectsStub::$projects[1]["file_paths"], ["en"]); + $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); + } + + /** + * @test + */ + public function push_with_projects_and_locales() + { + $this->service->push([1], ProjectsStub::$projects[1]["file_paths"], ["en"]); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); } @@ -177,9 +223,22 @@ public function push() */ public function WithLocales_update_Update() { - $this->service->update(self::PROJECT_ID, [__DIR__.'/../../Fixtures/Resources/'], ['es']); + $this->service->update([], ProjectsStub::$projects[1]["file_paths"], ['ja']); + $this->assertEquals( + [$this->buildExportFile1ja(), $this->buildExportFile2ja()], + FileServiceMock::$downloadedFiles + ); + $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); + } + + /** + * @test + */ + public function WithLocales_and_projects_update_Update() + { + $this->service->update([1], ProjectsStub::$projects[1]["file_paths"], ['ja']); $this->assertEquals( - [$this->buildExportFile1es(), $this->buildExportFile2es()], + [$this->buildExportFile1ja(), $this->buildExportFile2ja()], FileServiceMock::$downloadedFiles ); $this->assertEquals([$this->buildUploadFile1(), $this->buildUploadFile2()], FileServiceMock::$uploadedFiles); @@ -192,16 +251,10 @@ protected function setUp() { $this->service = new TranslationServiceImpl(); $fileFactory = new FileFactoryImpl(); - $fileFactory->setKeepingAllStrings(self::IS_KEEPING_ALL_STRINGS); - $fileFactory->setFileFormat(self::FILE_FORMAT, self::FILE_FORMATS); $fileFactory->setKernelRootDir(self::KERNEL_ROOT_DIR); - $fileFactory->setSourceLocale(self::SOURCE_LOCALE); $this->service->setEventDispatcher(new EventDispatcher()); $this->service->setFileFactory($fileFactory); - $this->service->setFileFormat(self::FILE_FORMAT, self::FILE_FORMATS); - $this->service->setFilePaths([ self::PROJECT_ID => [__DIR__.'/../../Fixtures/Resources/*']]); $this->service->setFileService(new FileServiceMock()); - $this->service->setRequestedLocales(['fr', 'es']); - $this->service->setSourceLocale(self::SOURCE_LOCALE); + $this->service->setProjects([1 => ProjectsStub::$projects[1]]); } } From 129e74d0660ad57aa6ca4b446d5fdc435f1898a9 Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Thu, 30 Mar 2017 12:07:29 +0200 Subject: [PATCH 10/13] Update travis config for yaml extension --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ed2e50c..6a196a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,14 @@ language: php php: - - "5.6" - "7.0" before_script: - composer self-update - composer install --no-scripts --no-interaction - composer dump-autoload -o + - apt-get install php-pear libyaml-dev + - pecl install yaml-2.0.0 after_script: - php vendor/bin/coveralls -v From d71993787bfd86df73ca89fdb5968891d3cb3c91 Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Thu, 30 Mar 2017 12:12:04 +0200 Subject: [PATCH 11/13] Install libyaml-dev and php-pear --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6a196a9..9b65866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,11 @@ language: php +addons: + apt: + packages: + - php-pear + - libyaml-dev + php: - "7.0" @@ -7,7 +13,6 @@ before_script: - composer self-update - composer install --no-scripts --no-interaction - composer dump-autoload -o - - apt-get install php-pear libyaml-dev - pecl install yaml-2.0.0 after_script: From 495c199ce4cb16daf67a82288e88a96962e3f438 Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Thu, 30 Mar 2017 12:31:03 +0200 Subject: [PATCH 12/13] Avoid interactions for pecl install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9b65866..92d4ec4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_script: - composer self-update - composer install --no-scripts --no-interaction - composer dump-autoload -o - - pecl install yaml-2.0.0 + - yes '' | pecl install yaml-2.0.0 after_script: - php vendor/bin/coveralls -v From 07e54a3345d2e8d01e41a07d393926edabb2e7ea Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Mon, 12 Mar 2018 15:07:13 +0100 Subject: [PATCH 13/13] Update config for SF3.4 --- DependencyInjection/Configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f626341..d101179 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,8 +25,8 @@ public function getConfigTreeBuilder() ->children() ->scalarNode('file_format')->cannotBeEmpty()->defaultValue('xliff')->end() ->scalarNode('source_locale')->cannotBeEmpty()->defaultValue('en')->end() - ->arrayNode('file_paths')->cannotBeEmpty()->prototype('scalar')->end()->end() - ->arrayNode('locales')->cannotBeEmpty()->prototype('scalar')->end()->end() + ->arrayNode('file_paths')->requiresAtLeastOneElement()->prototype('scalar')->end()->end() + ->arrayNode('locales')->requiresAtLeastOneElement()->prototype('scalar')->end()->end() ->scalarNode('keep_all_strings')->cannotBeEmpty()->defaultValue(true)->end() ->end() ->end()