From 372cca576f9d7971efee766e34b790fa9a0dad57 Mon Sep 17 00:00:00 2001 From: Bart McLeod Date: Sat, 17 Feb 2024 11:15:01 +0100 Subject: [PATCH] Remove propel support and fix unit tests (differences in loading files with odm definitions) --- .gitignore | 2 - DependencyInjection/Configuration.php | 1 - .../LexikTranslationExtension.php | 3 - Form/Handler/TransUnitFormHandler.php | 6 - Model/File.php | 138 ++----- Propel/File.php | 37 -- Propel/FileQuery.php | 9 - Propel/FileRepository.php | 44 --- Propel/TransUnit.php | 51 --- Propel/TransUnitQuery.php | 9 - Propel/TransUnitRepository.php | 254 ------------- Propel/Translation.php | 10 - Propel/TranslationQuery.php | 9 - Propel/TranslationRepository.php | 40 -- ...{File.mongodb.xml => File.mongodb-odm.xml} | 0 ....mongodb.xml => TransUnit.mongodb-odm.xml} | 0 ...ongodb.xml => Translation.mongodb-odm.xml} | 0 ...{File.mongodb.xml => File.mongodb-odm.xml} | 0 ....mongodb.xml => TransUnit.mongodb-odm.xml} | 0 ...ongodb.xml => Translation.mongodb-odm.xml} | 0 Resources/config/propel/schema.xml | 53 --- Resources/config/services.xml | 5 - Resources/doc/index.md | 6 +- Resources/doc/testing.md | 2 +- Storage/PropelStorage.php | 355 ------------------ Storage/StorageInterface.php | 1 - Tests/Fixtures/TransUnitDataPropel.php | 109 ------ Tests/Unit/BaseUnitTestCase.php | 68 +--- .../Repository/Propel/FileRepositoryTest.php | 59 --- .../Propel/TransUnitRepositoryTest.php | 317 ---------------- .../Translation/Manager/FileManagerTest.php | 60 --- .../Manager/TransUnitManagerTest.php | 104 +---- Tests/Unit/Translation/TranslatorTest.php | 2 +- Tests/app/AppKernel.php | 8 - composer.json | 24 +- phpunit.xml.dist | 1 - rector.php | 1 - 37 files changed, 58 insertions(+), 1730 deletions(-) delete mode 100644 Propel/File.php delete mode 100644 Propel/FileQuery.php delete mode 100644 Propel/FileRepository.php delete mode 100644 Propel/TransUnit.php delete mode 100644 Propel/TransUnitQuery.php delete mode 100644 Propel/TransUnitRepository.php delete mode 100644 Propel/Translation.php delete mode 100644 Propel/TranslationQuery.php delete mode 100644 Propel/TranslationRepository.php rename Resources/config/doctrine/{File.mongodb.xml => File.mongodb-odm.xml} (100%) rename Resources/config/doctrine/{TransUnit.mongodb.xml => TransUnit.mongodb-odm.xml} (100%) rename Resources/config/doctrine/{Translation.mongodb.xml => Translation.mongodb-odm.xml} (100%) rename Resources/config/model/{File.mongodb.xml => File.mongodb-odm.xml} (100%) rename Resources/config/model/{TransUnit.mongodb.xml => TransUnit.mongodb-odm.xml} (100%) rename Resources/config/model/{Translation.mongodb.xml => Translation.mongodb-odm.xml} (100%) delete mode 100644 Resources/config/propel/schema.xml delete mode 100644 Storage/PropelStorage.php delete mode 100644 Tests/Fixtures/TransUnitDataPropel.php delete mode 100644 Tests/Unit/Repository/Propel/FileRepositoryTest.php delete mode 100644 Tests/Unit/Repository/Propel/TransUnitRepositoryTest.php diff --git a/.gitignore b/.gitignore index 6db1fa57..8b6fbbeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ vendor composer.lock -Propel/map -Propel/om Tests/app/tmp/ diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 257bb0d8..dbf26632 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -27,7 +27,6 @@ public function getConfigTreeBuilder(): TreeBuilder $storages = [ StorageInterface::STORAGE_ORM, StorageInterface::STORAGE_MONGODB, - StorageInterface::STORAGE_PROPEL, ]; $registrationTypes = ['all', 'files', 'database']; $inputTypes = ['text', 'textarea']; diff --git a/DependencyInjection/LexikTranslationExtension.php b/DependencyInjection/LexikTranslationExtension.php index ba87e4e2..4d4c2138 100644 --- a/DependencyInjection/LexikTranslationExtension.php +++ b/DependencyInjection/LexikTranslationExtension.php @@ -169,9 +169,6 @@ protected function buildTranslationStorageDefinition(ContainerBuilder $container $args = [new Reference('doctrine_mongodb'), $objectManager ?? 'default']; $this->createDoctrineMappingDriver($container, 'lexik_translation.mongodb.metadata.xml', '%doctrine_mongodb.odm.metadata.xml.class%'); - } elseif (StorageInterface::STORAGE_PROPEL == $storage) { - // In the Propel case the object_manager setting is used for the connection name - $args = [$objectManager]; } else { throw new \RuntimeException(sprintf('Unsupported storage "%s".', $storage)); } diff --git a/Form/Handler/TransUnitFormHandler.php b/Form/Handler/TransUnitFormHandler.php index b140203d..68bbc4f7 100644 --- a/Form/Handler/TransUnitFormHandler.php +++ b/Form/Handler/TransUnitFormHandler.php @@ -7,7 +7,6 @@ use Lexik\Bundle\TranslationBundle\Manager\FileInterface; use Lexik\Bundle\TranslationBundle\Manager\FileManagerInterface; use Lexik\Bundle\TranslationBundle\Storage\StorageInterface; -use Lexik\Bundle\TranslationBundle\Propel\TransUnit as PropelTransUnit; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; @@ -76,11 +75,6 @@ public function process(FormInterface $form, Request $request) } } - if ($transUnit instanceof PropelTransUnit) { - // The setTranslations() method only accepts PropelCollections - $translations = new \PropelObjectCollection($translations); - } - $transUnit->setTranslations($translations); $this->storage->persist($transUnit); diff --git a/Model/File.php b/Model/File.php index 21d125ca..4788c853 100644 --- a/Model/File.php +++ b/Model/File.php @@ -2,7 +2,9 @@ namespace Lexik\Bundle\TranslationBundle\Model; + use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Symfony\Component\Validator\Constraints as Assert; /** @@ -12,155 +14,90 @@ */ abstract class File { - /** - * @var int - */ protected $id; /** - * @var string - * * @Assert\NotBlank() */ - protected $domain; + protected string $domain; /** - * @var string - * * @Assert\NotBlank() */ - protected $locale; + protected string $locale; /** - * @var string - * * @Assert\NotBlank() */ - protected $extention; + protected string $extention; /** - * @var string - * * @Assert\NotBlank() */ - protected $path; + protected string $path; /** - * @var string - * * @Assert\NotBlank() */ - protected $hash; + protected string $hash; - /** - * @var Doctrine\Common\Collections\Collection - */ - protected $translations; + protected Collection $translations; + + protected $createdAt; + + protected $updatedAt; - /** - * Construct. - */ public function __construct() { $this->translations = new ArrayCollection(); } - /** - * Get id - * - * @return int - */ public function getId() { return $this->id; } - /** - * Set domain - * - * @param string $domain - */ - public function setDomain($domain) + public function setDomain(string $domain): void { $this->domain = $domain; } - /** - * Get domain - * - * @return string - */ - public function getDomain() + public function getDomain(): string { return $this->domain; } - /** - * Set locale - * - * @param string $locale - */ - public function setLocale($locale) + public function setLocale(string $locale): void { $this->locale = $locale; } - /** - * Get locale - * - * @return string - */ - public function getLocale() + public function getLocale(): string { return $this->locale; } - /** - * Set extention - * - * @param string $extention - */ - public function setExtention($extention) + public function setExtention(string $extention): void { $this->extention = $extention; } - /** - * Get extention - * - * @return string - */ - public function getExtention() + public function getExtention(): string { return $this->extention; } - /** - * Set path - * - * @param string $path - */ - public function setPath($path) + public function setPath(string $path): void { $this->path = $path; } - /** - * Get path - * - * @return string - */ - public function getPath() + public function getPath(): string { return $this->path; } - /** - * Set file name - * - * @param string $name - */ - public function setName($name) + public function setName(string $name): void { [$domain, $locale, $extention] = explode('.', $name); @@ -169,52 +106,29 @@ public function setName($name) $this->extention = $extention; } - /** - * Get file name - * - * @return string - */ - public function getName() + public function getName(): string { return sprintf('%s.%s.%s', $this->domain, $this->locale, $this->extention); } - /** - * Set hash - * - * @return string - */ - public function setHash($hash) + public function setHash(string $hash): void { $this->hash = $hash; } - /** - * Get hash - * - * @return string - */ - public function getHash() + public function getHash(): string { return $this->hash; } - /** - * Add translation - */ - public function addTranslation(\Lexik\Bundle\TranslationBundle\Model\Translation $translation) + public function addTranslation(Translation $translation): void { $translation->setFile($this); $this->translations[] = $translation; } - /** - * Get translations - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getTranslations() + public function getTranslations(): Collection { return $this->translations; } diff --git a/Propel/File.php b/Propel/File.php deleted file mode 100644 index d502f6d4..00000000 --- a/Propel/File.php +++ /dev/null @@ -1,37 +0,0 @@ -setDomain($domain) - ->setLocale($locale) - ->setExtention($extention) - ; - - return $this; - } - - /** - * Get file name - * - * @return string - */ - public function getName() - { - return sprintf('%s.%s.%s', $this->getDomain(), $this->getLocale(), $this->getExtention()); - } -} diff --git a/Propel/FileQuery.php b/Propel/FileQuery.php deleted file mode 100644 index 19e4ceb9..00000000 --- a/Propel/FileQuery.php +++ /dev/null @@ -1,9 +0,0 @@ - - */ -class FileRepository -{ - public function __construct( - protected ConnectionWrapper $connection - ) { - } - - /** - * @return ConnectionWrapper - */ - protected function getConnection() - { - return $this->connection; - } - - /** - * Returns all files matching a given locale and a given domains. - * - * @return array - */ - public function findForLocalesAndDomains(array $locales, array $domains) - { - return FileQuery::create() - ->_if(count($locales) > 0) - ->filterByLocale($locales, Criteria::IN) - ->_endif() - ->_if(count($domains) > 0) - ->filterByDomain($domains, Criteria::IN) - ->_endif() - ->find($this->getConnection()); - } -} diff --git a/Propel/TransUnit.php b/Propel/TransUnit.php deleted file mode 100644 index c60e05d3..00000000 --- a/Propel/TransUnit.php +++ /dev/null @@ -1,51 +0,0 @@ -getTranslations()->getArrayCopy(), function (TranslationInterface $translation) { - $content = $translation->getContent(); - - return !empty($content); - }); - } - - /** (non-PHPdoc) - * @see \Lexik\Bundle\TranslationBundle\Manager\TransUnitInterface::hasTranslation() - */ - public function hasTranslation($locale): bool - { - return null !== $this->getTranslation($locale); - } - - /** - * Return the content of translation for the given locale. - * - * @param string $locale - * @return Translation - */ - public function getTranslation($locale) - { - foreach ($this->getTranslations() as $translation) { - if ($translation->getLocale() == $locale) { - return $translation; - } - } - - return null; - } -} diff --git a/Propel/TransUnitQuery.php b/Propel/TransUnitQuery.php deleted file mode 100644 index ca39ad7b..00000000 --- a/Propel/TransUnitQuery.php +++ /dev/null @@ -1,9 +0,0 @@ - - */ -class TransUnitRepository -{ - public function __construct( - protected ConnectionWrapper $connection - ) { - } - - /** - * @return ConnectionWrapper - */ - protected function getConnection() - { - return $this->connection; - } - - /** - * Returns all domain available in database. - * - * @return array - */ - public function getAllDomainsByLocale() - { - return TransUnitQuery::create() - ->joinWith('Translation') - ->withColumn('Translation.Locale', 'locale') - ->withColumn('Domain', 'domain') - ->select(['locale', 'domain']) - ->groupBy('locale') - ->groupBy('domain') - ->find($this->getConnection()) - ->getArrayCopy(); - } - - /** - * Returns all domains for each locale. - * - * @param string $locale - * @param string $domain - * @return array - */ - public function getAllByLocaleAndDomain($locale, $domain) - { - $unitsData = TransUnitQuery::create() - ->filterByDomain($domain) - ->joinWith('Translation') - ->useTranslationQuery() - ->filterByLocale($locale) - ->endUse() - ->setFormatter(ModelCriteria::FORMAT_ARRAY) - ->find($this->getConnection()); - - return $this->filterTransUnitData($unitsData); - } - - /** - * Returns all trans unit with translations for the given domain and locale. - * - * @return array - */ - public function getAllDomains() - { - $domains = TransUnitQuery::create() - ->select('Domain') - ->setDistinct() - ->orderByDomain(Criteria::ASC) - ->find($this->getConnection()); - - return array_values($domains->getArrayCopy()); - } - - /** - * Returns some trans units with their translations. - * - * @param int $rows - * @param int $page - * @return array - */ - public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null) - { - $sortColumn = $filters['sidx'] ?? 'id'; - $order = $filters['sord'] ?? 'ASC'; - - $sortColumn = ucfirst((string)$sortColumn); - - $query = TransUnitQuery::create() - ->select('Id'); - - $this->addTransUnitFilters($query, $filters); - $this->addTranslationFilter($query, $locales, $filters); - - $ids = $query - ->orderBy($sortColumn, $order) - ->offset($rows * ($page - 1)) - ->limit($rows) - ->find($this->getConnection()); - - $transUnits = []; - - if ((is_countable($ids) ? count($ids) : 0) > 0) { - $unitsData = TransUnitQuery::create() - ->filterById($ids, Criteria::IN) - ->joinWith('Translation') - ->useTranslationQuery() - ->filterByLocale($locales, Criteria::IN) - ->endUse() - ->orderBy($sortColumn, $order) - ->setFormatter(ModelCriteria::FORMAT_ARRAY) - ->find($this->getConnection()); - - $transUnits = $this->filterTransUnitData($unitsData); - } - - return $transUnits; - } - - /** - * Count the number of trans unit. - * - * @return int - */ - public function count(array $locales = null, array $filters = null) - { - $query = TransUnitQuery::create() - ->select('Id') - ->distinct(); - - $this->addTransUnitFilters($query, $filters); - $this->addTranslationFilter($query, $locales, $filters); - - return $query->count($this->getConnection()); - } - - /** - * Returns all translations for the given file. - * - * @param File $file - * @param boolean $onlyUpdated - * - * @return array - */ - public function getTranslationsForFile($file, $onlyUpdated) - { - $query = TranslationQuery::create() - ->filterByFile($file) - ->joinWith('TransUnit'); - - if ($onlyUpdated) { - $query->add(null, TranslationTableMap::COL_UPDATED_AT . '>' . TranslationTableMap::COL_CREATED_AT, Criteria::CUSTOM); - } - - $results = $query - ->select(['Content', 'TransUnit.Key']) - ->orderBy(TranslationTableMap::COL_ID, Criteria::ASC) - ->find(); - - $translations = []; - foreach ($results as $result) { - $translations[$result['TransUnit.Key']] = $result['Content']; - } - - return $translations; - } - - /** - * Add conditions according to given filters. - */ - protected function addTransUnitFilters(TransUnitQuery $query, array $filters = null) - { - if (isset($filters['_search']) && $filters['_search']) { - if (!empty($filters['domain'])) { - $query->filterByDomain(sprintf('%%%s%%', $filters['domain']), Criteria::LIKE); - } - - if (!empty($filters['key'])) { - $query->filterByKey(sprintf('%%%s%%', $filters['key']), Criteria::LIKE); - } - } - } - - /** - * Add conditions according to given filters. - */ - protected function addTranslationFilter(TransUnitQuery $query, array $locales = null, array $filters = null) - { - if (null !== $locales) { - $q = TransUnitQuery::create() - ->select('Id') - ->distinct() - ->join('Translation', Criteria::LEFT_JOIN) - ->useTranslationQuery() - ->filterByLocale($locales, Criteria::IN); - - foreach ($locales as $locale) { - if (!empty($filters[$locale])) { - $q - ->filterByContent(sprintf('%%%s%%', $filters[$locale]), Criteria::LIKE) - ->filterByLocale(sprintf('%s', $locale)); - } - } - - $ids = $q - ->endUse() - ->find($this->getConnection()); - - if ((is_countable($ids) ? count($ids) : 0) > 0) { - $query->filterById($ids, Criteria::IN); - } - } - } - - /** - * Convert transUnit data with nested translations into the required format. - * - * @param array|PropelArrayCollection $transUnitData - * @return array - */ - protected function filterTransUnitData($unitsData) - { - $cleaned = []; - - foreach ($unitsData as $unit) { - /* @var $unit TransUnit */ - $transUnit = ['id' => $unit['Id'], - 'key' => $unit['Key'], - 'domain' => $unit['Domain'], - 'translations' => [], - ]; - - foreach ($unit['Translations'] as $translation) { - $transUnit['translations'][] = ['locale' => $translation['Locale'], - 'content' => $translation['Content'], - ]; - } - - $cleaned[] = $transUnit; - } - - return $cleaned; - } -} diff --git a/Propel/Translation.php b/Propel/Translation.php deleted file mode 100644 index dc1bb6d4..00000000 --- a/Propel/Translation.php +++ /dev/null @@ -1,10 +0,0 @@ - - */ -class TranslationRepository -{ - public function __construct( - protected ConnectionWrapper $connection - ) { - } - - /** - * @return ConnectionWrapper - */ - protected function getConnection() - { - return $this->connection; - } - - /** - * @return \DateTime|null - */ - public function getLatestTranslationUpdatedAt() - { - $result = TranslationQuery::create() - ->withColumn(sprintf('MAX(%s)', TranslationTableMap::COL_UPDATED_AT), 'max_updated_at') - ->select(['max_updated_at']) - ->findOne($this->getConnection()); - - return !empty($result) ? new \DateTime($result) : null; - } -} diff --git a/Resources/config/doctrine/File.mongodb.xml b/Resources/config/doctrine/File.mongodb-odm.xml similarity index 100% rename from Resources/config/doctrine/File.mongodb.xml rename to Resources/config/doctrine/File.mongodb-odm.xml diff --git a/Resources/config/doctrine/TransUnit.mongodb.xml b/Resources/config/doctrine/TransUnit.mongodb-odm.xml similarity index 100% rename from Resources/config/doctrine/TransUnit.mongodb.xml rename to Resources/config/doctrine/TransUnit.mongodb-odm.xml diff --git a/Resources/config/doctrine/Translation.mongodb.xml b/Resources/config/doctrine/Translation.mongodb-odm.xml similarity index 100% rename from Resources/config/doctrine/Translation.mongodb.xml rename to Resources/config/doctrine/Translation.mongodb-odm.xml diff --git a/Resources/config/model/File.mongodb.xml b/Resources/config/model/File.mongodb-odm.xml similarity index 100% rename from Resources/config/model/File.mongodb.xml rename to Resources/config/model/File.mongodb-odm.xml diff --git a/Resources/config/model/TransUnit.mongodb.xml b/Resources/config/model/TransUnit.mongodb-odm.xml similarity index 100% rename from Resources/config/model/TransUnit.mongodb.xml rename to Resources/config/model/TransUnit.mongodb-odm.xml diff --git a/Resources/config/model/Translation.mongodb.xml b/Resources/config/model/Translation.mongodb-odm.xml similarity index 100% rename from Resources/config/model/Translation.mongodb.xml rename to Resources/config/model/Translation.mongodb-odm.xml diff --git a/Resources/config/propel/schema.xml b/Resources/config/propel/schema.xml deleted file mode 100644 index b3db04fd..00000000 --- a/Resources/config/propel/schema.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
-
diff --git a/Resources/config/services.xml b/Resources/config/services.xml index d920aaac..718415b1 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -28,11 +28,6 @@ Lexik\Bundle\TranslationBundle\Document\Translation Lexik\Bundle\TranslationBundle\Document\File - Lexik\Bundle\TranslationBundle\Storage\PropelStorage - Lexik\Bundle\TranslationBundle\Propel\TransUnit - Lexik\Bundle\TranslationBundle\Propel\Translation - Lexik\Bundle\TranslationBundle\Propel\File - Lexik\Bundle\TranslationBundle\Util\DataGrid\DataGridFormatter Lexik\Bundle\TranslationBundle\Util\DataGrid\DataGridRequestHandler diff --git a/Resources/doc/index.md b/Resources/doc/index.md index e941fd77..0ac7c8eb 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -63,15 +63,15 @@ lexik_translation: *Default values are shown here.* -Configure where to store translations, by default the bundle will use Doctrine ORM but you can also use Doctrine MongoDB or Propel ORM. -You can also define the name of the entity / document manager which uses [different connection](http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html), when using propel, this can be used to specify the propel connection name. +Configure where to store translations, by default the bundle will use Doctrine ORM but you can also use Doctrine MongoDB. +You can also define the name of the entity / document manager which uses [different connection](http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html). Note that MongoDB 2.0.0 or later is required if you choose to use MongoDB. ```yml lexik_translation: storage: - type: orm # orm | mongodb | propel + type: orm # orm | mongodb object_manager: something # The name of the entity / document manager which uses different connection (see: http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html) # When using propel, this can be used to specify the propel connection name ``` diff --git a/Resources/doc/testing.md b/Resources/doc/testing.md index dc07fa5b..42c75ea5 100644 --- a/Resources/doc/testing.md +++ b/Resources/doc/testing.md @@ -19,7 +19,7 @@ $ export DB_NAME=lexik_test && export DB_USER=root && unset DB_PASSWD && unset D ``` Available variables are: - - ORM - orm system, currently we support only doctrine2, we should also support propel and mongo + - ORM - orm system, currently we support doctrine2 and mongo - DB_NAME - database name (default: lexik_translation_test) - DB_USER - database user name (default: root) - DB_PASSWD - database user password (default: null) diff --git a/Storage/PropelStorage.php b/Storage/PropelStorage.php deleted file mode 100644 index e0a0f439..00000000 --- a/Storage/PropelStorage.php +++ /dev/null @@ -1,355 +0,0 @@ - - */ -class PropelStorage implements StorageInterface -{ - /** - * @var PDO - */ - private $connection; - - private array $collections = []; - - private ?TransUnitRepository $transUnitRepository = null; - - private ?TranslationRepository $translationRepository = null; - - private ?FileRepository $fileRepository = null; - - /** - * Constructor. - * - * @param string $connectionName - */ - public function __construct(private $connectionName, private array $classes) - { - $this->initCollections(); - } - - private function initCollections() - { - $this->collections = []; - - foreach ($this->classes as $className) { - $this->initCollection($className); - } - } - - private function initCollection($className) - { - $this->collections[$className] = new ObjectCollection(); - $this->collections[$className]->setModel($className); - } - - /** - * @return PDO - */ - private function getConnection() - { - if (null === $this->connection) { - $this->connection = Propel::getConnection($this->connectionName); - } - - return $this->connection; - } - - /** - * {@inheritdoc} - */ - public function persist($entity) - { - $found = false; - - foreach ($this->classes as $className) { - if ($entity instanceof $className) { - $this->collections[$className]->append($entity); - $found = true; - - break; - } - } - - if (!$found) { - throw new RuntimeException(sprintf('Invalid entity class: "%s".', $entity::class)); - } - } - - /** - * {@inheritdoc} - */ - public function remove($entity) - { - $entity->delete(); - } - - /** - * {@inheritdoc} - */ - public function flush($entity = null) - { - if (null === $entity) { - foreach ($this->classes as $className) { - $this->collections[$className]->save(); - } - } else { - $entity->save(); - } - } - - /** - * {@inheritdoc} - */ - public function clear($entityName = null) - { - if (null === $entityName) { - $this->initCollections(); - } else { - $this->initCollection($entityName); - } - } - - /** - * {@inheritdoc} - */ - public function getModelClass($name) - { - if (!isset($this->classes[$name])) { - throw new RuntimeException(sprintf('No class defined for name "%s".', $name)); - } - - return $this->classes[$name]; - } - - /** - * {@inheritdoc} - */ - public function getFilesByLocalesAndDomains(array $locales, array $domains) - { - return $this->getFileRepository()->findForLocalesAndDomains($locales, $domains); - } - - /** - * {@inheritdoc} - */ - public function getFileByHash($hash) - { - return FileQuery::create()->findOneByHash($hash, $this->getConnection()); - } - - /** - * {@inheritdoc} - */ - public function getTransUnitDomains() - { - return $this->getTransUnitRepository()->getAllDomains(); - } - - /** - * {@inheritdoc} - */ - public function getTransUnitById($id) - { - return TransUnitQuery::create()->findOneById($id, $this->getConnection()); - } - - /** - * {@inheritdoc} - */ - public function getTransUnitByKeyAndDomain($key, $domain) - { - $key = mb_substr($key, 0, 255, 'UTF-8'); - - $fields = ['Key' => $key, 'Domain' => $domain]; - - return TransUnitQuery::create()->findOneByArray($fields, $this->getConnection()); - } - - /** - * {@inheritdoc} - */ - public function getTransUnitDomainsByLocale() - { - if (!$this->isPropelReady()) { - /* - * This method is called during Symfony console init and will fail horribly if there is either no connection - * (config not loaded yet) or no Propel base classes. - * - * To make things work the easiest way is to fail silently at this point. - */ - return []; - } - - return $this->getTransUnitRepository()->getAllDomainsByLocale(); - } - - /** - * {@inheritdoc} - */ - public function getTransUnitsByLocaleAndDomain($locale, $domain) - { - return $this->getTransUnitRepository()->getAllByLocaleAndDomain($locale, $domain); - } - - /** - * {@inheritdoc} - */ - public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null) - { - return $this->getTransUnitRepository()->getTransUnitList($locales, $rows, $page, $filters); - } - - /** - * {@inheritdoc} - */ - public function countTransUnits(array $locales = null, array $filters = null) - { - return $this->getTransUnitRepository()->count($locales, $filters); - } - - /** - * {@inheritdoc} - */ - public function getTranslationsFromFile($file, $onlyUpdated) - { - return $this->getTransUnitRepository()->getTranslationsForFile($file, $onlyUpdated); - } - - /** - * {@inheritdoc} - */ - public function getLatestUpdatedAt() - { - return $this->getTranslationRepository()->getLatestTranslationUpdatedAt(); - } - - /** - * {@inheritdoc} - */ - public function getCountTransUnitByDomains() - { - $results = TransUnitQuery::create() - ->withColumn('count(TransUnit.ID)', 'number') - ->select(['number', 'TransUnit.Domain']) - ->groupBy('TransUnit.Domain') - ->find(); - - $counts = []; - foreach ($results as $row) { - $counts[$row['TransUnit.Domain']] = (int) $row['number']; - } - - return $counts; - } - - /** - * {@inheritdoc} - */ - public function getCountTranslationByLocales($domain) - { - $results = TranslationQuery::create() - ->join('TransUnit') - ->where('TransUnit.Domain = ?', $domain) - ->withColumn('count(Translation.ID)', 'number') - ->select(['number', 'Translation.Locale']) - ->groupBy('Translation.Locale') - ->find(); - - $counts = []; - foreach ($results as $row) { - $counts[$row['Translation.Locale']] = (int) $row['number']; - } - - return $counts; - } - - /** - * Returns true if translation tables exist. - * - * @return boolean - */ - public function translationsTablesExist() - { - return true; - } - - /** - * Check if both the Propel connection and the Propel base classes are present. - * This is necessary at some points during project init / warmup. - * - * @return boolean - */ - protected function isPropelReady() - { - try { - $this->getConnection(); - } catch (PropelException) { - return false; - } - - return - class_exists('Lexik\\Bundle\\TranslationBundle\\Propel\\Base\\File') && - class_exists('Lexik\\Bundle\\TranslationBundle\\Propel\\Base\\Translation') && - class_exists('Lexik\\Bundle\\TranslationBundle\\Propel\\Base\\TransUnit') - ; - } - - /** - * Returns the TransUnit repository. - * - * @return TransUnitRepository - */ - protected function getTransUnitRepository() - { - if (null === $this->transUnitRepository) { - $this->transUnitRepository = new TransUnitRepository($this->getConnection()); - } - - return $this->transUnitRepository; - } - - /** - * Returns the TransUnit repository. - * - * @return TranslationRepository - */ - protected function getTranslationRepository() - { - if (null === $this->translationRepository) { - $this->translationRepository = new TranslationRepository($this->getConnection()); - } - - return $this->translationRepository; - } - - /** - * Returns the File repository. - * - * @return FileRepository - */ - protected function getFileRepository() - { - if (null === $this->fileRepository) { - $this->fileRepository = new FileRepository($this->getConnection()); - } - - return $this->fileRepository; - } -} diff --git a/Storage/StorageInterface.php b/Storage/StorageInterface.php index bff04c2a..1720b4b9 100644 --- a/Storage/StorageInterface.php +++ b/Storage/StorageInterface.php @@ -16,7 +16,6 @@ interface StorageInterface */ public const STORAGE_ORM = 'orm'; public const STORAGE_MONGODB = 'mongodb'; - public const STORAGE_PROPEL = 'propel'; /** * Persist the given object. diff --git a/Tests/Fixtures/TransUnitDataPropel.php b/Tests/Fixtures/TransUnitDataPropel.php deleted file mode 100644 index 5097093b..00000000 --- a/Tests/Fixtures/TransUnitDataPropel.php +++ /dev/null @@ -1,109 +0,0 @@ - - */ -class TransUnitDataPropel -{ - /** - * (non-PHPdoc) - * @see Doctrine\Common\DataFixtures.FixtureInterface::load() - */ - public function load(ConnectionWrapper $con) - { - // add files - $files = []; - $domains = [ - 'superTranslations' => ['fr', 'en', 'de'], - 'messages' => ['fr', 'en'], - ]; - - foreach ($domains as $name => $locales) { - foreach ($locales as $locale) { - $file = new File(); - $file->setDomain($name); - $file->setLocale($locale); - $file->setExtention('yml'); - $file->setPath('Resources/translations'); - $file->setHash(md5(sprintf('Resources/translations/%s.%s.yml', $name, $locale))); - - $file->save($con); - $files[$name][$locale] = $file; - } - } - - // add translations for "key.say_hello" - $transUnit = new TransUnit(); - $transUnit->setKey('key.say_hello'); - $transUnit->setDomain('superTranslations'); - - $translations = [ - 'fr' => 'salut', - 'en' => 'hello', - 'de' => 'heil', - ]; - - foreach ($translations as $locale => $content) { - $translation = new Translation(); - $translation->setLocale($locale); - $translation->setContent($content); - $translation->setFile($files['superTranslations'][$locale]); - $translation->setTransUnit($transUnit); - $translation->save($con); - } - - $transUnit->save($con); - - // add translations for "key.say_goodbye" - $transUnit = new TransUnit(); - $transUnit->setKey('key.say_goodbye'); - - $translations = [ - 'fr' => 'au revoir', - 'en' => 'goodbye', - ]; - - foreach ($translations as $locale => $content) { - $translation = new Translation(); - $translation->setLocale($locale); - $translation->setContent($content); - $translation->setFile($files['messages'][$locale]); - $translation->setTransUnit($transUnit); - $translation->save($con); - } - - $transUnit->save($con); - - // add translations for "key.say_wtf" - $transUnit = new TransUnit(); - $transUnit->setKey('key.say_wtf'); - - $translations = [ - 'fr' => 'c\'est quoi ce bordel !?!', - 'en' => 'what the fuck !?!', - ]; - - foreach ($translations as $locale => $content) { - $translation = new Translation(); - $translation->setLocale($locale); - $translation->setContent($content); - $translation->setFile($files['messages'][$locale]); - $translation->setTransUnit($transUnit); - $translation->save($con); - } - - $transUnit->save($con); - } -} diff --git a/Tests/Unit/BaseUnitTestCase.php b/Tests/Unit/BaseUnitTestCase.php index 27b5be71..60cc6311 100644 --- a/Tests/Unit/BaseUnitTestCase.php +++ b/Tests/Unit/BaseUnitTestCase.php @@ -2,7 +2,7 @@ namespace Lexik\Bundle\TranslationBundle\Tests\Unit; -use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver; +use Doctrine\ODM\MongoDB\Mapping\Driver\SimplifiedXmlDriver as XmlDriver; use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor; use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Purger\MongoDBPurger; @@ -10,6 +10,7 @@ use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; +use Doctrine\ODM\MongoDB\MongoDBException; use Doctrine\ODM\MongoDB\SchemaManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; @@ -20,17 +21,11 @@ use Doctrine\Persistence\ObjectManager; use Lexik\Bundle\TranslationBundle\Storage\DoctrineMongoDBStorage; use Lexik\Bundle\TranslationBundle\Storage\DoctrineORMStorage; -use Lexik\Bundle\TranslationBundle\Storage\PropelStorage; use Lexik\Bundle\TranslationBundle\Tests\Fixtures\TransUnitData; -use Lexik\Bundle\TranslationBundle\Tests\Fixtures\TransUnitDataPropel; use Lexik\Bundle\TranslationBundle\Util\Doctrine\SingleColumnArrayHydrator; use MongoDB\Client; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Propel\Generator\Util\QuickBuilder; -use Propel\Runtime\Connection\ConnectionWrapper; -use Propel\Runtime\Connection\PdoConnection; -use Propel\Runtime\Propel; use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -49,10 +44,6 @@ abstract class BaseUnitTestCase extends TestCase final const DOCUMENT_TRANSLATION_CLASS = 'Lexik\Bundle\TranslationBundle\Document\Translation'; final const DOCUMENT_FILE_CLASS = 'Lexik\Bundle\TranslationBundle\Document\File'; - final const PROPEL_TRANS_UNIT_CLASS = 'Lexik\Bundle\TranslationBundle\Propel\TransUnit'; - final const PROPEL_TRANSLATION_CLASS = 'Lexik\Bundle\TranslationBundle\Propel\Translation'; - final const PROPEL_FILE_CLASS = 'Lexik\Bundle\TranslationBundle\Propel\File'; - /** * Create a storage class form doctrine ORM. * @@ -87,22 +78,6 @@ protected function getMongoDBStorage(DocumentManager $dm): DoctrineMongoDBStorag return $storage; } - /** - * Create a storage class for Propel. - * - * @return PropelStorage - */ - protected function getPropelStorage() - { - $storage = new PropelStorage(null, [ - 'trans_unit' => self::PROPEL_TRANS_UNIT_CLASS, - 'translation' => self::PROPEL_TRANSLATION_CLASS, - 'file' => self::PROPEL_FILE_CLASS, - ]); - - return $storage; - } - /** * Create the database schema. */ @@ -136,15 +111,6 @@ protected function loadFixtures(ObjectManager $om) $executor->execute([$fixtures], false); } - /** - * Load test fixtures for Propel. - */ - protected function loadPropelFixtures(ConnectionWrapper $con) - { - $fixtures = new TransUnitDataPropel(); - $fixtures->load($con); - } - /** * @param $om * @return MockObject @@ -228,8 +194,9 @@ protected function getMockSqliteEntityManager($mockCustomHydrator = false) * Create a DocumentManager instance for tests. * * @return DocumentManager + * @throws MongoDBException */ - protected function getMockMongoDbDocumentManager() + protected function getMockMongoDbDocumentManager(): DocumentManager { $prefixes = [ __DIR__ . '/../../Resources/config/model' => 'Lexik\Bundle\TranslationBundle\Model', @@ -263,32 +230,7 @@ protected function getMockMongoDbDocumentManager() $dm = DocumentManager::create($conn, $config); - return $dm; - } - - /** - * @return ConnectionWrapper - */ - protected function getMockPropelConnection() - { - if (!class_exists('Lexik\\Bundle\\TranslationBundle\\Propel\\Base\\File')) { - // classes are built in-memory. - $builder = new QuickBuilder(); - $builder->setSchema(file_get_contents(__DIR__ . '/../../Resources/config/propel/schema.xml')); - $con = $builder->build(null, null, null, null, ['tablemap', 'object', 'query']); - } else { - // in memory-classes already exist, create connection and SQL manually - $dsn = 'sqlite::memory:'; - $pdoConnection = new PdoConnection($dsn); - $con = new ConnectionWrapper($pdoConnection); - Propel::getServiceContainer()->setConnection('default', $con); - $con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); - $builder = new QuickBuilder(); - $builder->setSchema(file_get_contents(__DIR__ . '/../../Resources/config/propel/schema.xml')); - $builder->buildSQL($con); - } - - return $con; + return $dm; } } diff --git a/Tests/Unit/Repository/Propel/FileRepositoryTest.php b/Tests/Unit/Repository/Propel/FileRepositoryTest.php deleted file mode 100644 index 3f6c0377..00000000 --- a/Tests/Unit/Repository/Propel/FileRepositoryTest.php +++ /dev/null @@ -1,59 +0,0 @@ - - */ -class FileRepositoryTest extends BaseUnitTestCase -{ - /** - * @group orm - */ - public function testFindForLocalesAndDomains() - { - $con = $this->getMockPropelConnection(); - $this->loadPropelFixtures($con); - - $repository = new FileRepository($con); - - $result = $repository->findForLocalesAndDomains(['de'], []); - $expected = ['Resources/translations/superTranslations.de.yml']; - $this->assertEquals(1, count($result)); - $this->assertFilesPath($expected, $result); - - $result = $repository->findForLocalesAndDomains(['fr'], []); - $expected = ['Resources/translations/superTranslations.fr.yml', 'Resources/translations/messages.fr.yml']; - $this->assertEquals(2, count($result)); - $this->assertFilesPath($expected, $result); - - $result = $repository->findForLocalesAndDomains([], ['messages']); - $expected = ['Resources/translations/messages.fr.yml', 'Resources/translations/messages.en.yml']; - $this->assertEquals(2, count($result)); - - $result = $repository->findForLocalesAndDomains(['en', 'de'], ['messages', 'superTranslations']); - $expected = ['Resources/translations/superTranslations.en.yml', 'Resources/translations/superTranslations.de.yml', 'Resources/translations/messages.en.yml']; - $this->assertEquals(3, count($result)); - $this->assertFilesPath($expected, $result); - } - - /** - * Check files path. - * - * @param array $expected - * @param array $result - */ - public function assertFilesPath($expected, $result) - { - $i = 0; - foreach ($result as $file) { - $this->assertEquals($expected[$i], $file->getPath().'/'.$file->getName()); - $i++; - } - } -} diff --git a/Tests/Unit/Repository/Propel/TransUnitRepositoryTest.php b/Tests/Unit/Repository/Propel/TransUnitRepositoryTest.php deleted file mode 100644 index b47223e8..00000000 --- a/Tests/Unit/Repository/Propel/TransUnitRepositoryTest.php +++ /dev/null @@ -1,317 +0,0 @@ - - */ -class TransUnitRepositoryTest extends BaseUnitTestCase -{ - /** - * @group orm - */ - public function testGetAllDomainsByLocale() - { - $con = $this->loadDatabase(); - $repository = new TransUnitRepository($con); - - $results = $repository->getAllDomainsByLocale(); - $expected = [ - ['locale' => 'de', 'domain' => 'superTranslations'], - ['locale' => 'en', 'domain' => 'messages'], - ['locale' => 'en', 'domain' => 'superTranslations'], - ['locale' => 'fr', 'domain' => 'messages'], - ['locale' => 'fr', 'domain' => 'superTranslations'], - ]; - - $this->assertSame($expected, $results); - } - - /** - * @group orm - */ - public function testGetAllDomains() - { - $con = $this->loadDatabase(); - $repository = new TransUnitRepository($con); - - $results = $repository->getAllDomains(); - $expected = ['messages', 'superTranslations']; - - $this->assertSame($expected, $results); - } - - /** - * @group orm - */ - public function testGetAllByLocaleAndDomain() - { - $con = $this->loadDatabase(); - $repository = new TransUnitRepository($con); - - $results = $repository->getAllByLocaleAndDomain('de', 'messages'); - $expected = []; - $this->assertSameTransUnit($expected, $results); - - $results = $repository->getAllByLocaleAndDomain('de', 'superTranslations'); - $expected = [ - ['id' => 1, - 'key' => 'key.say_hello', - 'domain' => 'superTranslations', - 'translations' => [['locale' => 'de', 'content' => 'heil']], - ], - ]; - $this->assertSameTransUnit($expected, $results); - - $results = $repository->getAllByLocaleAndDomain('en', 'messages'); - $expected = [ - ['id' => 2, - 'key' => 'key.say_goodbye', - 'domain' => 'messages', - 'translations' => [['locale' => 'en', 'content' => 'goodbye']], - ], - ['id' => 3, - 'key' => 'key.say_wtf', - 'domain' => 'messages', - 'translations' => [['locale' => 'en', 'content' => 'what the fuck !?!']], - ], - ]; - $this->assertSameTransUnit($expected, $results); - } - - /** - * @group orm - * @dataProvider countProvider - */ - public function testCount($expectedCount, $arguments) - { - $con = $this->loadDatabase(); - $repository = new TransUnitRepository($con); - - $count = call_user_func_array($repository->count(...), $arguments); - - $this->assertEquals($expectedCount, $count); - } - - public function countProvider() - { - return [ - [3, [['fr', 'de', 'en'], []]], - [3, [['fr', 'it'], []]], - [3, [['fr', 'de'], ['_search' => false, 'key' => 'good']]], - [1, [['fr', 'de'], ['_search' => true, 'key' => 'good']]], - [1, [['en', 'de'], ['_search' => true, 'domain' => 'super']]], - [1, [['en', 'fr', 'de'], ['_search' => true, 'key' => 'hel', 'domain' => 'uper']]], - [2, [['en', 'de'], ['_search' => true, 'key' => 'say', 'domain' => 'ssa']]], - ]; - } - - /** - * @group orm - */ - public function testGetTransUnitList() - { - $con = $this->loadDatabase(); - $repository = new TransUnitRepository($con); - - $result = $repository->getTransUnitList(['fr', 'de'], 10, 1, ['sidx' => 'key', 'sord' => 'ASC']); - $expected = [ - [ - 'id' => 2, - 'key' => 'key.say_goodbye', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'fr', 'content' => 'au revoir'], - ], - ], - [ - 'id' => 1, - 'key' => 'key.say_hello', - 'domain' => 'superTranslations', - 'translations' => [ - ['locale' => 'de', 'content' => 'heil'], - ['locale' => 'fr', 'content' => 'salut'], - ], - ], - [ - 'id' => 3, - 'key' => 'key.say_wtf', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'fr', 'content' => 'c\'est quoi ce bordel !?!'], - ], - ], - ]; - $this->assertSameTransUnit($expected, $result); - - $result = $repository->getTransUnitList(['fr', 'de'], 10, 1, ['sidx' => 'key', - 'sord' => 'DESC', - '_search' => true, - 'domain' => 'mess', - ]); - $expected = [ - [ - 'id' => 3, - 'key' => 'key.say_wtf', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'fr', 'content' => 'c\'est quoi ce bordel !?!'], - ], - ], - [ - 'id' => 2, - 'key' => 'key.say_goodbye', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'fr', 'content' => 'au revoir'], - ], - ], - ]; - $this->assertSameTransUnit($expected, $result); - - $result = $repository->getTransUnitList(['fr', 'de'], 10, 1, ['sidx' => 'key', - 'sord' => 'DESC', - '_search' => true, - 'domain' => 'mess', - 'key' => 'oo', - ]); - $expected = [ - [ - 'id' => 2, - 'key' => 'key.say_goodbye', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'fr', 'content' => 'au revoir'], - ], - ], - ]; - $this->assertSameTransUnit($expected, $result); - - $result = $repository->getTransUnitList(['fr', 'en'], 10, 1, ['sidx' => 'key', - 'sord' => 'DESC', - '_search' => true, - 'fr' => 'alu', - ]); - $expected = [ - [ - 'id' => 1, - 'key' => 'key.say_hello', - 'domain' => 'superTranslations', - 'translations' => [ - ['locale' => 'en', 'content' => 'hello'], - ['locale' => 'fr', 'content' => 'salut'], - ], - ], - ]; - $this->assertSameTransUnit($expected, $result); - - $result = $repository->getTransUnitList(['fr', 'de', 'en'], 2, 1, ['sidx' => 'domain', 'sord' => 'ASC']); - $expected = [ - [ - 'id' => 2, - 'key' => 'key.say_goodbye', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'en', 'content' => 'goodbye'], - ['locale' => 'fr', 'content' => 'au revoir'], - ], - ], - [ - 'id' => 3, - 'key' => 'key.say_wtf', - 'domain' => 'messages', - 'translations' => [ - ['locale' => 'en', 'content' => 'what the fuck !?!'], - ['locale' => 'fr', 'content' => 'c\'est quoi ce bordel !?!'], - ], - ], - ]; - $this->assertSameTransUnit($expected, $result); - - $result = $repository->getTransUnitList(['fr', 'de', 'en'], 2, 2, ['sidx' => 'domain', 'sord' => 'ASC']); - $expected = [ - [ - 'id' => 1, - 'key' => 'key.say_hello', - 'domain' => 'superTranslations', - 'translations' => [ - ['locale' => 'de', 'content' => 'heil'], - ['locale' => 'en', 'content' => 'hello'], - ['locale' => 'fr', 'content' => 'salut'], - ], - ], - ]; - $this->assertSameTransUnit($expected, $result); - } - - /** - * @group orm - */ - public function testGetTranslationsForFile() - { - $con = $this->loadDatabase(); - $repository = new TransUnitRepository($con); - - $file = FileQuery::create()->findOneByArray( [ - 'Domain' => 'messages', - 'Locale' => 'fr', - 'Extention' => 'yml', - ], $con); - $this->assertInstanceOf(self::PROPEL_FILE_CLASS, $file); - - $result = $repository->getTranslationsForFile($file, false); - $expected = [ - 'key.say_goodbye' => 'au revoir', - 'key.say_wtf' => 'c\'est quoi ce bordel !?!', - ]; - $this->assertEquals($expected, $result); - - // update a translation and then get translations with onlyUpdated = true - $now = new \DateTime('now'); - $now->modify('+2 days'); - - TranslationQuery::create() - ->filterByLocale('fr') - ->filterByContent('au revoir') - ->update(['UpdatedAt' => $now], $con, false); - - $result = $repository->getTranslationsForFile($file, true); - $expected = [ - 'key.say_goodbye' => 'au revoir', - ]; - $this->assertEquals($expected, $result); - } - - protected function assertSameTransUnit($expected, $result) - { - $this->assertEquals(is_countable($expected) ? count($expected) : 0, is_countable($result) ? count($result) : 0); - - foreach ($expected as $i => $transUnit) { - $this->assertEquals($transUnit['id'], $result[$i]['id']); - $this->assertEquals($transUnit['key'], $result[$i]['key']); - $this->assertEquals($transUnit['domain'], $result[$i]['domain']); - - $this->assertEquals(is_countable($transUnit['translations']) ? count($transUnit['translations']) : 0, is_countable($result[$i]['translations']) ? count($result[$i]['translations']) : 0); - - foreach ($transUnit['translations'] as $j => $translation) { - $this->assertEquals($translation['locale'], $result[$i]['translations'][$j]['locale']); - $this->assertEquals($translation['content'], $result[$i]['translations'][$j]['content']); - } - } - } - - protected function loadDatabase() - { - $con = $this->getMockPropelConnection(); - $this->loadPropelFixtures($con); - - return $con; - } -} diff --git a/Tests/Unit/Translation/Manager/FileManagerTest.php b/Tests/Unit/Translation/Manager/FileManagerTest.php index 264b24ba..033f7211 100644 --- a/Tests/Unit/Translation/Manager/FileManagerTest.php +++ b/Tests/Unit/Translation/Manager/FileManagerTest.php @@ -10,7 +10,6 @@ use Lexik\Bundle\TranslationBundle\Storage\DoctrineMongoDBStorage; use Lexik\Bundle\TranslationBundle\Storage\DoctrineORMStorage; use Lexik\Bundle\TranslationBundle\Tests\Unit\BaseUnitTestCase; -use Lexik\Bundle\TranslationBundle\Propel\FileQuery; /** * Unit test for FileManager. @@ -27,12 +26,6 @@ class FileManagerTest extends BaseUnitTestCase private DoctrineMongoDBStorage $odmStorage; - /** - * - * @var Lexik\Bundle\TranslationBundle\Storage\PropelStorage - */ - private $propelStorage; - private string $rootDir = '/test/root/dir/app'; public function setUp(): void @@ -48,10 +41,6 @@ public function setUp(): void $this->loadFixtures($this->dm); $this->odmStorage = $this->getMongoDBStorage($this->dm); - - $con = $this->getMockPropelConnection(); - $this->loadPropelFixtures($con); - $this->propelStorage = $this->getPropelStorage(); } /** @@ -122,30 +111,6 @@ public function testODMCreate() $this->assertEquals('Resources/translations', $file->getPath()); } - /** - * @group propel - */ - public function testPropelCreate() - { - $manager = new FileManager($this->propelStorage, $this->rootDir); - - $file = $manager->create('myDomain.en.yml', '/test/root/dir/src/Project/CoolBundle/Resources/translations'); - $this->assertTrue($file->isNew()); - $this->assertEquals('myDomain', $file->getDomain()); - $this->assertEquals('en', $file->getLocale()); - $this->assertEquals('yml', $file->getExtention()); - $this->assertEquals('myDomain.en.yml', $file->getName()); - $this->assertEquals('../src/Project/CoolBundle/Resources/translations', $file->getPath()); - - $file = $manager->create('messages.fr.xliff', '/test/root/dir/app/Resources/translations', true); - $this->assertFalse($file->isNew()); - $this->assertEquals('messages', $file->getDomain()); - $this->assertEquals('fr', $file->getLocale()); - $this->assertEquals('xliff', $file->getExtention()); - $this->assertEquals('messages.fr.xliff', $file->getName()); - $this->assertEquals('Resources/translations', $file->getPath()); - } - /** * @group orm */ @@ -197,29 +162,4 @@ public function testODMGetFor() $total = count($repository->findAll()); $this->assertEquals(6, $total); } - - /** - * @group propel - */ - public function testPropelGetFor() - { - $manager = new FileManager($this->propelStorage, $this->rootDir); - - $total = FileQuery::create()->count(); - $this->assertEquals(5, $total); - - // get an existing file - $file = $manager->getFor('superTranslations.de.yml', '/test/root/dir/app/Resources/translations'); - $file->save(); - - $total = FileQuery::create()->count(); - $this->assertEquals(5, $total); - - // get a new file - $file = $manager->getFor('superTranslations.it.yml', '/test/root/dir/app/Resources/translations'); - $file->save(); - - $total = FileQuery::create()->count(); - $this->assertEquals(6, $total); - } } diff --git a/Tests/Unit/Translation/Manager/TransUnitManagerTest.php b/Tests/Unit/Translation/Manager/TransUnitManagerTest.php index 27627a74..e0cbc0d4 100644 --- a/Tests/Unit/Translation/Manager/TransUnitManagerTest.php +++ b/Tests/Unit/Translation/Manager/TransUnitManagerTest.php @@ -11,7 +11,6 @@ use Lexik\Bundle\TranslationBundle\Manager\FileManager; use Lexik\Bundle\TranslationBundle\Storage\DoctrineMongoDBStorage; use Lexik\Bundle\TranslationBundle\Storage\DoctrineORMStorage; -use Lexik\Bundle\TranslationBundle\Storage\PropelStorage; use Lexik\Bundle\TranslationBundle\Tests\Unit\BaseUnitTestCase; /** @@ -29,8 +28,6 @@ class TransUnitManagerTest extends BaseUnitTestCase private DoctrineMongoDBStorage $odmStorage; - private PropelStorage $propelStorage; - private string $rootDir = '/test/root/dir/app'; public function setUp(): void @@ -44,9 +41,6 @@ public function setUp(): void $this->createSchema($this->dm); $this->odmStorage = $this->getMongoDBStorage($this->dm); - - $this->getMockPropelConnection(); - $this->propelStorage = $this->getPropelStorage(); } /** @@ -73,7 +67,7 @@ public function testORMCreate() */ public function testODMCreate() { - $fileManager = new FileManager($this->odmStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->odmStorage, $this->rootDir); $manager = new TransUnitManager($this->odmStorage, $fileManager, $this->rootDir); $transUnit = $manager->create('chuck.norris', 'badass'); @@ -87,31 +81,12 @@ public function testODMCreate() $this->assertEquals('rambo', $transUnit->getKey()); } - /** - * @group propel - */ - public function testPropelCreate() - { - $fileManager = new FileManager($this->propelStorage, self::PROPEL_FILE_CLASS, $this->rootDir); - $manager = new TransUnitManager($this->propelStorage, $fileManager, $this->rootDir); - - $transUnit = $manager->create('chuck.norris', 'badass'); - $this->assertTrue($transUnit->isNew()); - $this->assertEquals('badass', $transUnit->getDomain()); - $this->assertEquals('chuck.norris', $transUnit->getKey()); - - $transUnit = $manager->create('rambo', 'badass', true); - $this->assertFalse($transUnit->isNew()); - $this->assertEquals('badass', $transUnit->getDomain()); - $this->assertEquals('rambo', $transUnit->getKey()); - } - /** * @group orm */ public function testORMAddTranslation() { - $fileManager = new FileManager($this->ormStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->ormStorage, $this->rootDir); $manager = new TransUnitManager($this->ormStorage, $fileManager, $this->rootDir); $class = TransUnit::class; @@ -139,7 +114,7 @@ public function testORMAddTranslation() */ public function testODMAddTranslation() { - $fileManager = new FileManager($this->odmStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->odmStorage, $this->rootDir); $manager = new TransUnitManager($this->odmStorage, $fileManager, $this->rootDir); $transUnit = $manager->create('bwah', 'messages', true); @@ -159,37 +134,12 @@ public function testODMAddTranslation() $this->assertEquals('fr', $translation->getLocale()); } - /** - * @group propel - */ - public function testPropelAddTranslation() - { - $fileManager = new FileManager($this->propelStorage, self::PROPEL_FILE_CLASS, $this->rootDir); - $manager = new TransUnitManager($this->propelStorage, $fileManager, $this->rootDir); - - $transUnit = $manager->create('bwah', 'messages', true); - - $translation = $manager->addTranslation($transUnit, 'en', 'bwaaaAaAahhHHh', null, true); - $this->assertEquals(1, $transUnit->getTranslations()->count()); - $this->assertEquals('bwaaaAaAahhHHh', $translation->getContent()); - $this->assertEquals('en', $translation->getLocale()); - - $translation = $manager->addTranslation($transUnit, 'en', 'blebleble', null, true); - $this->assertEquals(1, $transUnit->getTranslations()->count()); - $this->assertNull($translation); - - $translation = $manager->addTranslation($transUnit, 'fr', 'bwoOoOohH', null, true); - $this->assertEquals(2, $transUnit->getTranslations()->count()); - $this->assertEquals('bwoOoOohH', $translation->getContent()); - $this->assertEquals('fr', $translation->getLocale()); - } - /** * @group orm */ public function testORMUpdateTranslation() { - $fileManager = new FileManager($this->ormStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->ormStorage, $this->rootDir); $manager = new TransUnitManager($this->ormStorage, $fileManager, $this->rootDir); $transUnit = $manager->create('bwah', 'messages', true); @@ -211,7 +161,7 @@ public function testORMUpdateTranslation() */ public function testODMUpdateTranslation() { - $fileManager = new FileManager($this->odmStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->odmStorage, $this->rootDir); $manager = new TransUnitManager($this->odmStorage, $fileManager, $this->rootDir); $transUnit = $manager->create('bwah', 'messages', true); @@ -228,34 +178,12 @@ public function testODMUpdateTranslation() $this->assertEquals(2, $transUnit->getTranslations()->count()); } - /** - * @group propel - */ - public function testPropelUpdateTranslation() - { - $fileManager = new FileManager($this->propelStorage, self::PROPEL_FILE_CLASS, $this->rootDir); - $manager = new TransUnitManager($this->propelStorage, $fileManager, $this->rootDir); - - $transUnit = $manager->create('bwah', 'messages', true); - $manager->addTranslation($transUnit, 'en', 'hello'); - $manager->addTranslation($transUnit, 'fr', 'salut'); - - $translation = $manager->updateTranslation($transUnit, 'en', 'Hiiii', true); - $this->assertEquals('Hiiii', $translation->getContent()); - $this->assertEquals('en', $translation->getLocale()); - $this->assertEquals(2, $transUnit->getTranslations()->count()); - - $translation = $manager->updateTranslation($transUnit, 'de', 'Hallo', true); - $this->assertNull($translation); - $this->assertEquals(2, $transUnit->getTranslations()->count()); - } - /** * @group orm */ public function testORMNewInstance() { - $fileManager = new FileManager($this->ormStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->ormStorage, $this->rootDir); $manager = new TransUnitManager($this->ormStorage, $fileManager, $this->rootDir); $transUnit = $manager->newInstance(); @@ -273,7 +201,7 @@ public function testORMNewInstance() */ public function testODMNewInstance() { - $fileManager = new FileManager($this->odmStorage, self::ENTITY_FILE_CLASS, $this->rootDir); + $fileManager = new FileManager($this->odmStorage, $this->rootDir); $manager = new TransUnitManager($this->odmStorage, $fileManager, $this->rootDir); $transUnit = $manager->newInstance(); @@ -285,22 +213,4 @@ public function testODMNewInstance() $this->assertEquals('fr', $transUnit->getTranslations()->get(0)->getLocale()); $this->assertEquals('en', $transUnit->getTranslations()->get(1)->getLocale()); } - - /** - * @group propel - */ - public function testPropelNewInstance() - { - $fileManager = new FileManager($this->propelStorage, self::PROPEL_FILE_CLASS, $this->rootDir); - $manager = new TransUnitManager($this->propelStorage, $fileManager, $this->rootDir); - - $transUnit = $manager->newInstance(); - $this->assertTrue($transUnit->isNew()); - $this->assertEquals(0, $transUnit->getTranslations()->count()); - - $transUnit = $manager->newInstance(['fr', 'en']); - $this->assertTrue($transUnit->isNew()); - $this->assertEquals('fr', $transUnit->getTranslations()->get(0)->getLocale()); - $this->assertEquals('en', $transUnit->getTranslations()->get(1)->getLocale()); - } } diff --git a/Tests/Unit/Translation/TranslatorTest.php b/Tests/Unit/Translation/TranslatorTest.php index 89ac8364..cb046c69 100644 --- a/Tests/Unit/Translation/TranslatorTest.php +++ b/Tests/Unit/Translation/TranslatorTest.php @@ -143,7 +143,7 @@ class TranslatorMock extends Translator { public $dbResources = []; - public function addResource($format, $resource, $locale, $domain = 'messages') + public function addResource($format, $resource, $locale, $domain = 'messages'): void { if ('database' == $format) { $this->dbResources[$locale][] = [$format, $resource, $domain]; diff --git a/Tests/app/AppKernel.php b/Tests/app/AppKernel.php index af889ba9..09083a79 100644 --- a/Tests/app/AppKernel.php +++ b/Tests/app/AppKernel.php @@ -11,8 +11,6 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Kernel; /** @@ -95,10 +93,4 @@ protected function getKernelParameters(): array return $parameters; } - - public function terminate( - Request $request, Response $response) - { - parent::terminate($request, $response); // TODO: Change the autogenerated stub - } } diff --git a/composer.json b/composer.json index 6b3fbe66..68bce6ec 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,12 @@ "name": "lexik/translation-bundle", "type": "symfony-bundle", "description": "This bundle allows to import translation files content into the database and provide a GUI to edit translations.", - "keywords": ["Symfony", "bundle", "translation", "i18n"], + "keywords": [ + "Symfony", + "bundle", + "translation", + "i18n" + ], "homepage": "https://github.com/lexik/LexikTranslationBundle", "license": "MIT", "prefer-stable": true, @@ -25,27 +30,28 @@ "symfony/asset": "7.0.*", "symfony/form": "7.0.*", "symfony/security-csrf": "7.0.*", - "symfony/translation": "7.0.*", + "symfony/translation": "7.0.*|^5.0.0", "symfony/validator": "^7.0", - "symfony/twig-bundle": "7.0.*" + "symfony/twig-bundle": "7.0.*", + "symfony/yaml": "*" }, "require-dev": { - "symfony/symfony": "~7.0", "ext-mongodb": "*", "doctrine/annotations": "^1.13", "doctrine/cache": "^1.4", "doctrine/data-fixtures": "~1.1", - "doctrine/mongodb-odm-bundle": "~4.2", - "propel/propel": "2.0.0-alpha12|dev-master", "phpunit/phpunit": "^9.5", - "doctrine/mongodb-odm": "^2.1", + "doctrine/mongodb-odm-bundle": "^2.0", + "doctrine/mongodb-odm": "^2.7.x-dev", "mongodb/mongodb": "^1.8", "ext-pdo": "*", "mikey179/vfsstream": "^1.6", "rector/rector": "^0.14.8" }, - "autoload": { - "psr-4": { "Lexik\\Bundle\\TranslationBundle\\": "" } + "autoload": { + "psr-4": { + "Lexik\\Bundle\\TranslationBundle\\": "" + } }, "autoload-dev": { "classmap": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c254dfa4..4ea539b3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,7 +19,6 @@ util orm odm - propel exporter loader importer diff --git a/rector.php b/rector.php index 3119855c..79c9cd26 100644 --- a/rector.php +++ b/rector.php @@ -17,7 +17,6 @@ __DIR__ . '/Form', __DIR__ . '/Manager', __DIR__ . '/Model', - __DIR__ . '/Propel', __DIR__ . '/Storage', __DIR__ . '/Tests', __DIR__ . '/Translation',