diff --git a/.github/workflows/verify-stability.yaml b/.github/workflows/verify-stability.yaml new file mode 100644 index 0000000..9630a3f --- /dev/null +++ b/.github/workflows/verify-stability.yaml @@ -0,0 +1,143 @@ +name: Verify stability + +on: + push: + branches: + - master + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + Validate: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.2', '8.3' ] + env: + extensions: dom, fileinfo, intl, json, pcre, simplexml + key: cache-v1 # can be any string, change to clear the extension cache. + steps: + - name: Hello + run: echo "馃帀 The job was automatically triggered by a ${{ github.event_name }} event." + - name: Checkout branch + uses: actions/checkout@v4 + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + - name: Validate Composer (composer.json and composer.lock) + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + command: validate --strict --no-check-publish + - name: Cache Composer dependencies + id: composer-cache + uses: actions/cache@v4 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + dev: no + PHPStan: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.2', '8.3' ] + env: + extensions: dom, fileinfo, intl, json, pcre, simplexml + key: cache-v1 # can be any string, change to clear the extension cache. + needs: [ Validate ] + if: needs.Validate.result == 'success' + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + - name: Analyse code with PHPStan + run: vendor/bin/phpstan analyse --memory-limit 256M + PHPUnit: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.2', '8.3' ] + env: + extensions: dom, fileinfo, intl, json, pcre, simplexml + key: cache-v1 # can be any string, change to clear the extension cache. + needs: [ PHPStan ] + if: needs.PHPStan.result == 'success' + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + - name: Install locales + run: | + sudo apt-get update \ + && sudo apt-get install -y --no-install-recommends --fix-missing \ + locales + - name: Generate locales + run: | + sudo sed -i "s/^# de_DE/de_DE/g; \ + s/^# es_ES/es_ES/g; \ + s/^# en_GB/en_GB/g; \ + s/^# en_US/en_US/g; \ + s/^# fr_FR/fr_FR/g; \ + s/^# it_IT/it_IT/g; \ + s/^# pl_PL/pl_PL/g; \ + s/^# ru_RU/ru_RU/g;" /etc/locale.gen \ + && sudo locale-gen + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + - name: Run PHPUnit tests + run: vendor/bin/phpunit --no-coverage + - name: Bye 馃憢 + run: echo "馃崗 This job's status is ${{ job.status }}." diff --git a/CHANGELOG.md b/CHANGELOG.md index 99040b6..872c8db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ Common & useful classes, resources, extensions. Based on Symfony framework. +# 0.4.0 + +1. Support Symfony `5.4` +2. Pluralization in + translations [using the ICU MessageFormat](https://symfony.com/doc/current/reference/formats/message_format.html#pluralization) +3. Update the `meritoo/common-library` package to `^1.3` +4. Fix PHPStan errors +5. Bump minimum PHP version: `8.0` -> `8.2` + 1. All the `*Type` classes, that extend `Meritoo\Common\Type\Base\BaseType` class, have been replaced by enumerations + + | Before | After | + |-----------------------------------------------------------------------|---------------------------------------------------------| + | `Meritoo\CommonBundle\Type\DependencyInjection\ConfigurationFileType` | `Meritoo\CommonBundle\Enums\Date\ConfigurationFileType` | + | `Meritoo\CommonBundle\Type\Date\DateLength` | `Meritoo\CommonBundle\Enums\Date\DateLength` | + | `Meritoo\Common\Type\OopVisibilityType` | `Meritoo\Common\Enums\OopVisibility` | + + 2. Other than that: + - The following classes have been removed as not needed anymore: + - `Meritoo\CommonBundle\Exception\Type\Date\UnknownDateLengthException` + - `Meritoo\CommonBundle\Exception\Type\DependencyInjection\UnknownConfigurationFileTypeException` + - `Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\UnknownServicesFileType\Extension` + +# 0.3.1 + +1. Create `Meritoo\CommonBundle\Traits\Test\Entity\EntityTestCaseTrait::dropDatabase()` method for removing whole + database in PHPUnit tests + # 0.3.0 1. Support PHP 8.0+ diff --git a/VERSION b/VERSION index 0d91a54..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.4.0 diff --git a/composer.json b/composer.json index a28e9cf..ab67ce8 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,14 @@ } ], "require": { - "php": "^8.0", + "php": "^8.2", "ext-intl": "*", - "doctrine/annotations": "^1.13", - "meritoo/common-library": "^1.2", - "symfony/form": "^4.4|^5.2", - "symfony/framework-bundle": "^4.0|^5.4", - "symfony/twig-bundle": "^4.0|^5.4", - "symfony/validator": "^4.0|^5.4" + "doctrine/annotations": "^2.0", + "meritoo/common-library": "^1.3", + "symfony/form": "^5.4", + "symfony/framework-bundle": "^5.4", + "symfony/twig-bundle": "^5.4", + "symfony/validator": "^5.4" }, "require-dev": { "friends-of-phpspec/phpspec-code-coverage": "^6.1", @@ -31,6 +31,7 @@ "sebastian/phpcpd": "^6.0", "squizlabs/php_codesniffer": "^3.6", "symfony/phpunit-bridge": "^6.0", + "symfony/translation": "^6.0", "symfony/yaml": "^5.4", "vimeo/psalm": "^4.22" }, diff --git a/docker-compose.yml b/docker-compose.yml index 4f76814..88f98e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,9 @@ -version: '3' - services: # # Required to run project # php: - image: meritoo/php:8.0 + image: meritoo/php:8.2 container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-php entrypoint: php command: -S 0.0.0.0:9999 @@ -14,7 +12,7 @@ services: volumes: - .:/var/www/application:cached composer: - image: meritoo/php:8.0 + image: meritoo/php:8.2 container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-composer entrypoint: php -d memory_limit=-1 /usr/local/bin/composer volumes: @@ -23,7 +21,7 @@ services: # Required to run PHPUnit's tests # phpunit: - image: meritoo/php:8.0 + image: meritoo/php:8.2 container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-phpunit entrypoint: ./vendor/bin/simple-phpunit command: --version diff --git a/phpstan.neon.dist b/phpstan.neon similarity index 84% rename from phpstan.neon.dist rename to phpstan.neon index 09ad357..82aa8e8 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon @@ -3,5 +3,5 @@ parameters: paths: - src - tests - excludes_analyse: + excludePaths: - %rootDir%/../../../tests/Resources/var/* diff --git a/src/Bundle/Descriptor.php b/src/Bundle/Descriptor.php index e51884f..d038ef6 100644 --- a/src/Bundle/Descriptor.php +++ b/src/Bundle/Descriptor.php @@ -89,12 +89,12 @@ class Descriptor /** * Class constructor * - * @param string $name (optional) Name of bundle - * @param string $configurationRootName (optional) Name of configuration root node of bundle - * @param string $rootNamespace (optional) Root namespace of bundle - * @param string $path (optional) Physical path of bundle + * @param string $name (optional) Name of bundle + * @param string $configurationRootName (optional) Name of configuration root node of bundle + * @param string $rootNamespace (optional) Root namespace of bundle + * @param string $path (optional) Physical path of bundle * @param null|Descriptor $parentBundleDescriptor (optional) Descriptor of the parent bundle - * @param null|Descriptor $childBundleDescriptor (optional) Descriptor of the child bundle + * @param null|Descriptor $childBundleDescriptor (optional) Descriptor of the child bundle */ public function __construct( string $name = '', @@ -102,7 +102,7 @@ public function __construct( string $rootNamespace = '', string $path = '', ?Descriptor $parentBundleDescriptor = null, - ?Descriptor $childBundleDescriptor = null + ?Descriptor $childBundleDescriptor = null, ) { $this->name = $name; $this->configurationRootName = $configurationRootName; @@ -119,6 +119,7 @@ public function __construct( * Adds names of files with data fixtures from bundle * * @param array $fixturesPaths Names of files with data fixtures + * * @return Descriptor */ public function addDataFixtures(array $fixturesPaths): Descriptor @@ -136,6 +137,7 @@ public function addDataFixtures(array $fixturesPaths): Descriptor * Creates and returns descriptor from given data * * @param array $data Data of descriptor + * * @return Descriptor */ public static function fromArray(array $data): Descriptor @@ -175,13 +177,13 @@ public static function fromArray(array $data): Descriptor $childBundleDescriptor = static::fromArray($childData); } - return new static( + return new self( $name, $configurationRootName, $rootNamespace, $path, $parentBundleDescriptor, - $childBundleDescriptor + $childBundleDescriptor, ); } @@ -189,6 +191,7 @@ public static function fromArray(array $data): Descriptor * Creates and returns descriptor of given bundle * * @param Bundle $bundle The bundle + * * @return Descriptor */ public static function fromBundle(Bundle $bundle): Descriptor @@ -201,7 +204,7 @@ public static function fromBundle(Bundle $bundle): Descriptor // Default values, not provided by bundle directly $configurationRootName = ''; - return new static($name, $configurationRootName, $rootNamespace, $path); + return new self($name, $configurationRootName, $rootNamespace, $path); } /** @@ -218,6 +221,7 @@ public function getChildBundleDescriptor(): ?Descriptor * Sets descriptor of the child bundle * * @param Descriptor|null $childBundleDescriptor (optional) The child's descriptor + * * @return Descriptor */ public function setChildBundleDescriptor(?Descriptor $childBundleDescriptor): Descriptor @@ -241,6 +245,7 @@ public function getConfigurationRootName(): string * Sets name of configuration root node of bundle * * @param string $configurationRootName The name + * * @return Descriptor */ public function setConfigurationRootName(string $configurationRootName): Descriptor @@ -273,10 +278,7 @@ public function getDataFixturesDirectoryPath(): ?string return null; } - return Miscellaneous::concatenatePaths([ - $path, - static::PATH_DATA_FIXTURES, - ]); + return Miscellaneous::concatenatePaths($path, static::PATH_DATA_FIXTURES); } /** @@ -293,6 +295,7 @@ public function getName(): string * Sets name of bundle * * @param string $name The name + * * @return Descriptor */ public function setName(string $name): Descriptor @@ -316,6 +319,7 @@ public function getParentBundleDescriptor(): ?Descriptor * Sets descriptor of the parent bundle * * @param Descriptor|null $parentBundleDescriptor (optional) The parent's descriptor + * * @return Descriptor */ public function setParentBundleDescriptor(?Descriptor $parentBundleDescriptor): Descriptor @@ -339,6 +343,7 @@ public function getPath(): string * Sets physical path of bundle * * @param string $path The path + * * @return Descriptor */ public function setPath(string $path): Descriptor @@ -362,6 +367,7 @@ public function getRootNamespace(): string * Sets root namespace of bundle * * @param string $rootNamespace The root namespace + * * @return Descriptor */ public function setRootNamespace(string $rootNamespace): Descriptor @@ -392,6 +398,7 @@ public function getShortName(): string * Returns information if given file belongs to bundle * * @param string $filePath Path of file to verify + * * @return bool */ public function hasFile(string $filePath): bool @@ -404,6 +411,7 @@ public function hasFile(string $filePath): bool * * @param bool $withParentAndChild (optional) If is set to true, includes descriptor of the parent and child * bundle (default behaviour). Otherwise - not. + * * @return array */ public function toArray(bool $withParentAndChild = true): array diff --git a/src/Bundle/Descriptors.php b/src/Bundle/Descriptors.php index d6e0b7b..0ddb566 100644 --- a/src/Bundle/Descriptors.php +++ b/src/Bundle/Descriptors.php @@ -25,11 +25,12 @@ class Descriptors extends BaseCollection * Returns the descriptors created from given data * * @param array $data Data of descriptors + * * @return Descriptors */ public static function fromArray(array $data): Descriptors { - $result = new static(); + $result = new self(); if (!empty($data)) { $descriptors = []; @@ -48,6 +49,7 @@ public static function fromArray(array $data): Descriptors * Returns descriptor of bundle that contains given class * * @param string $classNamespace Namespace of class for which descriptor of bundle should be returned + * * @return null|Descriptor */ public function getDescriptor(string $classNamespace): ?Descriptor @@ -81,6 +83,7 @@ public function getDescriptor(string $classNamespace): ?Descriptor * Returns descriptor of bundle with given name * * @param string $bundleName Name of bundle who descriptor should be returned + * * @return null|Descriptor */ public function getDescriptorByName(string $bundleName): ?Descriptor diff --git a/src/DependencyInjection/Base/BaseExtension.php b/src/DependencyInjection/Base/BaseExtension.php index 237ba98..1be99e1 100644 --- a/src/DependencyInjection/Base/BaseExtension.php +++ b/src/DependencyInjection/Base/BaseExtension.php @@ -13,7 +13,7 @@ use Meritoo\Common\Utilities\Arrays; use Meritoo\Common\Utilities\Miscellaneous; use Meritoo\CommonBundle\DependencyInjection\ConfigurationFile\FileLoaderFactory; -use Meritoo\CommonBundle\Type\DependencyInjection\ConfigurationFileType; +use Meritoo\CommonBundle\Enums\Date\ConfigurationFileType; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -31,7 +31,7 @@ abstract class BaseExtension extends ConfigurableExtension /** * Default extension of configuration files * - * @var string + * @var ConfigurationFileType */ protected const CONFIGURATION_DEFAULT_EXTENSION = ConfigurationFileType::YAML; @@ -123,7 +123,7 @@ protected function getKeysToStopLoadingParametersOn(): array */ protected function getServicesFileName(): string { - return sprintf('%s.%s', static::CONFIGURATION_SERVICES_NAME, static::CONFIGURATION_DEFAULT_EXTENSION); + return sprintf('%s.%s', static::CONFIGURATION_SERVICES_NAME, static::CONFIGURATION_DEFAULT_EXTENSION->value); } /** @@ -142,6 +142,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container * If the file name does not contain extension, default extension will be used (the ".yaml" extension). * * @param string $fileName Name of configuration file (with or without extension) + * * @return string */ private function getConfigurationFileWithExtension(string $fileName): string @@ -150,7 +151,7 @@ private function getConfigurationFileWithExtension(string $fileName): string // Use the default extension, if extension of configuration file is unknown if (empty($fileExtension)) { - return Miscellaneous::includeFileExtension($fileName, static::CONFIGURATION_DEFAULT_EXTENSION); + return Miscellaneous::includeFileExtension($fileName, static::CONFIGURATION_DEFAULT_EXTENSION->value); } return $fileName; @@ -160,12 +161,16 @@ private function getConfigurationFileWithExtension(string $fileName): string * Returns loader of configuration file * * @param ContainerBuilder $container Container for the Dependency Injection (DI) - * @param FileLocator $locator Locator used to find files - * @param string $fileType Type of configuration file + * @param FileLocator $locator Locator used to find files + * @param ConfigurationFileType $fileType Type of configuration file + * * @return null|FileLoader */ - private function getFileLoader(ContainerBuilder $container, FileLocator $locator, string $fileType): ?FileLoader - { + private function getFileLoader( + ContainerBuilder $container, + FileLocator $locator, + ConfigurationFileType $fileType, + ): ?FileLoader { $loaderFactory = new FileLoaderFactory($container, $locator); if (ConfigurationFileType::YAML === $fileType) { @@ -220,8 +225,9 @@ private function getGlobalKeysToStopLoadingParametersOn(): array * Loads the configuration file * * @param ContainerBuilder $container Container for the Dependency Injection (DI) - * @param string $fileName Name of configuration file. If provided without extension, the default - * extension of configuration files will be used. + * @param string $fileName Name of configuration file. If provided without extension, the default extension of + * configuration files will be used. + * * @return void */ private function loadConfigurationFile(ContainerBuilder $container, string $fileName): void @@ -233,15 +239,8 @@ private function loadConfigurationFile(ContainerBuilder $container, string $file return; } - $resourcesPath = Miscellaneous::concatenatePaths([ - $bundlePath, - static::CONFIGURATION_PATH, - ]); - - $filePath = Miscellaneous::concatenatePaths([ - $resourcesPath, - $fileName, - ]); + $resourcesPath = Miscellaneous::concatenatePaths($bundlePath, static::CONFIGURATION_PATH); + $filePath = Miscellaneous::concatenatePaths($resourcesPath, $fileName); // Configuration file doesn't exist or is not readable? Nothing to do if (!is_readable($filePath)) { @@ -262,8 +261,9 @@ private function loadConfigurationFile(ContainerBuilder $container, string $file /** * Loads parameters into container * - * @param array $mergedConfig Custom configuration merged with defaults - * @param ContainerBuilder $container Container for the Dependency Injection (DI) + * @param array $mergedConfig Custom configuration merged with defaults + * @param ContainerBuilder $container Container for the Dependency Injection (DI) + * * @return BaseExtension */ private function loadParameters(array $mergedConfig, ContainerBuilder $container): BaseExtension @@ -306,6 +306,7 @@ private function loadParameters(array $mergedConfig, ContainerBuilder $container * Loads services from configuration file (located in bundle's resources) * * @param ContainerBuilder $container Container for the Dependency Injection (DI) + * * @return void */ private function loadServices(ContainerBuilder $container): void @@ -321,6 +322,7 @@ private function loadServices(ContainerBuilder $container): void * Returns an array with key-value pairs, where key - name of parameter, value - value of parameter. * * @param array $mergedConfig Custom configuration merged with defaults + * * @return null|array */ private function makeFlatConfig(array $mergedConfig): ?array @@ -332,7 +334,7 @@ private function makeFlatConfig(array $mergedConfig): ?array // Merging standard with global keys and paths $stopIfMatchedBy = array_merge( Arrays::makeArray($keysToStop), - Arrays::makeArray($globalKeysToStop) + Arrays::makeArray($globalKeysToStop), ); // Let's get the last elements' paths and load values into container diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index e685bac..cb4c9d5 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -10,8 +10,8 @@ namespace Meritoo\CommonBundle\DependencyInjection; +use Meritoo\CommonBundle\Enums\Date\DateLength; use Meritoo\CommonBundle\Service\ApplicationService; -use Meritoo\CommonBundle\Type\Date\DateLength; use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -120,15 +120,15 @@ private function getDateNode(): NodeDefinition ->arrayNode('format') ->addDefaultsIfNotSet() ->children() - ->scalarNode(DateLength::DATE) + ->scalarNode(DateLength::Date->value) ->info('Format of date without time') ->defaultValue('d.m.Y') ->end() - ->scalarNode(DateLength::DATETIME) + ->scalarNode(DateLength::DateTime->value) ->info('Format of date with time') ->defaultValue('d.m.Y H:i') ->end() - ->scalarNode(DateLength::TIME) + ->scalarNode(DateLength::Time->value) ->info('Format of time without date') ->defaultValue('H:i') ->end() diff --git a/src/DependencyInjection/MeritooCommonExtension.php b/src/DependencyInjection/MeritooCommonExtension.php index fa513ae..ca9b330 100644 --- a/src/DependencyInjection/MeritooCommonExtension.php +++ b/src/DependencyInjection/MeritooCommonExtension.php @@ -26,9 +26,6 @@ class MeritooCommonExtension extends BaseExtension */ protected function getBundleDirectoryPath(): string { - return Miscellaneous::concatenatePaths([ - __DIR__, - '..', - ]); + return Miscellaneous::concatenatePaths(__DIR__, '..'); } } diff --git a/src/Enums/Date/ConfigurationFileType.php b/src/Enums/Date/ConfigurationFileType.php new file mode 100644 index 0000000..0e8a4e3 --- /dev/null +++ b/src/Enums/Date/ConfigurationFileType.php @@ -0,0 +1,34 @@ + - * @copyright Meritoo - */ -class UnknownDateLengthException extends UnknownTypeException -{ - /** - * Creates exception - * - * @param string $unknownType Unknown type of date length for date format - * @return UnknownDateLengthException - */ - public static function createException(string $unknownType): UnknownDateLengthException - { - /** @var UnknownDateLengthException $exception */ - $exception = static::create($unknownType, new DateLength(), 'date length for date format'); - - return $exception; - } -} diff --git a/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php b/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php deleted file mode 100644 index 1499b20..0000000 --- a/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @copyright Meritoo - */ -class UnknownConfigurationFileTypeException extends UnknownTypeException -{ - /** - * Creates exception - * - * @param string $unknownType Unknown type of Dependency Injection (DI) configuration file - * @return UnknownConfigurationFileTypeException - */ - public static function createException(string $unknownType): UnknownConfigurationFileTypeException - { - /** @var UnknownConfigurationFileTypeException $exception */ - $exception = static::create($unknownType, new ConfigurationFileType(), 'Dependency Injection (DI) configuration file'); - - return $exception; - } -} diff --git a/src/Resources/translations/words+intl-icu.de.yaml b/src/Resources/translations/words+intl-icu.de.yaml new file mode 100644 index 0000000..d52fa06 --- /dev/null +++ b/src/Resources/translations/words+intl-icu.de.yaml @@ -0,0 +1,79 @@ +meritoo_common: + general: + action: >- + {count, plural, + one {Aktion} + other {Aktionen} + } + error: >- + {count, plural, + one {Fehler} + other {Fehler} + } + advantage: >- + {count, plural, + one {Vorteil} + other {Vorteile} + } + disadvantage: >- + {count, plural, + one {Nachteil} + other {Nachteile} + } + invitation: >- + {count, plural, + one {Einladung} + other {Einladungen} + } + ingredient: >- + {count, plural, + one {Zutat} + other {Zutaten} + } + picture: >- + {count, plural, + one {Bild} + other {Bilder} + } + photo: >- + {count, plural, + one {Foto} + other {Fotos} + } + certificate: >- + {count, plural, + one {Zertifikat} + other {Zertifikate} + } + message: >- + {count, plural, + one {Nachricht} + other {Nachrichten} + } + day: >- + {count, plural, + one {Tag} + other {Tage} + } + month: >- + {count, plural, + one {Monat} + other {Monate} + } + year: >- + {count, plural, + one {Jahr} + other {Jahre} + } + finances: + transaction: >- + {count, plural, + one {Transaktion} + other {Transaktionen} + } + pagination: + page: >- + {count, plural, + one {Seite} + other {Seiten} + } diff --git a/src/Resources/translations/words+intl-icu.en.yaml b/src/Resources/translations/words+intl-icu.en.yaml new file mode 100644 index 0000000..4d92dae --- /dev/null +++ b/src/Resources/translations/words+intl-icu.en.yaml @@ -0,0 +1,79 @@ +meritoo_common: + general: + action: >- + {count, plural, + one {Action} + other {Actions} + } + error: >- + {count, plural, + one {Error} + other {Errors} + } + advantage: >- + {count, plural, + one {Advantage} + other {Advantages} + } + disadvantage: >- + {count, plural, + one {Disadvantage} + other {Disadvantages} + } + invitation: >- + {count, plural, + one {Invitation} + other {Invitations} + } + ingredient: >- + {count, plural, + one {Ingredient} + other {Ingredients} + } + picture: >- + {count, plural, + one {Picture} + other {Pictures} + } + photo: >- + {count, plural, + one {Photo} + other {Photos} + } + certificate: >- + {count, plural, + one {Certificate} + other {Certificates} + } + message: >- + {count, plural, + one {Message} + other {Messages} + } + day: >- + {count, plural, + one {Day} + other {Days} + } + month: >- + {count, plural, + one {Month} + other {Months} + } + year: >- + {count, plural, + one {Year} + other {Years} + } + finances: + transaction: >- + {count, plural, + one {Transaction} + other {Transactions} + } + pagination: + page: >- + {count, plural, + one {Page} + other {Pages} + } diff --git a/src/Resources/translations/words+intl-icu.pl.yaml b/src/Resources/translations/words+intl-icu.pl.yaml new file mode 100644 index 0000000..e06d606 --- /dev/null +++ b/src/Resources/translations/words+intl-icu.pl.yaml @@ -0,0 +1,109 @@ +meritoo_common: + general: + action: >- + {count, plural, + one {Akcja} + few {Akcje} + many {Akcji} + other {Akcji} + } + error: >- + {count, plural, + one {B艂膮d} + few {B艂臋dy} + many {B艂臋d贸w} + other {B艂臋d贸w} + } + advantage: >- + {count, plural, + one {Zaleta} + few {Zalety} + many {Zalet} + other {Zalety} + } + disadvantage: >- + {count, plural, + one {Wada} + few {Wady} + many {Wad} + other {Wady} + } + invitation: >- + {count, plural, + one {Zaproszenie} + few {Zaproszenia} + many {Zaprosze艅} + other {Zaprosze艅} + } + ingredient: >- + {count, plural, + one {Sk艂adnik} + few {Sk艂adniki} + many {Sk艂adnik贸w} + other {Sk艂adnik贸w} + } + picture: >- + {count, plural, + one {Obrazek} + few {Obrazki} + many {Obrazk贸w} + other {Obrazk贸w} + } + photo: >- + {count, plural, + one {Zdj臋cie} + few {Zdj臋cia} + many {Zdj臋膰} + other {Zdj臋膰} + } + certificate: >- + {count, plural, + one {Certyfikat} + few {Certyfikaty} + many {Certyfikat贸w} + other {Certyfikat贸w} + } + message: >- + {count, plural, + one {Wiadomo艣膰} + few {Wiadomo艣ci} + many {Wiadomo艣ci} + other {Wiadomo艣ci} + } + day: >- + {count, plural, + one {Dzie艅} + few {Dni} + many {Dni} + other {Dni} + } + month: >- + {count, plural, + one {Miesi膮c} + few {Miesi膮ce} + many {Miesi臋cy} + other {Miesi臋cy} + } + year: >- + {count, plural, + one {Rok} + few {Lata} + many {Lat} + other {Lat} + } + finances: + transaction: >- + {count, plural, + one {Transakcja} + few {Transakcje} + many {Transakcji} + other {Transakcji} + } + pagination: + page: >- + {count, plural, + one {Strona} + few {Strony} + many {Stron} + other {Stron} + } diff --git a/src/Resources/translations/words.de.yaml b/src/Resources/translations/words.de.yaml index 9791027..9be795c 100644 --- a/src/Resources/translations/words.de.yaml +++ b/src/Resources/translations/words.de.yaml @@ -17,8 +17,6 @@ meritoo_common: recommendation: Empfehlung resale_shop: Weiterverkauf directory: Verzeichnis - action: Aktion|Aktionen - error: Fehler|Fehler type: Art kind: Art locality: Lokalit盲t @@ -30,32 +28,21 @@ meritoo_common: here: Hier now: Jetzt right_now: Jetzt sofort - advantage: Vorteil|Vorteile - disadvantage: Nachteil|Nachteile new: Neu price: Preis price_amount: Betrag weight: Gewicht category: Kategorie - invitation: Einladung|Einladungen please: Bitte all: male: Jeder female: Alles neutral: Alles - ingredient: Zutat|Zutaten - picture: Bild|Bilder - photo: Foto|Fotos - certificate: Zertifikat|Zertifikate preview: Vorschau help: Hilfe account: Konto my_account: Mein Konto - message: Nachricht|Nachrichten history: Geschichte - day: Tag|Tage - month: Monat|Monate - year: Jahr|Jahre gallery: Galerie gallery_of_photos: Fotogalerie date: Datum @@ -151,7 +138,5 @@ meritoo_common: account_balance: Kontostand transaction_history: Verlauf der Transaktionen transaction_date: Transaktionsdatum - transaction: Transaktion|Transaktionen pagination: - page: Seite|Seiten page_of_pages: Seite %page% von %pages% diff --git a/src/Resources/translations/words.en.yaml b/src/Resources/translations/words.en.yaml index cecd872..e1e4e25 100644 --- a/src/Resources/translations/words.en.yaml +++ b/src/Resources/translations/words.en.yaml @@ -17,8 +17,6 @@ meritoo_common: recommendation: Recommendation resale_shop: Resale shop directory: Directory - action: Action|Actions - error: Error|Errors type: Type kind: Kind locality: Locality @@ -30,32 +28,21 @@ meritoo_common: here: Here now: Now right_now: Right now - advantage: Advantage|Advantages - disadvantage: Disadvantage|Disadvantages new: New price: Price price_amount: Amount weight: Weight category: Category - invitation: Invitation|Invitations please: Please all: male: Everyone female: All neutral: Everything - ingredient: Ingredient|Ingredients - picture: Picture|Pictures - photo: Photo|Photos - certificate: Certificate|Certificates preview: Preview help: Help account: Account my_account: My account - message: Message|Messages history: History - day: Day|Days - month: Month|Months - year: Year|Years gallery: Gallery gallery_of_photos: Photo gallery date: Date @@ -151,7 +138,5 @@ meritoo_common: account_balance: Account balance transaction_history: Transaction history transaction_date: Transaction date - transaction: Transaction|Transactions pagination: - page: Page|Pages page_of_pages: Page %page% of %pages% diff --git a/src/Resources/translations/words.pl.yaml b/src/Resources/translations/words.pl.yaml index 7cc7ec4..a57fd63 100644 --- a/src/Resources/translations/words.pl.yaml +++ b/src/Resources/translations/words.pl.yaml @@ -17,8 +17,6 @@ meritoo_common: recommendation: Rekomendacja resale_shop: Komis directory: Katalog - action: Akcja|Akcje - error: B艂膮d|B艂臋dy type: Typ kind: Rodzaj locality: Miejscowo艣膰 @@ -30,32 +28,21 @@ meritoo_common: here: Tutaj now: Teraz right_now: Teraz - advantage: Zaleta|Zalety - disadvantage: Wada|Wady new: Nowy price: Cena price_amount: Kwota weight: Waga category: Kategoria - invitation: '{0}Zaprosze艅|{1}Zaproszenie|[2,4]Zaproszenia|[5,20]Zaprosze艅' please: Prosz臋 all: male: Wszyscy female: Wszystkie neutral: Wszystko - ingredient: Sk艂adnik|Sk艂adniki - picture: Obrazek|Obrazki - photo: Zdj臋cie|Zdj臋cia - certificate: Certyfikat|Certyfikaty preview: Podgl膮d help: Pomoc account: Konto my_account: Moje konto - message: Wiadomo艣膰|Wiadomo艣ci history: Historia - day: Dzie艅|Dni - month: Miesi膮c|Miesi膮ce - year: Rok|Lata gallery: Galeria gallery_of_photos: Galeria zdj臋ciowa date: Data @@ -151,7 +138,5 @@ meritoo_common: account_balance: Saldo konta transaction_history: Historia transakcji transaction_date: Data transakcji - transaction: Transakcja|Transakcje pagination: - page: Strona|Strony page_of_pages: Strona %page% z %pages% diff --git a/src/Service/DateService.php b/src/Service/DateService.php index d0ae8be..6218316 100644 --- a/src/Service/DateService.php +++ b/src/Service/DateService.php @@ -13,9 +13,8 @@ use DateTimeInterface; use Exception; use IntlDateFormatter; -use Meritoo\CommonBundle\Exception\Type\Date\UnknownDateLengthException; +use Meritoo\CommonBundle\Enums\Date\DateLength; use Meritoo\CommonBundle\Service\Base\BaseService; -use Meritoo\CommonBundle\Type\Date\DateLength; /** * Serves dates @@ -49,9 +48,9 @@ class DateService extends BaseService /** * Class constructor * - * @param string $dateFormat Format of date without time + * @param string $dateFormat Format of date without time * @param string $dateTimeFormat Format of date with time - * @param string $timeFormat Format of time without date + * @param string $timeFormat Format of time without date */ public function __construct(string $dateFormat, string $dateTimeFormat, string $timeFormat) { @@ -63,11 +62,12 @@ public function __construct(string $dateFormat, string $dateTimeFormat, string $ /** * Returns date formatted according to given length of date * - * @param DateTimeInterface $dateTime The date to format - * @param string $dateLength Type of date length. One of the DateLength's class constants. + * @param DateTimeInterface $dateTime The date to format + * @param DateLength $dateLength Type of date length + * * @return string */ - public function formatDate(DateTimeInterface $dateTime, string $dateLength): string + public function formatDate(DateTimeInterface $dateTime, DateLength $dateLength): string { $format = $this->getFormat($dateLength); @@ -78,12 +78,13 @@ public function formatDate(DateTimeInterface $dateTime, string $dateLength): str * Returns given date formatted with format based on locale. * Uses the \IntlDateFormatter class to set proper type / length of date and time part in the returned string. * - * @param int $dateType Type/length of date part in the returned string. One of constants of the - * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. - * @param int $timeType Type/length of time part in the returned string. One of constants of the - * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. - * @param string $locale Locale used to format given date - * @param DateTimeInterface $dateTime The date to format + * @param int $dateType Type/length of date part in the returned string. One of constants of the + * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. + * @param int $timeType Type/length of time part in the returned string. One of constants of the + * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. + * @param string $locale Locale used to format given date + * @param DateTimeInterface $dateTime The date to format + * * @return string * @throws Exception */ @@ -91,7 +92,7 @@ public function formatDateUsingLocale( int $dateType, int $timeType, string $locale, - DateTimeInterface $dateTime + DateTimeInterface $dateTime, ): string { $timestamp = $dateTime->getTimestamp(); @@ -101,29 +102,24 @@ public function formatDateUsingLocale( /** * Returns format of date according to given length of date * - * @param string $dateLength Type of date length. One of the DateLength's class constants. - * @throws UnknownDateLengthException + * @param DateLength $dateLength Type of date length + * * @return string */ - public function getFormat(string $dateLength): string + public function getFormat(DateLength $dateLength): string { - // Oops, unknown length of date - if (false === DateLength::isCorrectType($dateLength)) { - throw UnknownDateLengthException::createException($dateLength); - } - $format = ''; switch ($dateLength) { - case DateLength::DATE: + case DateLength::Date: $format = $this->dateFormat; break; - case DateLength::DATETIME: + case DateLength::DateTime: $format = $this->dateTimeFormat; break; - case DateLength::TIME: + case DateLength::Time: $format = $this->timeFormat; break; diff --git a/src/Traits/Test/Entity/EntityTestCaseTrait.php b/src/Traits/Test/Entity/EntityTestCaseTrait.php index 61774ab..b1c9fd0 100644 --- a/src/Traits/Test/Entity/EntityTestCaseTrait.php +++ b/src/Traits/Test/Entity/EntityTestCaseTrait.php @@ -38,6 +38,14 @@ public function dropDatabaseSchema(): void ; } + public function dropDatabase(): void + { + $this + ->getSchemaTool() + ->dropDatabase() + ; + } + /** * Returns the entity manager * @@ -56,6 +64,7 @@ public function getEntityManager(): EntityManagerInterface * Returns repository for given entity * * @param string $entityClass Fully qualified class name of entity + * * @return ObjectRepository */ public function getRepository(string $entityClass): ObjectRepository diff --git a/src/Twig/HtmlExtension.php b/src/Twig/HtmlExtension.php new file mode 100644 index 0000000..5620310 --- /dev/null +++ b/src/Twig/HtmlExtension.php @@ -0,0 +1,37 @@ + + * @copyright Meritoo + */ +class HtmlExtension extends AbstractExtension +{ + public function getFilters(): array + { + $filters = [ + 1 => [ + [HtmlRuntime::class, 'attributes2string',], + ['is_safe' => ['html']], + ], + ]; + + return array_merge(parent::getFilters(), [ + new TwigFilter('meritoo_common_html_attributes_2_string', $filters[1][0], $filters[1][1]), + ]); + } +} diff --git a/src/Twig/HtmlRuntime.php b/src/Twig/HtmlRuntime.php new file mode 100644 index 0000000..443994e --- /dev/null +++ b/src/Twig/HtmlRuntime.php @@ -0,0 +1,29 @@ + + * @copyright Meritoo + */ +class HtmlRuntime implements RuntimeExtensionInterface +{ + public function attributes2string(array $attributes): ?string + { + return Arrays::valuesKeys2string($attributes, ' ', '=', '"'); + } +} diff --git a/src/Type/Date/DateLength.php b/src/Type/Date/DateLength.php deleted file mode 100644 index ca1a764..0000000 --- a/src/Type/Date/DateLength.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @copyright Meritoo - */ -class DateLength extends BaseType -{ - /** - * The "date" length. - * Date without time. - * - * @var string - */ - public const DATE = 'date'; - - /** - * The "datetime" length. - * Date with time. - * - * @var string - */ - public const DATETIME = 'datetime'; - - /** - * The "time" length. - * Time only, without date. - * - * @var string - */ - public const TIME = 'time'; -} diff --git a/src/Type/DependencyInjection/ConfigurationFileType.php b/src/Type/DependencyInjection/ConfigurationFileType.php deleted file mode 100644 index 9d50d40..0000000 --- a/src/Type/DependencyInjection/ConfigurationFileType.php +++ /dev/null @@ -1,64 +0,0 @@ - - * @copyright Meritoo - */ -class ConfigurationFileType extends BaseType -{ - /** - * The PHP configuration file - * - * @var string - */ - public const PHP = 'php'; - - /** - * The XML configuration file - * - * @var string - */ - public const XML = 'xml'; - - /** - * The YAML configuration file - * - * @var string - */ - public const YAML = 'yaml'; - - /** - * Returns type of configuration file based on name of the file - * - * @param string $fileName Name of configuration file - * @return string - * @throws UnknownConfigurationFileTypeException - */ - public static function getTypeFromFileName(string $fileName): string - { - $fileExtension = strtolower(Miscellaneous::getFileExtension($fileName)); - - // Oops, incorrect type/extension of configuration file - if (false === static::isCorrectType($fileExtension)) { - throw UnknownConfigurationFileTypeException::createException($fileExtension); - } - - return $fileExtension; - } -} diff --git a/tests/Application/DescriptorTest.php b/tests/Application/DescriptorTest.php index 6caecf5..4967336 100644 --- a/tests/Application/DescriptorTest.php +++ b/tests/Application/DescriptorTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Application; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Version; use Meritoo\CommonBundle\Application\Descriptor; @@ -127,7 +127,7 @@ public function provideDescriptorAsString(): Generator new Descriptor( 'Ultricies', 'Nullam quis risus eget urna mollis ornare vel eu leo', - new Version(10, 99, 73) + new Version(10, 99, 73), ), 'Ultricies | Nullam quis risus eget urna mollis ornare vel eu leo | 10.99.73', ]; @@ -136,7 +136,7 @@ public function provideDescriptorAsString(): Generator new Descriptor( '', 'Nullam quis risus eget urna mollis ornare vel eu leo', - new Version(10, 99, 73) + new Version(10, 99, 73), ), '- | Nullam quis risus eget urna mollis ornare vel eu leo | 10.99.73', ]; @@ -145,7 +145,7 @@ public function provideDescriptorAsString(): Generator new Descriptor( '', 'Nullam quis risus eget urna mollis ornare vel eu leo', - new Version(10, 99, 73) + new Version(10, 99, 73), ), '- | Nullam quis risus eget urna mollis ornare vel eu leo | 10.99.73', ]; @@ -175,14 +175,14 @@ public function provideEmptyValuesForConstructor(): Generator public function testConstructor(): void { - static::assertConstructorVisibilityAndArguments(Descriptor::class, OopVisibilityType::IS_PUBLIC, 3, 3); + static::assertConstructorVisibilityAndArguments(Descriptor::class, OopVisibility::Public, 3, 3); } /** - * @param string $name Name of application - * @param string $description Description of application - * @param null|Version $version Version of application - * @param Descriptor $expected Expected descriptor of application + * @param string $name Name of application + * @param string $description Description of application + * @param null|Version $version Version of application + * @param Descriptor $expected Expected descriptor of application * * @dataProvider provideEmptyValuesForConstructor */ @@ -190,7 +190,7 @@ public function testConstructorUsingEmptyValues( string $name, string $description, ?Version $version, - Descriptor $expected + Descriptor $expected, ): void { $descriptor = new Descriptor($name, $description, $version); static::assertEquals($expected, $descriptor); @@ -198,7 +198,7 @@ public function testConstructorUsingEmptyValues( /** * @param Descriptor $descriptor Descriptor of application - * @param string $expected Expected description of application + * @param string $expected Expected description of application * * @dataProvider provideDescriptorAndDescription */ @@ -209,7 +209,7 @@ public function testGetDescription(Descriptor $descriptor, string $expected): vo /** * @param Descriptor $descriptor Descriptor of application - * @param string $expected Expected name of application + * @param string $expected Expected name of application * * @dataProvider provideDescriptorAndName */ @@ -219,8 +219,8 @@ public function testGetName(Descriptor $descriptor, string $expected): void } /** - * @param Descriptor $descriptor Descriptor of application - * @param null|Version $expected Expected version of application + * @param Descriptor $descriptor Descriptor of application + * @param null|Version $expected Expected version of application * * @dataProvider provideDescriptorAndVersion */ @@ -231,13 +231,13 @@ public function testGetVersion(Descriptor $descriptor, ?Version $expected): void /** * @param Descriptor $descriptor Descriptor of application - * @param string $expected Expected string representation of descriptor + * @param string $expected Expected string representation of descriptor * * @dataProvider provideDescriptorAsString * @covers \Meritoo\CommonBundle\Application\Descriptor::__toString */ public function testToString(Descriptor $descriptor, string $expected): void { - static::assertSame($expected, (string) $descriptor); + static::assertSame($expected, (string)$descriptor); } } diff --git a/tests/Bundle/DescriptorTest.php b/tests/Bundle/DescriptorTest.php index f18f08f..2efb74e 100644 --- a/tests/Bundle/DescriptorTest.php +++ b/tests/Bundle/DescriptorTest.php @@ -12,8 +12,8 @@ use Generator; use Meritoo\Common\Collection\StringCollection; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Bundle\Descriptor; use Meritoo\Test\CommonBundle\Bundle\Descriptor\SimpleBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -92,8 +92,8 @@ public function provideArrayForDescriptor(): Generator '', new Descriptor( 'Vulputate', - 'Dolor' - ) + 'Dolor', + ), ), ]; @@ -114,8 +114,8 @@ public function provideArrayForDescriptor(): Generator null, new Descriptor( 'Euismod', - 'Quam' - ) + 'Quam', + ), ), ]; @@ -142,13 +142,13 @@ public function provideArrayForDescriptor(): Generator 'pellentesque/tortor/ultricies/quam', new Descriptor( 'Venenatis', - 'Sem' + 'Sem', ), new Descriptor( 'Adipiscing', 'Etiam', - 'Ornare\Malesuada\Venenatis\Consectetur' - ) + 'Ornare\Malesuada\Venenatis\Consectetur', + ), ), ]; } @@ -191,7 +191,7 @@ public function provideArrayFromDescriptor(): Generator 'PortaCommodoBundle', 'Commodo', 'Porta\CommodoBundle', - 'etiam/risus/parturient' + 'etiam/risus/parturient', ), true, [ @@ -209,7 +209,7 @@ public function provideArrayFromDescriptor(): Generator 'PortaCommodoBundle', 'Commodo', 'Porta\CommodoBundle', - 'etiam/risus/parturient' + 'etiam/risus/parturient', ), false, [ @@ -228,7 +228,7 @@ public function provideArrayFromDescriptor(): Generator 'Commodo', 'Porta\CommodoBundle', 'etiam/risus/parturient', - new Descriptor() + new Descriptor(), ), true, [ @@ -255,7 +255,7 @@ public function provideArrayFromDescriptor(): Generator 'Commodo', 'Porta\CommodoBundle', 'etiam/risus/parturient', - new Descriptor() + new Descriptor(), ), false, [ @@ -275,7 +275,7 @@ public function provideArrayFromDescriptor(): Generator 'Porta\CommodoBundle', 'etiam/risus/parturient', null, - new Descriptor() + new Descriptor(), ), true, [ @@ -303,7 +303,7 @@ public function provideArrayFromDescriptor(): Generator 'Porta\CommodoBundle', 'etiam/risus/parturient', null, - new Descriptor() + new Descriptor(), ), false, [ @@ -323,7 +323,7 @@ public function provideArrayFromDescriptor(): Generator 'Porta\CommodoBundle', 'etiam/risus/parturient', new Descriptor(), - new Descriptor() + new Descriptor(), ), true, [ @@ -359,7 +359,7 @@ public function provideArrayFromDescriptor(): Generator 'Porta\CommodoBundle', 'etiam/risus/parturient', new Descriptor(), - new Descriptor() + new Descriptor(), ), false, [ @@ -382,9 +382,9 @@ public function provideArrayFromDescriptor(): Generator 'OrnareEgestasBundle', 'Ornare', 'Ornare\EgestasBundle', - 'condimentum/fusce/risus' + 'condimentum/fusce/risus', ), - new Descriptor() + new Descriptor(), ), true, [ @@ -423,9 +423,9 @@ public function provideArrayFromDescriptor(): Generator 'OrnareEgestasBundle', 'Ornare', 'Ornare\EgestasBundle', - 'condimentum/fusce/risus' + 'condimentum/fusce/risus', ), - new Descriptor() + new Descriptor(), ), false, [ @@ -448,14 +448,14 @@ public function provideArrayFromDescriptor(): Generator 'OrnareEgestasBundle', 'Ornare', 'Ornare\EgestasBundle', - 'condimentum/fusce/risus' + 'condimentum/fusce/risus', ), new Descriptor( 'ParturientPharetraBundle', 'OrnareMattis', 'Parturient\PharetraBundle', - 'tortor/ullamcorper/mattis' - ) + 'tortor/ullamcorper/mattis', + ), ), true, [ @@ -494,14 +494,14 @@ public function provideArrayFromDescriptor(): Generator 'OrnareEgestasBundle', 'Ornare', 'Ornare\EgestasBundle', - 'condimentum/fusce/risus' + 'condimentum/fusce/risus', ), new Descriptor( 'ParturientPharetraBundle', 'OrnareMattis', 'Parturient\PharetraBundle', - 'tortor/ullamcorper/mattis' - ) + 'tortor/ullamcorper/mattis', + ), ), false, [ @@ -541,7 +541,7 @@ public function provideArrayFromDescriptorUsingDefaults(): Generator 'PortaCommodoBundle', 'Commodo', 'Porta\CommodoBundle', - 'etiam/risus/parturient' + 'etiam/risus/parturient', ), [ 'name' => 'PortaCommodoBundle', @@ -561,7 +561,7 @@ public function provideArrayFromDescriptorUsingDefaults(): Generator 'Commodo', 'Porta\CommodoBundle', 'etiam/risus/parturient', - new Descriptor() + new Descriptor(), ), [ 'name' => 'PortaCommodoBundle', @@ -589,7 +589,7 @@ public function provideArrayFromDescriptorUsingDefaults(): Generator 'Porta\CommodoBundle', 'etiam/risus/parturient', new Descriptor(), - new Descriptor() + new Descriptor(), ), [ 'name' => 'PortaCommodoBundle', @@ -627,9 +627,9 @@ public function provideArrayFromDescriptorUsingDefaults(): Generator 'OrnareEgestasBundle', 'Ornare', 'Ornare\EgestasBundle', - 'condimentum/fusce/risus' + 'condimentum/fusce/risus', ), - new Descriptor() + new Descriptor(), ), [ 'name' => 'PortaCommodoBundle', @@ -667,14 +667,14 @@ public function provideArrayFromDescriptorUsingDefaults(): Generator 'OrnareEgestasBundle', 'Ornare', 'Ornare\EgestasBundle', - 'condimentum/fusce/risus' + 'condimentum/fusce/risus', ), new Descriptor( 'ParturientPharetraBundle', 'OrnareMattis', 'Parturient\PharetraBundle', - 'tortor/ullamcorper/mattis' - ) + 'tortor/ullamcorper/mattis', + ), ), [ 'name' => 'PortaCommodoBundle', @@ -716,7 +716,7 @@ public function provideBundle(): Generator 'SimpleBundle', '', 'Meritoo\Test\CommonBundle\Bundle\Descriptor', - '/tests/Bundle/Descriptor' + '/tests/Bundle/Descriptor', ), ]; } @@ -740,7 +740,7 @@ public function provideChildBundleDescriptor(): Generator '', 'path/of/bundle', null, - null + null, ), null, ]; @@ -754,7 +754,7 @@ public function provideChildBundleDescriptor(): Generator '', 'path/of/bundle', null, - $childBundleDescriptor + $childBundleDescriptor, ), $childBundleDescriptor, ]; @@ -762,7 +762,7 @@ public function provideChildBundleDescriptor(): Generator $childBundleDescriptor = new Descriptor( 'Test', '', - 'This/Is/Namespace' + 'This/Is/Namespace', ); yield [ @@ -772,7 +772,7 @@ public function provideChildBundleDescriptor(): Generator '', 'path/of/bundle', null, - $childBundleDescriptor + $childBundleDescriptor, ), $childBundleDescriptor, ]; @@ -977,7 +977,7 @@ public function provideParentBundleDescriptor(): Generator '', 'path/of/bundle', null, - null + null, ), null, ]; @@ -991,7 +991,7 @@ public function provideParentBundleDescriptor(): Generator '', 'path/of/bundle', $parentBundleDescriptor, - null + null, ), $parentBundleDescriptor, ]; @@ -999,7 +999,7 @@ public function provideParentBundleDescriptor(): Generator $parentBundleDescriptor = new Descriptor( 'Test', '', - 'This/Is/Namespace' + 'This/Is/Namespace', ); yield [ @@ -1009,7 +1009,7 @@ public function provideParentBundleDescriptor(): Generator '', 'path/of/bundle', $parentBundleDescriptor, - null + null, ), $parentBundleDescriptor, ]; @@ -1090,10 +1090,9 @@ public function provideShortName(): Generator } /** - * @param Descriptor $descriptor Descriptor of bundle for who names of files with data fixtures should be - * added - * @param array $fixturesPaths Names of files with data fixtures to add - * @param StringCollection $expected Expected names of files with data fixtures after add + * @param Descriptor $descriptor Descriptor of bundle for who names of files with data fixtures should be added + * @param array $fixturesPaths Names of files with data fixtures to add + * @param StringCollection $expected Expected names of files with data fixtures after add * * @dataProvider provideDataFixturesToAdd * @covers \Meritoo\CommonBundle\Bundle\Descriptor::addDataFixtures @@ -1108,7 +1107,7 @@ public function testAddDataFixtures(Descriptor $descriptor, array $fixturesPaths public function testConstructor(): void { - static::assertConstructorVisibilityAndArguments(Descriptor::class, OopVisibilityType::IS_PUBLIC, 6); + static::assertConstructorVisibilityAndArguments(Descriptor::class, OopVisibility::Public, 6); } public function testConstructorUsingDefaults(): void @@ -1124,7 +1123,7 @@ public function testConstructorUsingDefaults(): void } /** - * @param array $array Data of descriptor + * @param array $array Data of descriptor * @param Descriptor $expected Expected descriptor * * @dataProvider provideArrayForDescriptor @@ -1145,20 +1144,20 @@ public function testFromArray(array $array, Descriptor $expected): void if (null !== $expected->getParentBundleDescriptor()) { static::assertSame( $expected->getParentBundleDescriptor()->toArray(), - $descriptor->getParentBundleDescriptor()->toArray() + $descriptor->getParentBundleDescriptor()->toArray(), ); } if (null !== $expected->getChildBundleDescriptor()) { static::assertSame( $expected->getChildBundleDescriptor()->toArray(), - $descriptor->getChildBundleDescriptor()->toArray() + $descriptor->getChildBundleDescriptor()->toArray(), ); } } /** - * @param Bundle $bundle The bundle + * @param Bundle $bundle The bundle * @param Descriptor $expected Expected descriptor * * @dataProvider provideBundle @@ -1176,8 +1175,8 @@ public function testFromBundle(Bundle $bundle, Descriptor $expected): void } /** - * @param Descriptor $descriptor Descriptor of bundle which descriptor of the child bundle should be returned - * @param null|Descriptor $expected Expected descriptor of the child bundle + * @param Descriptor $descriptor Descriptor of bundle which descriptor of the child bundle should be returned + * @param null|Descriptor $expected Expected descriptor of the child bundle * * @dataProvider provideChildBundleDescriptor */ @@ -1189,7 +1188,7 @@ public function testGetChildBundleDescriptor(Descriptor $descriptor, ?Descriptor /** * @param Descriptor $descriptor Descriptor of bundle who name of configuration root node of bundle should be * returned - * @param string $expected Expected name of configuration root node + * @param string $expected Expected name of configuration root node * * @dataProvider provideConfigurationRootName */ @@ -1199,8 +1198,8 @@ public function testGetConfigurationRootName(Descriptor $descriptor, string $exp } /** - * @param Descriptor $descriptor Descriptor of bundle who names of files with data fixtures from bundle - * @param StringCollection $expected Expected names of files with data fixtures + * @param Descriptor $descriptor Descriptor of bundle who names of files with data fixtures from bundle + * @param StringCollection $expected Expected names of files with data fixtures * * @dataProvider provideDataFixtures */ @@ -1211,9 +1210,9 @@ public function testGetDataFixtures(Descriptor $descriptor, StringCollection $ex } /** - * @param Descriptor $descriptor Descriptor of bundle which path of directory with classes for the DataFixtures - * should be returned - * @param null|string $expected Expected path + * @param Descriptor $descriptor Descriptor of bundle which path of directory with classes for the DataFixtures + * should be returned + * @param null|string $expected Expected path * * @dataProvider provideDataFixturesPath */ @@ -1224,7 +1223,7 @@ public function testGetDataFixturesDirectoryPath(Descriptor $descriptor, ?string /** * @param Descriptor $descriptor Descriptor of bundle who name should be returned - * @param string $expected Expected name + * @param string $expected Expected name * * @dataProvider provideName */ @@ -1234,8 +1233,8 @@ public function testGetName(Descriptor $descriptor, string $expected): void } /** - * @param Descriptor $descriptor Descriptor of bundle which descriptor of the parent bundle should be returned - * @param null|Descriptor $expected Expected descriptor of the parent bundle + * @param Descriptor $descriptor Descriptor of bundle which descriptor of the parent bundle should be returned + * @param null|Descriptor $expected Expected descriptor of the parent bundle * * @dataProvider provideParentBundleDescriptor */ @@ -1246,7 +1245,7 @@ public function testGetParentBundleDescriptor(Descriptor $descriptor, ?Descripto /** * @param Descriptor $descriptor Descriptor of bundle which path should be returned - * @param string $expected Expected physical path of the bundle + * @param string $expected Expected physical path of the bundle * * @dataProvider providePath */ @@ -1257,7 +1256,7 @@ public function testGetPath(Descriptor $descriptor, string $expected): void /** * @param Descriptor $descriptor Descriptor of bundle who root namespace of bundle should be returned - * @param string $expected Expected root namespace of bundle + * @param string $expected Expected root namespace of bundle * * @dataProvider provideRootNamespace */ @@ -1268,7 +1267,7 @@ public function testGetRootNamespace(Descriptor $descriptor, string $expected): /** * @param Descriptor $descriptor Descriptor of bundle who short, simple name should be returned - * @param string $expected Expected short, simple name of the bundle + * @param string $expected Expected short, simple name of the bundle * * @dataProvider provideShortName */ @@ -1279,8 +1278,8 @@ public function testGetShortName(Descriptor $descriptor, string $expected): void /** * @param Descriptor $descriptor Descriptor of bundle who should be verified if file belongs to the bundle - * @param string $filePath Path of file to verify - * @param bool $expected Expected result of verification + * @param string $filePath Path of file to verify + * @param bool $expected Expected result of verification * * @dataProvider provideFilePath */ @@ -1348,10 +1347,10 @@ public function testSetRootNamespace(): void } /** - * @param Descriptor $descriptor Descriptor of bundle who an array representation should be returned - * @param bool $withParentAndChild If is set to true, includes descriptor of the parent and child bundle - * (default behaviour). Otherwise - not. - * @param array $expected Expected array + * @param Descriptor $descriptor Descriptor of bundle who an array representation should be returned + * @param bool $withParentAndChild If is set to true, includes descriptor of the parent and child bundle (default + * behaviour). Otherwise - not. + * @param array $expected Expected array * * @dataProvider provideArrayFromDescriptor */ diff --git a/tests/Bundle/DescriptorsTest.php b/tests/Bundle/DescriptorsTest.php index 3cf4071..af0d4a9 100644 --- a/tests/Bundle/DescriptorsTest.php +++ b/tests/Bundle/DescriptorsTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Bundle; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Bundle\Descriptor; use Meritoo\CommonBundle\Bundle\Descriptors; @@ -51,8 +51,8 @@ public function provideArrayForDescriptors(): Generator '', new Descriptor( 'Vulputate', - 'Dolor' - ) + 'Dolor', + ), ), ]); @@ -128,8 +128,8 @@ public function provideArrayForDescriptors(): Generator '', new Descriptor( 'Vulputate', - 'Dolor' - ) + 'Dolor', + ), ), ]), ]; @@ -202,12 +202,12 @@ public function provideArrayFromDescriptors(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), [ @@ -277,19 +277,19 @@ public function provideDescriptorAndClassNamespace(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), 'Vestibulum\Amet\Vehicula\Egestas', new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]; @@ -298,12 +298,12 @@ public function provideDescriptorAndClassNamespace(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), new Descriptor( 'SollicitudinBundle', @@ -313,8 +313,8 @@ public function provideDescriptorAndClassNamespace(): Generator new Descriptor( 'SemBundle', '', - 'Fringilla\Quam\Mollis' - ) + 'Fringilla\Quam\Mollis', + ), ), ]), 'Cras\Risus\Amet\Vehicula\Egestas', @@ -326,8 +326,8 @@ public function provideDescriptorAndClassNamespace(): Generator new Descriptor( 'SemBundle', '', - 'Fringilla\Quam\Mollis' - ) + 'Fringilla\Quam\Mollis', + ), ), ]; } @@ -344,19 +344,19 @@ public function provideDescriptorAndName(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), 'VehiculaBundle', new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]; @@ -365,12 +365,12 @@ public function provideDescriptorAndName(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), new Descriptor( 'SollicitudinBundle', @@ -380,8 +380,8 @@ public function provideDescriptorAndName(): Generator new Descriptor( 'SemBundle', '', - 'Fringilla\Quam\Mollis' - ) + 'Fringilla\Quam\Mollis', + ), ), ]), 'SollicitudinBundle', @@ -393,8 +393,8 @@ public function provideDescriptorAndName(): Generator new Descriptor( 'SemBundle', '', - 'Fringilla\Quam\Mollis' - ) + 'Fringilla\Quam\Mollis', + ), ), ]; } @@ -423,12 +423,12 @@ public function provideNotExistingDescriptorAndClassNamespace(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), 'Vulputate\Commodo\Egestas', @@ -440,12 +440,12 @@ public function provideNotExistingDescriptorAndClassNamespace(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), 'Vulputate\Commodo\Egestas', @@ -477,12 +477,12 @@ public function provideNotExistingDescriptorAndName(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), 'CommodoBundle', @@ -494,12 +494,12 @@ public function provideNotExistingDescriptorAndName(): Generator new Descriptor( 'MattisBundle', '', - 'Euismod\Egestas\Mattis' + 'Euismod\Egestas\Mattis', ), new Descriptor( 'VehiculaBundle', 'ipsummattis', - 'Vestibulum\Amet\Vehicula' + 'Vestibulum\Amet\Vehicula', ), ]), 'EgestasBundle', @@ -509,11 +509,11 @@ public function provideNotExistingDescriptorAndName(): Generator public function testConstructor(): void { - static::assertConstructorVisibilityAndArguments(Descriptors::class, OopVisibilityType::IS_PUBLIC, 1); + static::assertConstructorVisibilityAndArguments(Descriptors::class, OopVisibility::Public, 1); } /** - * @param array $data Data of descriptors + * @param array $data Data of descriptors * @param Descriptors $expected Expected descriptors * * @dataProvider provideArrayForDescriptors @@ -525,9 +525,9 @@ public function testFromArray(array $data, Descriptors $expected): void } /** - * @param Descriptors $descriptors Descriptors of bundles - * @param string $classNamespace Namespace of class for which descriptor of bundle should be returned - * @param Descriptor $expected Expected descriptor + * @param Descriptors $descriptors Descriptors of bundles + * @param string $classNamespace Namespace of class for which descriptor of bundle should be returned + * @param Descriptor $expected Expected descriptor * * @dataProvider provideDescriptorAndClassNamespace */ @@ -546,22 +546,22 @@ public function testGetDescriptor(Descriptors $descriptors, string $classNamespa if (null !== $expected->getParentBundleDescriptor()) { static::assertSame( $expected->getParentBundleDescriptor()->toArray(), - $descriptor->getParentBundleDescriptor()->toArray() + $descriptor->getParentBundleDescriptor()->toArray(), ); } if (null !== $expected->getChildBundleDescriptor()) { static::assertSame( $expected->getChildBundleDescriptor()->toArray(), - $descriptor->getChildBundleDescriptor()->toArray() + $descriptor->getChildBundleDescriptor()->toArray(), ); } } /** * @param Descriptors $descriptors Descriptors of bundles - * @param string $bundleName Name of bundle which descriptor should be returned - * @param Descriptor $expected Expected descriptor + * @param string $bundleName Name of bundle which descriptor should be returned + * @param Descriptor $expected Expected descriptor * * @dataProvider provideDescriptorAndName */ @@ -580,21 +580,21 @@ public function testGetDescriptorByName(Descriptors $descriptors, string $bundle if (null !== $expected->getParentBundleDescriptor()) { static::assertSame( $expected->getParentBundleDescriptor()->toArray(), - $descriptor->getParentBundleDescriptor()->toArray() + $descriptor->getParentBundleDescriptor()->toArray(), ); } if (null !== $expected->getChildBundleDescriptor()) { static::assertSame( $expected->getChildBundleDescriptor()->toArray(), - $descriptor->getChildBundleDescriptor()->toArray() + $descriptor->getChildBundleDescriptor()->toArray(), ); } } /** * @param Descriptors $descriptors Descriptors of bundles - * @param string $bundleName Name of bundle which descriptor should be returned + * @param string $bundleName Name of bundle which descriptor should be returned * * @dataProvider provideNotExistingDescriptorAndName */ @@ -604,8 +604,8 @@ public function testGetDescriptorByNameWhenDoesNotExist(Descriptors $descriptors } /** - * @param Descriptors $descriptors Descriptors of bundles - * @param string $classNamespace Namespace of class for which descriptor of bundle should be returned + * @param Descriptors $descriptors Descriptors of bundles + * @param string $classNamespace Namespace of class for which descriptor of bundle should be returned * * @dataProvider provideNotExistingDescriptorAndClassNamespace */ @@ -616,7 +616,7 @@ public function testGetDescriptorWhenDoesNotExist(Descriptors $descriptors, stri /** * @param Descriptors $descriptors Descriptors of bundles - * @param array $expected Expected array + * @param array $expected Expected array * * @dataProvider provideArrayFromDescriptors */ diff --git a/tests/DependencyInjection/Base/BaseExtensionTest.php b/tests/DependencyInjection/Base/BaseExtensionTest.php index bb1dbe7..706ed19 100644 --- a/tests/DependencyInjection/Base/BaseExtensionTest.php +++ b/tests/DependencyInjection/Base/BaseExtensionTest.php @@ -13,11 +13,9 @@ use Generator; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\CommonBundle\DependencyInjection\Base\BaseExtension; -use Meritoo\CommonBundle\Exception\Type\DependencyInjection\UnknownConfigurationFileTypeException; use Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\EmptyBundlePath\Extension as EmptyBundlePathExtension; use Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\NotExistingServicesFile\Extension as NotExistingServicesFileExtension; use Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\PhpServicesFileType\Extension as PhpServicesFileTypeExtension; -use Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\UnknownServicesFileType\Extension as UnknownServicesFileTypeExtension; use Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\WithoutParameters\Extension as WithoutParametersExtension; use Meritoo\Test\CommonBundle\DependencyInjection\Base\BaseExtension\XmlServicesFileType\Extension as XmlServicesFileTypeExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -87,19 +85,4 @@ public function testLoadingParametersAndServices(BaseExtension $extension): void */ static::assertCount(1, $container->getServiceIds()); } - - public function testLoadingParametersWithUnknownServicesFileType(): void - { - $message = 'The \'txt\' type of Dependency Injection (DI) configuration file is unknown. Probably doesn\'t' - .' exist or there is a typo. You should use one of these types: php, xml, yaml.'; - - $this->expectException(UnknownConfigurationFileTypeException::class); - $this->expectExceptionMessage($message); - - $container = new ContainerBuilder(); - $extension = new UnknownServicesFileTypeExtension(); - - $configuration = []; - $extension->load($configuration, $container); - } } diff --git a/tests/DependencyInjection/ConfigurationFile/FileLoaderFactoryTest.php b/tests/DependencyInjection/ConfigurationFile/FileLoaderFactoryTest.php index 9c4a504..ce0266e 100644 --- a/tests/DependencyInjection/ConfigurationFile/FileLoaderFactoryTest.php +++ b/tests/DependencyInjection/ConfigurationFile/FileLoaderFactoryTest.php @@ -10,8 +10,8 @@ namespace Meritoo\Test\CommonBundle\DependencyInjection\ConfigurationFile; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\DependencyInjection\ConfigurationFile\FileLoaderFactory; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Config\FileLocator; @@ -37,9 +37,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( FileLoaderFactory::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 2, 2, - 2 ); } diff --git a/tests/Exception/Controller/BaseController/CannotRedirectToEmptyRefererUrlExceptionTest.php b/tests/Exception/Controller/BaseController/CannotRedirectToEmptyRefererUrlExceptionTest.php index 1c76e54..e3b64b4 100644 --- a/tests/Exception/Controller/BaseController/CannotRedirectToEmptyRefererUrlExceptionTest.php +++ b/tests/Exception/Controller/BaseController/CannotRedirectToEmptyRefererUrlExceptionTest.php @@ -10,8 +10,8 @@ namespace Meritoo\Test\CommonBundle\Exception\Controller\BaseController; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Contract\Service\RequestServiceInterface; use Meritoo\CommonBundle\Exception\Controller\BaseController\CannotRedirectToEmptyRefererUrlException; @@ -30,8 +30,8 @@ public function testConstructorVisibilityAndArguments(): void { static::assertConstructorVisibilityAndArguments( CannotRedirectToEmptyRefererUrlException::class, - OopVisibilityType::IS_PUBLIC, - 3 + OopVisibility::Public, + 3, ); } diff --git a/tests/Exception/Pagination/IncorrectCurrentPageExceptionTest.php b/tests/Exception/Pagination/IncorrectCurrentPageExceptionTest.php index a1ca69b..1b41e3f 100644 --- a/tests/Exception/Pagination/IncorrectCurrentPageExceptionTest.php +++ b/tests/Exception/Pagination/IncorrectCurrentPageExceptionTest.php @@ -4,8 +4,8 @@ namespace Meritoo\Test\CommonBundle\Exception\Pagination; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Exception\ValueObject\Pagination\IncorrectCurrentPageException; /** @@ -23,9 +23,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( IncorrectCurrentPageException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } @@ -36,7 +36,7 @@ public function testCreate(): void static::assertSame( 'The \'current page\' parameter of pagination should be greater than 0, but 0 was provided. Is there' .' everything ok?', - $exception->getMessage() + $exception->getMessage(), ); } } diff --git a/tests/Exception/Pagination/IncorrectPerPageExceptionTest.php b/tests/Exception/Pagination/IncorrectPerPageExceptionTest.php index 118b45e..898e937 100644 --- a/tests/Exception/Pagination/IncorrectPerPageExceptionTest.php +++ b/tests/Exception/Pagination/IncorrectPerPageExceptionTest.php @@ -4,8 +4,8 @@ namespace Meritoo\Test\CommonBundle\Exception\Pagination; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Exception\ValueObject\Pagination\IncorrectPerPageException; /** @@ -23,9 +23,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( IncorrectPerPageException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } @@ -36,7 +36,7 @@ public function testCreate(): void static::assertSame( 'The \'per page\' parameter of pagination should be greater than 0, but 0 was provided. Is there' .' everything ok?', - $exception->getMessage() + $exception->getMessage(), ); } } diff --git a/tests/Exception/Pagination/IncorrectTotalAmountExceptionTest.php b/tests/Exception/Pagination/IncorrectTotalAmountExceptionTest.php index b886db9..154ef65 100644 --- a/tests/Exception/Pagination/IncorrectTotalAmountExceptionTest.php +++ b/tests/Exception/Pagination/IncorrectTotalAmountExceptionTest.php @@ -4,8 +4,8 @@ namespace Meritoo\Test\CommonBundle\Exception\Pagination; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Exception\ValueObject\Pagination\IncorrectTotalAmountException; /** @@ -23,9 +23,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( IncorrectTotalAmountException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } @@ -36,7 +36,7 @@ public function testCreate(): void static::assertSame( 'The \'total amount\' parameter of pagination should be greater than or equal 0, but -1 was' .' provided. Is there everything ok?', - $exception->getMessage() + $exception->getMessage(), ); } } diff --git a/tests/Exception/Service/EmptyVersionFilePathExceptionTest.php b/tests/Exception/Service/EmptyVersionFilePathExceptionTest.php index 3e895b1..1719973 100644 --- a/tests/Exception/Service/EmptyVersionFilePathExceptionTest.php +++ b/tests/Exception/Service/EmptyVersionFilePathExceptionTest.php @@ -10,8 +10,8 @@ namespace Meritoo\Test\CommonBundle\Exception\Service; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Exception\Service\ApplicationService\EmptyVersionFilePathException; /** @@ -27,12 +27,15 @@ class EmptyVersionFilePathExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments(): void { - static::assertConstructorVisibilityAndArguments(EmptyVersionFilePathException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(EmptyVersionFilePathException::class, OopVisibility::Public, 3); } public function testCreate(): void { $exception = EmptyVersionFilePathException::create(); - static::assertSame('Path of a file, who contains version of the application, is empty. Is there everything ok?', $exception->getMessage()); + + static::assertSame('Path of a file, who contains version of the application, is empty. Is there everything ok?', + $exception->getMessage(), + ); } } diff --git a/tests/Exception/Service/UnreadableVersionFileExceptionTest.php b/tests/Exception/Service/UnreadableVersionFileExceptionTest.php index 4c991a1..df2ca95 100644 --- a/tests/Exception/Service/UnreadableVersionFileExceptionTest.php +++ b/tests/Exception/Service/UnreadableVersionFileExceptionTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Exception\Service; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Exception\Service\ApplicationService\UnreadableVersionFileException; /** @@ -53,11 +53,15 @@ public function provideFilePathAndMessage(): Generator public function testConstructorVisibilityAndArguments(): void { - static::assertConstructorVisibilityAndArguments(UnreadableVersionFileException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments( + UnreadableVersionFileException::class, + OopVisibility::Public, + 3, + ); } /** - * @param string $filePath Path of a file who contains version of the application + * @param string $filePath Path of a file who contains version of the application * @param string $expectedMessage Expected message of exception * * @dataProvider provideFilePathAndMessage diff --git a/tests/Exception/Type/Date/UnknownDateLengthExceptionTest.php b/tests/Exception/Type/Date/UnknownDateLengthExceptionTest.php deleted file mode 100644 index 2826e2e..0000000 --- a/tests/Exception/Type/Date/UnknownDateLengthExceptionTest.php +++ /dev/null @@ -1,80 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\CommonBundle\Exception\Type\Date\UnknownDateLengthException - */ -class UnknownDateLengthExceptionTest extends BaseTestCase -{ - public function provideUnknownTypeAndMessage(): ?Generator - { - $template = 'The \'%s\' type of %s is unknown. Probably doesn\'t exist or there is a typo. You should use one' - .' of these types: %s.'; - - $allTypes = (new DateLength())->getAll(); - $types = Arrays::values2string($allTypes, '', ', '); - - yield [ - 'An empty string', - '', - sprintf($template, '', 'date length for date format', $types), - ]; - - yield [ - 'Strange type 1', - 'xyz ;asdkq28h', - sprintf($template, 'xyz ;asdkq28h', 'date length for date format', $types), - ]; - - yield [ - 'Strange type 2', - ' _ & #---# ++;;...', - sprintf($template, ' _ & #---# ++;;...', 'date length for date format', $types), - ]; - } - - public function testConstructorVisibilityAndArguments(): void - { - static::assertConstructorVisibilityAndArguments( - UnknownConfigurationFileTypeException::class, - OopVisibilityType::IS_PUBLIC, - 3 - ); - } - - /** - * @param string $description Description of test - * @param string $unknownType Unknown type of date length for date format - * @param string $expectedMessage Expected message of exception - * - * @dataProvider provideUnknownTypeAndMessage - */ - public function testCreateException(string $description, string $unknownType, string $expectedMessage): void - { - $exception = UnknownDateLengthException::createException($unknownType); - static::assertSame($expectedMessage, $exception->getMessage(), $description); - } -} diff --git a/tests/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeExceptionTest.php b/tests/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeExceptionTest.php deleted file mode 100644 index 643151e..0000000 --- a/tests/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeExceptionTest.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\CommonBundle\Exception\Type\DependencyInjection\UnknownConfigurationFileTypeException - */ -class UnknownConfigurationFileTypeExceptionTest extends BaseTestCase -{ - /** - * Provides unknown type and message of exception - * - * @return Generator - */ - public function provideUnknownTypeAndMessage(): Generator - { - $template = 'The \'%s\' type of Dependency Injection (DI) configuration file is unknown. Probably doesn\'t' - .' exist or there is a typo. You should use one of these types: php, xml, yaml.'; - - yield [ - '', - sprintf($template, ''), - ]; - - yield [ - 'jpg', - sprintf($template, 'jpg'), - ]; - - yield [ - 'txt', - sprintf($template, 'txt'), - ]; - - yield [ - 'yml', - sprintf($template, 'yml'), - ]; - } - - public function testConstructorVisibilityAndArguments(): void - { - static::assertConstructorVisibilityAndArguments(UnknownConfigurationFileTypeException::class, OopVisibilityType::IS_PUBLIC, 3); - } - - /** - * @param string $unknownType Unknown type of Dependency Injection (DI) configuration file - * @param string $expectedMessage Expected message of exception - * - * @dataProvider provideUnknownTypeAndMessage - */ - public function testCreateException(string $unknownType, string $expectedMessage): void - { - $exception = UnknownConfigurationFileTypeException::createException($unknownType); - static::assertSame($expectedMessage, $exception->getMessage()); - } -} diff --git a/tests/Resources/config/packages/framework.yaml b/tests/Resources/config/packages/framework.yaml index 3223ff1..5e39153 100644 --- a/tests/Resources/config/packages/framework.yaml +++ b/tests/Resources/config/packages/framework.yaml @@ -1,7 +1,7 @@ framework: ide: phpstorm secret: '%env(APP_SECRET)%' - default_locale: '%env(APP_DEFAULT_LOCALE)%' + default_locale: '%locale%' #csrf_protection: true #http_method_override: true diff --git a/tests/Resources/config/packages/test/framework.yaml b/tests/Resources/config/packages/test/framework.yaml index d051c84..76eaa63 100644 --- a/tests/Resources/config/packages/test/framework.yaml +++ b/tests/Resources/config/packages/test/framework.yaml @@ -2,3 +2,7 @@ framework: test: true session: storage_id: session.storage.mock_file + translator: + default_path: '%kernel.project_dir%/../src/Resources/translations' + fallbacks: + - '%locale%' diff --git a/tests/Resources/config/services_test.yaml b/tests/Resources/config/services_test.yaml index db556f6..c04c70e 100644 --- a/tests/Resources/config/services_test.yaml +++ b/tests/Resources/config/services_test.yaml @@ -1,3 +1,6 @@ +parameters: + locale: '%env(APP_DEFAULT_LOCALE)%' + services: _defaults: public: true diff --git a/tests/Service/ApplicationServiceTest.php b/tests/Service/ApplicationServiceTest.php index a82629d..2fb0be7 100644 --- a/tests/Service/ApplicationServiceTest.php +++ b/tests/Service/ApplicationServiceTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Service; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Version; use Meritoo\CommonBundle\Application\Descriptor; use Meritoo\CommonBundle\Exception\Service\ApplicationService\EmptyVersionFilePathException; @@ -60,7 +60,7 @@ public function provideConstructorArgumentsAndDescriptor(): Generator new Descriptor( 'Lorem', 'Sed posuere consectetur est at lobortis', - new Version(5, 46, 17) + new Version(5, 46, 17), ), ]; } @@ -69,9 +69,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( ApplicationService::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 3, 3, - 3 ); } @@ -97,10 +97,10 @@ public function testConstructorUsingUnreadableVersionFilePath(): void } /** - * @param string $versionFilePath Path of a file who contains version of the application - * @param null|string $applicationName Name of application. May be displayed near logo. + * @param string $versionFilePath Path of a file who contains version of the application + * @param null|string $applicationName Name of application. May be displayed near logo. * @param null|string $applicationDescription Description of application. May be displayed near logo. - * @param Descriptor $expected Expected descriptor of application + * @param Descriptor $expected Expected descriptor of application * * @dataProvider provideConstructorArgumentsAndDescriptor */ @@ -108,7 +108,7 @@ public function testGetDescriptor( string $versionFilePath, ?string $applicationName, ?string $applicationDescription, - Descriptor $expected + Descriptor $expected, ): void { $service = new ApplicationService($versionFilePath, $applicationName, $applicationDescription); static::assertEquals($expected, $service->getDescriptor()); @@ -119,7 +119,7 @@ public function testGetDescriptorUsingTestEnvironment(): void $expected = new Descriptor( 'This is a Test', 'Just for Testing', - new Version(1, 2, 0) + new Version(1, 2, 0), ); static::assertEquals($expected, $this->applicationService->getDescriptor()); diff --git a/tests/Service/DateServiceTest.php b/tests/Service/DateServiceTest.php index 786e2d6..077bcb5 100644 --- a/tests/Service/DateServiceTest.php +++ b/tests/Service/DateServiceTest.php @@ -15,11 +15,10 @@ use DateTimeZone; use Generator; use IntlDateFormatter; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; -use Meritoo\CommonBundle\Exception\Type\Date\UnknownDateLengthException; +use Meritoo\CommonBundle\Enums\Date\DateLength; use Meritoo\CommonBundle\Service\DateService; -use Meritoo\CommonBundle\Type\Date\DateLength; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; /** @@ -51,17 +50,17 @@ class DateServiceTest extends KernelTestCase public function provideDateFormatUsingDefaults(): Generator { yield [ - DateLength::DATE, + DateLength::Date, 'd.m.Y', ]; yield [ - DateLength::DATETIME, + DateLength::DateTime, 'd.m.Y H:i', ]; yield [ - DateLength::TIME, + DateLength::Time, 'H:i', ]; } @@ -74,17 +73,17 @@ public function provideDateFormatUsingDefaults(): Generator public function provideDateFormatUsingTestEnvironment(): Generator { yield [ - DateLength::DATE, + DateLength::Date, 'Y.m.d', ]; yield [ - DateLength::DATETIME, + DateLength::DateTime, 'Y.m.d H:i:s', ]; yield [ - DateLength::TIME, + DateLength::Time, 'H:i:s', ]; } @@ -103,73 +102,73 @@ public function provideDateFormattedUsingDefaults(): Generator yield [ new DateTime($date1, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '01.02.1900', ]; yield [ new DateTime($date2, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '15.10.2000', ]; yield [ new DateTime($date3, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '01.05.2100', ]; yield [ new DateTime($date4, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '01.08.2200', ]; yield [ new DateTime($date1, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '01.02.1900 08:25', ]; yield [ new DateTime($date2, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '15.10.2000 10:05', ]; yield [ new DateTime($date3, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '01.05.2100 00:00', ]; yield [ new DateTime($date4, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '01.08.2200 20:00', ]; yield [ new DateTime($date1, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '08:25', ]; yield [ new DateTime($date2, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '10:05', ]; yield [ new DateTime($date3, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '00:00', ]; yield [ new DateTime($date4, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '20:00', ]; } @@ -181,7 +180,7 @@ public function provideDateFormattedUsingDefaults(): Generator */ public function provideDateFormattedUsingLocale(): Generator { - $locale = 'en_EN'; + $locale = 'en_US'; $dateString = '1900-02-01 08:25:40'; /* @@ -237,7 +236,7 @@ public function provideDateFormattedUsingLocale(): Generator IntlDateFormatter::SHORT, $locale, new DateTime($dateString, new DateTimeZone(static::TIMEZONE)), - '8:25 AM', + '8:25鈥疉M', ]; yield [ @@ -245,7 +244,7 @@ public function provideDateFormattedUsingLocale(): Generator IntlDateFormatter::MEDIUM, $locale, new DateTime($dateString, new DateTimeZone(static::TIMEZONE)), - '8:25:40 AM', + '8:25:40鈥疉M', ]; // @@ -275,7 +274,7 @@ public function provideDateFormattedUsingLocale(): Generator IntlDateFormatter::SHORT, $locale, new DateTime($dateString, new DateTimeZone(static::TIMEZONE)), - 'Feb 1, 1900, 8:25 AM', + 'Feb 1, 1900, 8:25鈥疉M', ]; yield [ @@ -283,7 +282,7 @@ public function provideDateFormattedUsingLocale(): Generator IntlDateFormatter::MEDIUM, $locale, new DateTime($dateString, new DateTimeZone(static::TIMEZONE)), - 'February 1, 1900 at 8:25:40 AM', + 'February 1, 1900 at 8:25:40鈥疉M', ]; } @@ -300,55 +299,55 @@ public function provideDateFormattedUsingTestEnvironment(): Generator yield [ new DateTime($date1, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '1900.02.01', ]; yield [ new DateTime($date2, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '2000.10.15', ]; yield [ new DateTime($date3, new DateTimeZone(static::TIMEZONE)), - DateLength::DATE, + DateLength::Date, '2100.05.01', ]; yield [ new DateTime($date1, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '1900.02.01 08:25:40', ]; yield [ new DateTime($date2, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '2000.10.15 10:05:40', ]; yield [ new DateTime($date3, new DateTimeZone(static::TIMEZONE)), - DateLength::DATETIME, + DateLength::DateTime, '2100.05.01 00:00:00', ]; yield [ new DateTime($date1, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '08:25:40', ]; yield [ new DateTime($date2, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '10:05:40', ]; yield [ new DateTime($date3, new DateTimeZone(static::TIMEZONE)), - DateLength::TIME, + DateLength::Time, '00:00:00', ]; } @@ -385,23 +384,23 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( DateService::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 3, 3, - 3 ); } /** - * @param DateTimeInterface $dateTime The date to format - * @param string $dateLength Type of date length - * @param string $expected Expected date + * @param DateTimeInterface $dateTime The date to format + * @param DateLength $dateLength Type of date length + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingDefaults */ public function testFormatDateUsingDefaults( DateTimeInterface $dateTime, - string $dateLength, - string $expected + DateLength $dateLength, + string $expected, ): void { static::bootKernel([ 'environment' => 'default', @@ -416,13 +415,13 @@ public function testFormatDateUsingDefaults( } /** - * @param int $dateType Type/length of date part in the returned string. One of constants of the + * @param int $dateType Type/length of date part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. - * @param int $timeType Type/length of time part in the returned string. One of constants of the + * @param int $timeType Type/length of time part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. - * @param string $locale Locale used to format given date - * @param DateTimeInterface $dateTime The date to format - * @param string $expected Expected date + * @param string $locale Locale used to format given date + * @param DateTimeInterface $dateTime The date to format + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingLocale */ @@ -431,7 +430,7 @@ public function testFormatDateUsingLocaleAndDefaults( int $timeType, string $locale, DateTimeInterface $dateTime, - string $expected + string $expected, ): void { static::bootKernel([ 'environment' => 'default', @@ -443,7 +442,7 @@ public function testFormatDateUsingLocaleAndDefaults( $dateType, $timeType, $locale, - $dateTime + $dateTime, ) ; @@ -451,13 +450,13 @@ public function testFormatDateUsingLocaleAndDefaults( } /** - * @param int $dateType Type/length of date part in the returned string. One of constants of the + * @param int $dateType Type/length of date part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. - * @param int $timeType Type/length of time part in the returned string. One of constants of the + * @param int $timeType Type/length of time part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. - * @param string $locale Locale used to format given date - * @param DateTimeInterface $dateTime The date to format - * @param string $expected Expected date + * @param string $locale Locale used to format given date + * @param DateTimeInterface $dateTime The date to format + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingLocale */ @@ -466,7 +465,7 @@ public function testFormatDateUsingLocaleAndTestEnvironment( int $timeType, string $locale, DateTimeInterface $dateTime, - string $expected + string $expected, ): void { $formatted = $this ->dateService @@ -474,7 +473,7 @@ public function testFormatDateUsingLocaleAndTestEnvironment( $dateType, $timeType, $locale, - $dateTime + $dateTime, ) ; @@ -482,39 +481,29 @@ public function testFormatDateUsingLocaleAndTestEnvironment( } /** - * @param DateTimeInterface $dateTime The date to format - * @param string $dateLength Type of date length - * @param string $expected Expected date + * @param DateTimeInterface $dateTime The date to format + * @param DateLength $dateLength Type of date length + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingTestEnvironment */ public function testFormatDateUsingTestEnvironment( DateTimeInterface $dateTime, - string $dateLength, - string $expected + DateLength $dateLength, + string $expected, ): void { static::assertSame($expected, $this->dateService->formatDate($dateTime, $dateLength)); } /** - * @param string $dateLength Unknown type of date length - * @dataProvider provideUnknownDateLength - */ - public function testFormatDateUsingUnknownDateLength(string $dateLength): void - { - $this->expectException(UnknownDateLengthException::class); - $this->dateService->formatDate(new DateTime(), $dateLength); - } - - /** - * @param string $dateLength Type of date length - * @param string $expected Expected date format + * @param DateLength $dateLength Type of date length + * @param string $expected Expected date format * * @dataProvider provideDateFormatUsingDefaults */ public function testGetFormatUsingDefaults( - string $dateLength, - string $expected + DateLength $dateLength, + string $expected, ): void { static::bootKernel([ 'environment' => 'default', @@ -529,28 +518,18 @@ public function testGetFormatUsingDefaults( } /** - * @param string $dateLength Type of date length - * @param string $expected Expected date format + * @param DateLength $dateLength Type of date length + * @param string $expected Expected date format * * @dataProvider provideDateFormatUsingTestEnvironment */ public function testGetFormatUsingTestEnvironment( - string $dateLength, - string $expected + DateLength $dateLength, + string $expected, ): void { static::assertSame($expected, $this->dateService->getFormat($dateLength)); } - /** - * @param string $dateLength Unknown type of date length - * @dataProvider provideUnknownDateLength - */ - public function testGetFormatUsingUnknownDateLength(string $dateLength): void - { - $this->expectException(UnknownDateLengthException::class); - $this->dateService->getFormat($dateLength); - } - /** * {@inheritdoc} */ diff --git a/tests/Service/FormServiceTest.php b/tests/Service/FormServiceTest.php index a2435ca..31fecdb 100644 --- a/tests/Service/FormServiceTest.php +++ b/tests/Service/FormServiceTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Service; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Contract\Service\FormServiceInterface; use Meritoo\CommonBundle\Service\FormService; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -94,7 +94,7 @@ public function provideExistingFormOptionsUsingDefaults(): Generator /** * @param array $existingOptions Existing options - * @param array $expected Expected options + * @param array $expected Expected options * * @dataProvider provideExistingFormOptionsCustomConfiguration */ @@ -114,7 +114,7 @@ public function testAddHtml5ValidationOptionsUsingDefaults(array $existingOption /** * @param array $existingOptions Existing options - * @param array $expected Expected options + * @param array $expected Expected options * * @dataProvider provideExistingFormOptionsUsingDefaults */ @@ -128,9 +128,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( FormService::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } diff --git a/tests/Service/PaginationServiceTest.php b/tests/Service/PaginationServiceTest.php index a2ab026..d55fab6 100644 --- a/tests/Service/PaginationServiceTest.php +++ b/tests/Service/PaginationServiceTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Service; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\Reflection; use Meritoo\CommonBundle\Contract\Service\PaginationServiceInterface; use Meritoo\CommonBundle\Exception\Pagination\MissingPerPageAmountException; @@ -79,9 +79,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( PaginationService::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 5, - 2 + 2, ); } diff --git a/tests/Service/RequestServiceTest.php b/tests/Service/RequestServiceTest.php index f7e7bbd..c5d3fbf 100644 --- a/tests/Service/RequestServiceTest.php +++ b/tests/Service/RequestServiceTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Service; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Contract\Service\RequestServiceInterface; use Meritoo\CommonBundle\Exception\Service\Request\UnknownRequestException; use Meritoo\CommonBundle\Service\RequestService; @@ -143,14 +143,15 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( RequestService::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 2, 2, - 2 ); } /** * @param string $expected Expected url of referer + * * @dataProvider provideUrl */ public function testFetchRefererUrl(string $expected): void @@ -333,7 +334,7 @@ public function testGetParameterIfCurrentRequestIsUnknown(): void } /** - * @param Request $request The request (that probably contains referer) + * @param Request $request The request (that probably contains referer) * @param null|string $expected Expected url of referer * * @dataProvider provideRequestAndRefererUrl @@ -383,6 +384,7 @@ public function testIsCurrentRouteIfCurrentRequestIsUnknown(): void /** * @param string $url The referer url to store + * * @dataProvider provideUrl */ public function testStoreRefererUrl(string $url): void @@ -392,7 +394,7 @@ public function testStoreRefererUrl(string $url): void } /** - * @param Request $request The request (that probably contains referer) + * @param Request $request The request (that probably contains referer) * @param null|string $expected Expected url of referer * * @dataProvider provideRequestAndRefererUrlToStore diff --git a/tests/Service/ResponseServiceTest.php b/tests/Service/ResponseServiceTest.php index 35edd5a..53d213b 100644 --- a/tests/Service/ResponseServiceTest.php +++ b/tests/Service/ResponseServiceTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Service; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Service\ResponseService; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -60,17 +60,17 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( ResponseService::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } /** - * @param string $routeName The name of the route. Used to build url used for redirection. - * @param array $routeParameters An array of parameters. Used to build url used for redirection. - * @param string $url Url that should be generated and used for redirection - * @param RedirectResponse $expected Expected instance of RedirectResponse + * @param string $routeName The name of the route. Used to build url used for redirection. + * @param array $routeParameters An array of parameters. Used to build url used for redirection. + * @param string $url Url that should be generated and used for redirection + * @param RedirectResponse $expected Expected instance of RedirectResponse * * @dataProvider provideRouteDetailsForRedirectResponse */ @@ -78,11 +78,12 @@ public function testGetRedirectResponse( string $routeName, array $routeParameters, string $url, - RedirectResponse $expected + RedirectResponse $expected, ): void { $redirectResponse = $this ->getResponseService($routeName, $routeParameters, $url) - ->getRedirectResponse($routeName, $routeParameters); + ->getRedirectResponse($routeName, $routeParameters) + ; static::assertSame($expected->getTargetUrl(), $redirectResponse->getTargetUrl()); static::assertSame($expected->getContent(), $redirectResponse->getContent()); @@ -103,9 +104,10 @@ protected function setUp(): void /** * Returns instance of ResponseService with all related and mocked instances * - * @param string $routeName The name of the route. Used to build url used for redirection. - * @param array $routeParameters An array of parameters. Used to build url used for redirection. - * @param string $url Url that should be generated and used for redirection + * @param string $routeName The name of the route. Used to build url used for redirection. + * @param array $routeParameters An array of parameters. Used to build url used for redirection. + * @param string $url Url that should be generated and used for redirection + * * @return ResponseService */ private function getResponseService(string $routeName, array $routeParameters, string $url): ResponseService diff --git a/tests/Translations/TranslationsTest.php b/tests/Translations/TranslationsTest.php new file mode 100644 index 0000000..e50f158 --- /dev/null +++ b/tests/Translations/TranslationsTest.php @@ -0,0 +1,304 @@ + + * @copyright Meritoo.pl + * + * @coversNothing + */ +class TranslationsTest extends KernelTestCase +{ + private TranslatorInterface $translator; + + public function providePlurals(): \Generator + { + // Action + yield '0 Actions' => ['meritoo_common.general.action', ['count' => 0], 'words', 'pl', 'Akcji']; + yield '1 Action' => ['meritoo_common.general.action', ['count' => 1], 'words', 'pl', 'Akcja']; + yield '2 Actions' => ['meritoo_common.general.action', ['count' => 2], 'words', 'pl', 'Akcje']; + yield '5 Actions' => ['meritoo_common.general.action', ['count' => 5], 'words', 'pl', 'Akcji']; + yield '100 Actions' => ['meritoo_common.general.action', ['count' => 100], 'words', 'pl', 'Akcji']; + + yield '0 Actions DE' => ['meritoo_common.general.action', ['count' => 0], 'words', 'de', 'Aktionen']; + yield '1 Action DE' => ['meritoo_common.general.action', ['count' => 1], 'words', 'de', 'Aktion']; + yield '2 Actions DE' => ['meritoo_common.general.action', ['count' => 2], 'words', 'de', 'Aktionen']; + yield '5 Actions DE' => ['meritoo_common.general.action', ['count' => 5], 'words', 'de', 'Aktionen']; + yield '100 Actions DE' => ['meritoo_common.general.action', ['count' => 100], 'words', 'de', 'Aktionen']; + + // Error + yield '0 Errors' => ['meritoo_common.general.error', ['count' => 0], 'words', 'pl', 'B艂臋d贸w']; + yield '1 Error' => ['meritoo_common.general.error', ['count' => 1], 'words', 'pl', 'B艂膮d']; + yield '2 Errors' => ['meritoo_common.general.error', ['count' => 2], 'words', 'pl', 'B艂臋dy']; + yield '5 Errors' => ['meritoo_common.general.error', ['count' => 5], 'words', 'pl', 'B艂臋d贸w']; + yield '100 Errors' => ['meritoo_common.general.error', ['count' => 100], 'words', 'pl', 'B艂臋d贸w']; + + // Advantage + yield '0 Advantages DE' => ['meritoo_common.general.advantage', ['count' => 0], 'words', 'pl', 'Zalet']; + yield '1 Advantage DE' => ['meritoo_common.general.advantage', ['count' => 1], 'words', 'pl', 'Zaleta']; + yield '2 Advantages DE' => ['meritoo_common.general.advantage', ['count' => 2], 'words', 'pl', 'Zalety']; + yield '5 Advantages DE' => ['meritoo_common.general.advantage', ['count' => 5], 'words', 'pl', 'Zalet']; + yield '100 Advantages DE' => ['meritoo_common.general.advantage', ['count' => 100], 'words', 'pl', 'Zalet']; + + yield '0 Advantages' => ['meritoo_common.general.advantage', ['count' => 0], 'words', 'de', 'Vorteile']; + yield '1 Advantage' => ['meritoo_common.general.advantage', ['count' => 1], 'words', 'de', 'Vorteil']; + yield '2 Advantages' => ['meritoo_common.general.advantage', ['count' => 2], 'words', 'de', 'Vorteile']; + yield '5 Advantages' => ['meritoo_common.general.advantage', ['count' => 5], 'words', 'de', 'Vorteile']; + yield '100 Advantages' => ['meritoo_common.general.advantage', ['count' => 100], 'words', 'de', 'Vorteile']; + + // Invitation + yield '0 Invitations' => ['meritoo_common.general.invitation', ['count' => 0], 'words', 'pl', 'Zaprosze艅']; + yield '1 Invitation' => ['meritoo_common.general.invitation', ['count' => 1], 'words', 'pl', 'Zaproszenie']; + yield '2 Invitations' => ['meritoo_common.general.invitation', ['count' => 2], 'words', 'pl', 'Zaproszenia']; + yield '5 Invitations' => ['meritoo_common.general.invitation', ['count' => 5], 'words', 'pl', 'Zaprosze艅']; + yield '100 Invitations' => ['meritoo_common.general.invitation', ['count' => 100], 'words', 'pl', 'Zaprosze艅']; + + // Ingredient + yield '0 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 0], 'words', 'pl', 'Sk艂adnik贸w']; + yield '1 Ingredient' => ['meritoo_common.general.ingredient', ['count' => 1], 'words', 'pl', 'Sk艂adnik']; + yield '2 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 2], 'words', 'pl', 'Sk艂adniki']; + yield '5 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 5], 'words', 'pl', 'Sk艂adnik贸w']; + yield '100 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 100], 'words', 'pl', 'Sk艂adnik贸w']; + + // Picture + yield '0 Pictures' => ['meritoo_common.general.picture', ['count' => 0], 'words', 'pl', 'Obrazk贸w']; + yield '1 Picture' => ['meritoo_common.general.picture', ['count' => 1], 'words', 'pl', 'Obrazek']; + yield '2 Pictures' => ['meritoo_common.general.picture', ['count' => 2], 'words', 'pl', 'Obrazki']; + yield '5 Pictures' => ['meritoo_common.general.picture', ['count' => 5], 'words', 'pl', 'Obrazk贸w']; + yield '100 Pictures' => ['meritoo_common.general.picture', ['count' => 100], 'words', 'pl', 'Obrazk贸w']; + + // Photo + yield '0 Photos' => ['meritoo_common.general.photo', ['count' => 0], 'words', 'pl', 'Zdj臋膰']; + yield '1 Photo' => ['meritoo_common.general.photo', ['count' => 1], 'words', 'pl', 'Zdj臋cie']; + yield '2 Photos' => ['meritoo_common.general.photo', ['count' => 2], 'words', 'pl', 'Zdj臋cia']; + yield '5 Photos' => ['meritoo_common.general.photo', ['count' => 5], 'words', 'pl', 'Zdj臋膰']; + yield '100 Photos' => ['meritoo_common.general.photo', ['count' => 100], 'words', 'pl', 'Zdj臋膰']; + + // Certificate + yield '0 Certificates' => ['meritoo_common.general.certificate', ['count' => 0], 'words', 'pl', 'Certyfikat贸w']; + yield '1 Certificate' => ['meritoo_common.general.certificate', ['count' => 1], 'words', 'pl', 'Certyfikat']; + yield '2 Certificates' => ['meritoo_common.general.certificate', ['count' => 2], 'words', 'pl', 'Certyfikaty']; + yield '5 Certificates' => ['meritoo_common.general.certificate', ['count' => 5], 'words', 'pl', 'Certyfikat贸w']; + yield '100 Certificates' => ['meritoo_common.general.certificate', ['count' => 100], 'words', 'pl', 'Certyfikat贸w']; + + // Message + yield '0 Messages' => ['meritoo_common.general.message', ['count' => 0], 'words', 'pl', 'Wiadomo艣ci']; + yield '1 Message' => ['meritoo_common.general.message', ['count' => 1], 'words', 'pl', 'Wiadomo艣膰']; + yield '2 Messages' => ['meritoo_common.general.message', ['count' => 2], 'words', 'pl', 'Wiadomo艣ci']; + yield '5 Messages' => ['meritoo_common.general.message', ['count' => 5], 'words', 'pl', 'Wiadomo艣ci']; + yield '100 Messages' => ['meritoo_common.general.message', ['count' => 100], 'words', 'pl', 'Wiadomo艣ci']; + + // Day + yield '0 Days' => ['meritoo_common.general.day', ['count' => 0], 'words', 'pl', 'Dni']; + yield '1 Day' => ['meritoo_common.general.day', ['count' => 1], 'words', 'pl', 'Dzie艅']; + yield '2 Days' => ['meritoo_common.general.day', ['count' => 2], 'words', 'pl', 'Dni']; + yield '5 Days' => ['meritoo_common.general.day', ['count' => 5], 'words', 'pl', 'Dni']; + yield '100 Days' => ['meritoo_common.general.day', ['count' => 100], 'words', 'pl', 'Dni']; + + // Month + yield '0 Months' => ['meritoo_common.general.month', ['count' => 0], 'words', 'pl', 'Miesi臋cy']; + yield '1 Month' => ['meritoo_common.general.month', ['count' => 1], 'words', 'pl', 'Miesi膮c']; + yield '2 Months' => ['meritoo_common.general.month', ['count' => 2], 'words', 'pl', 'Miesi膮ce']; + yield '5 Months' => ['meritoo_common.general.month', ['count' => 5], 'words', 'pl', 'Miesi臋cy']; + yield '100 Months' => ['meritoo_common.general.month', ['count' => 100], 'words', 'pl', 'Miesi臋cy']; + + // Year + yield '0 Years' => ['meritoo_common.general.year', ['count' => 0], 'words', 'pl', 'Lat']; + yield '1 Year' => ['meritoo_common.general.year', ['count' => 1], 'words', 'pl', 'Rok']; + yield '2 Years' => ['meritoo_common.general.year', ['count' => 2], 'words', 'pl', 'Lata']; + yield '5 Years' => ['meritoo_common.general.year', ['count' => 5], 'words', 'pl', 'Lat']; + yield '100 Years' => ['meritoo_common.general.year', ['count' => 100], 'words', 'pl', 'Lat']; + + // Transaction + yield '0 Transactions' => ['meritoo_common.finances.transaction', ['count' => 0], 'words', 'pl', 'Transakcji']; + yield '1 Transaction' => ['meritoo_common.finances.transaction', ['count' => 1], 'words', 'pl', 'Transakcja']; + yield '2 Transactions' => ['meritoo_common.finances.transaction', ['count' => 2], 'words', 'pl', 'Transakcje']; + yield '5 Transactions' => ['meritoo_common.finances.transaction', ['count' => 5], 'words', 'pl', 'Transakcji']; + yield '100 Transactions' => ['meritoo_common.finances.transaction', ['count' => 100], 'words', 'pl', 'Transakcji']; + + // Page + yield '0 Pages' => ['meritoo_common.pagination.page', ['count' => 0], 'words', 'pl', 'Stron']; + yield '1 Page' => ['meritoo_common.pagination.page', ['count' => 1], 'words', 'pl', 'Strona']; + yield '2 Pages' => ['meritoo_common.pagination.page', ['count' => 2], 'words', 'pl', 'Strony']; + yield '5 Pages' => ['meritoo_common.pagination.page', ['count' => 5], 'words', 'pl', 'Stron']; + yield '100 Pages' => ['meritoo_common.pagination.page', ['count' => 100], 'words', 'pl', 'Stron']; + } + + public function providePluralsForDefaultLocale(): \Generator + { + // Action + yield '0 Actions' => ['meritoo_common.general.action', ['count' => 0], 'words', 'Actions']; + yield '1 Action' => ['meritoo_common.general.action', ['count' => 1], 'words', 'Action']; + yield '2 Actions' => ['meritoo_common.general.action', ['count' => 2], 'words', 'Actions']; + yield '5 Actions' => ['meritoo_common.general.action', ['count' => 5], 'words', 'Actions']; + yield '100 Actions' => ['meritoo_common.general.action', ['count' => 100], 'words', 'Actions']; + + // Error + yield '0 Errors' => ['meritoo_common.general.error', ['count' => 0], 'words', 'Errors']; + yield '1 Error' => ['meritoo_common.general.error', ['count' => 1], 'words', 'Error']; + yield '2 Errors' => ['meritoo_common.general.error', ['count' => 2], 'words', 'Errors']; + yield '5 Errors' => ['meritoo_common.general.error', ['count' => 5], 'words', 'Errors']; + yield '100 Errors' => ['meritoo_common.general.error', ['count' => 100], 'words', 'Errors']; + + // Advantage + yield '0 Advantages' => ['meritoo_common.general.advantage', ['count' => 0], 'words', 'Advantages']; + yield '1 Advantage' => ['meritoo_common.general.advantage', ['count' => 1], 'words', 'Advantage']; + yield '2 Advantages' => ['meritoo_common.general.advantage', ['count' => 2], 'words', 'Advantages']; + yield '5 Advantages' => ['meritoo_common.general.advantage', ['count' => 5], 'words', 'Advantages']; + yield '100 Advantages' => ['meritoo_common.general.advantage', ['count' => 100], 'words', 'Advantages']; + + // Invitation + yield '0 Invitations' => ['meritoo_common.general.invitation', ['count' => 0], 'words', 'Invitations']; + yield '1 Invitation' => ['meritoo_common.general.invitation', ['count' => 1], 'words', 'Invitation']; + yield '2 Invitations' => ['meritoo_common.general.invitation', ['count' => 2], 'words', 'Invitations']; + yield '5 Invitations' => ['meritoo_common.general.invitation', ['count' => 5], 'words', 'Invitations']; + yield '100 Invitations' => ['meritoo_common.general.invitation', ['count' => 100], 'words', 'Invitations']; + + // Ingredient + yield '0 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 0], 'words', 'Ingredients']; + yield '1 Ingredient' => ['meritoo_common.general.ingredient', ['count' => 1], 'words', 'Ingredient']; + yield '2 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 2], 'words', 'Ingredients']; + yield '5 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 5], 'words', 'Ingredients']; + yield '100 Ingredients' => ['meritoo_common.general.ingredient', ['count' => 100], 'words', 'Ingredients']; + + // Picture + yield '0 Pictures' => ['meritoo_common.general.picture', ['count' => 0], 'words', 'Pictures']; + yield '1 Picture' => ['meritoo_common.general.picture', ['count' => 1], 'words', 'Picture']; + yield '2 Pictures' => ['meritoo_common.general.picture', ['count' => 2], 'words', 'Pictures']; + yield '5 Pictures' => ['meritoo_common.general.picture', ['count' => 5], 'words', 'Pictures']; + yield '100 Pictures' => ['meritoo_common.general.picture', ['count' => 100], 'words', 'Pictures']; + + // Photo + yield '0 Photos' => ['meritoo_common.general.photo', ['count' => 0], 'words', 'Photos']; + yield '1 Photo' => ['meritoo_common.general.photo', ['count' => 1], 'words', 'Photo']; + yield '2 Photos' => ['meritoo_common.general.photo', ['count' => 2], 'words', 'Photos']; + yield '5 Photos' => ['meritoo_common.general.photo', ['count' => 5], 'words', 'Photos']; + yield '100 Photos' => ['meritoo_common.general.photo', ['count' => 100], 'words', 'Photos']; + + // Certificate + yield '0 Certificates' => ['meritoo_common.general.certificate', ['count' => 0], 'words', 'Certificates']; + yield '1 Certificate' => ['meritoo_common.general.certificate', ['count' => 1], 'words', 'Certificate']; + yield '2 Certificates' => ['meritoo_common.general.certificate', ['count' => 2], 'words', 'Certificates']; + yield '5 Certificates' => ['meritoo_common.general.certificate', ['count' => 5], 'words', 'Certificates']; + yield '100 Certificates' => ['meritoo_common.general.certificate', ['count' => 100], 'words', 'Certificates']; + + // Message + yield '0 Messages' => ['meritoo_common.general.message', ['count' => 0], 'words', 'Messages']; + yield '1 Message' => ['meritoo_common.general.message', ['count' => 1], 'words', 'Message']; + yield '2 Messages' => ['meritoo_common.general.message', ['count' => 2], 'words', 'Messages']; + yield '5 Messages' => ['meritoo_common.general.message', ['count' => 5], 'words', 'Messages']; + yield '100 Messages' => ['meritoo_common.general.message', ['count' => 100], 'words', 'Messages']; + + // Day + yield '0 Days' => ['meritoo_common.general.day', ['count' => 0], 'words', 'Days']; + yield '1 Day' => ['meritoo_common.general.day', ['count' => 1], 'words', 'Day']; + yield '2 Days' => ['meritoo_common.general.day', ['count' => 2], 'words', 'Days']; + yield '5 Days' => ['meritoo_common.general.day', ['count' => 5], 'words', 'Days']; + yield '100 Days' => ['meritoo_common.general.day', ['count' => 100], 'words', 'Days']; + + // Month + yield '0 Months' => ['meritoo_common.general.month', ['count' => 0], 'words', 'Months']; + yield '1 Month' => ['meritoo_common.general.month', ['count' => 1], 'words', 'Month']; + yield '2 Months' => ['meritoo_common.general.month', ['count' => 2], 'words', 'Months']; + yield '5 Months' => ['meritoo_common.general.month', ['count' => 5], 'words', 'Months']; + yield '100 Months' => ['meritoo_common.general.month', ['count' => 100], 'words', 'Months']; + + // Year + yield '0 Years' => ['meritoo_common.general.year', ['count' => 0], 'words', 'Years']; + yield '1 Year' => ['meritoo_common.general.year', ['count' => 1], 'words', 'Year']; + yield '2 Years' => ['meritoo_common.general.year', ['count' => 2], 'words', 'Years']; + yield '5 Years' => ['meritoo_common.general.year', ['count' => 5], 'words', 'Years']; + yield '100 Years' => ['meritoo_common.general.year', ['count' => 100], 'words', 'Years']; + + // Transaction + yield '0 Transactions' => ['meritoo_common.finances.transaction', ['count' => 0], 'words', 'Transactions']; + yield '1 Transaction' => ['meritoo_common.finances.transaction', ['count' => 1], 'words', 'Transaction']; + yield '2 Transactions' => ['meritoo_common.finances.transaction', ['count' => 2], 'words', 'Transactions']; + yield '5 Transactions' => ['meritoo_common.finances.transaction', ['count' => 5], 'words', 'Transactions']; + yield '100 Transactions' => ['meritoo_common.finances.transaction', ['count' => 100], 'words', 'Transactions']; + + // Page + yield '0 Pages' => ['meritoo_common.pagination.page', ['count' => 0], 'words', 'Pages']; + yield '1 Page' => ['meritoo_common.pagination.page', ['count' => 1], 'words', 'Page']; + yield '2 Pages' => ['meritoo_common.pagination.page', ['count' => 2], 'words', 'Pages']; + yield '5 Pages' => ['meritoo_common.pagination.page', ['count' => 5], 'words', 'Pages']; + yield '100 Pages' => ['meritoo_common.pagination.page', ['count' => 100], 'words', 'Pages']; + } + + public function provideSingulars(): \Generator + { + yield 'Name' => ['meritoo_common.general.name', 'words', 'pl', 'Nazwa']; + yield 'Title' => ['meritoo_common.general.title', 'words', 'pl', 'Tytu艂']; + yield 'Version' => ['meritoo_common.general.version', 'words', 'pl', 'Wersja']; + } + + public function provideSingularsForDefaultLocale(): \Generator + { + yield 'Name' => ['meritoo_common.general.name', 'words', 'Name']; + yield 'Title' => ['meritoo_common.general.title', 'words', 'Title']; + yield 'Version' => ['meritoo_common.general.version', 'words', 'Version']; + } + + /** + * @dataProvider providePlurals + */ + public function testPlurals( + string $key, + array $parameters, + string $domain, + string $locale, + string $expected + ): void { + self::assertSame($expected, $this->translator->trans($key, $parameters, $domain, $locale)); + } + + /** + * @dataProvider providePluralsForDefaultLocale + */ + public function testPluralsUsingDefaultLocale( + string $key, + array $parameters, + string $domain, + string $expected + ): void { + self::assertSame($expected, $this->translator->trans($key, $parameters, $domain)); + } + + /** + * @dataProvider provideSingulars + */ + public function testSingulars(string $key, string $domain, string $locale, string $expected): void + { + self::assertSame($expected, $this->translator->trans($key, [], $domain, $locale)); + } + + /** + * @dataProvider provideSingularsForDefaultLocale + */ + public function testSingularsUsingDefaultLocale(string $key, string $domain, string $expected): void + { + self::assertSame($expected, $this->translator->trans($key, [], $domain)); + } + + protected function setUp(): void + { + parent::setUp(); + static::bootKernel(); + + $this->translator = self::getContainer()->get(TranslatorInterface::class); + } +} diff --git a/tests/Twig/ApplicationRuntimeTest.php b/tests/Twig/ApplicationRuntimeTest.php index 7b97045..f6f9c1e 100644 --- a/tests/Twig/ApplicationRuntimeTest.php +++ b/tests/Twig/ApplicationRuntimeTest.php @@ -10,8 +10,8 @@ namespace Meritoo\Test\CommonBundle\Twig; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Version; use Meritoo\CommonBundle\Application\Descriptor; use Meritoo\CommonBundle\Exception\Service\ApplicationService\UnreadableVersionFileException; @@ -38,9 +38,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( ApplicationRuntime::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } @@ -63,7 +63,7 @@ public function testGetDescriptorUsingTestEnvironment(): void $expected = new Descriptor( 'This is a Test', 'Just for Testing', - new Version(1, 2, 0) + new Version(1, 2, 0), ); static::assertEquals($expected, $this->applicationRuntime->getDescriptor()); diff --git a/tests/Twig/CommonRuntimeTest.php b/tests/Twig/CommonRuntimeTest.php index 8856455..2246fd2 100644 --- a/tests/Twig/CommonRuntimeTest.php +++ b/tests/Twig/CommonRuntimeTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\Twig; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Twig\CommonRuntime; use stdClass; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -225,9 +225,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( CommonRuntime::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } @@ -237,23 +237,23 @@ public function testIsInstanceOfRuntimeExtensionInterface(): void } /** - * @param mixed $value The value to check + * @param mixed $value The value to check * @param null|string $emptyValueReplacement Custom replacement of empty value. If is set to null, the - * replacement is retrieved from configuration (default behaviour). - * @param mixed $expected Expected value + * replacement is retrieved from configuration (default behaviour). + * @param mixed $expected Expected value * * @dataProvider provideValueAndValueReplacementToVerifyEmptyValue */ public function testVerifyEmptyValueUsingCustomValueReplacement( $value, ?string $emptyValueReplacement, - $expected + $expected, ): void { static::assertSame($expected, $this->commonRuntime->verifyEmptyValue($value, $emptyValueReplacement)); } /** - * @param mixed $value The value to check + * @param mixed $value The value to check * @param mixed $expected Expected value * * @dataProvider provideValueToVerifyEmptyValueUsingDefaults @@ -273,7 +273,7 @@ public function testVerifyEmptyValueUsingDefaults($value, $expected): void } /** - * @param mixed $value The value to check + * @param mixed $value The value to check * @param mixed $expected Expected value * * @dataProvider provideValueToVerifyEmptyValue diff --git a/tests/Twig/FormRuntimeTest.php b/tests/Twig/FormRuntimeTest.php index 74564d2..f778169 100644 --- a/tests/Twig/FormRuntimeTest.php +++ b/tests/Twig/FormRuntimeTest.php @@ -10,8 +10,8 @@ namespace Meritoo\Test\CommonBundle\Twig; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Twig\FormRuntime; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Twig\Extension\RuntimeExtensionInterface; @@ -35,9 +35,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( FormRuntime::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } diff --git a/tests/Twig/HtmlExtensionTest.php b/tests/Twig/HtmlExtensionTest.php new file mode 100644 index 0000000..768a1b7 --- /dev/null +++ b/tests/Twig/HtmlExtensionTest.php @@ -0,0 +1,66 @@ + + * @copyright Meritoo + * + * @internal + * @covers \Meritoo\CommonBundle\Twig\HtmlExtension + * @covers \Meritoo\CommonBundle\Test\Twig\Base\BaseTwigExtensionTestCase + */ +class HtmlExtensionTest extends BaseTwigExtensionTestCase +{ + public function provideAttributes(): \Generator + { + yield 'Empty object' => [ + 'attributes_2_string_empty_object', + '{{ {}|meritoo_common_html_attributes_2_string }}', + '', + ]; + + yield 'Empty array' => [ + 'attributes_2_string_empty_array', + '{{ []|meritoo_common_html_attributes_2_string }}', + '', + ]; + + yield 'Non empty' => [ + 'attributes_2_string_object', + '{{ {test1: "lorem", test2: "ipsum"}|meritoo_common_html_attributes_2_string }}', + 'test1="lorem" test2="ipsum"', + ]; + } + + /** + * @dataProvider provideAttributes + */ + public function testAttributes2String(string $name, string $sourceCode, string $expected): void + { + $this->verifyRenderedTemplate($name, $sourceCode, $expected); + } + + public function testGetFilters(): void + { + static::assertCount(1, $this->twigExtension->getFilters()); + } + + protected function getExtensionNamespace(): string + { + return HtmlExtension::class; + } +} diff --git a/tests/Twig/HtmlRuntimeTest.php b/tests/Twig/HtmlRuntimeTest.php new file mode 100644 index 0000000..ab1e746 --- /dev/null +++ b/tests/Twig/HtmlRuntimeTest.php @@ -0,0 +1,74 @@ + + * @copyright Meritoo + * + * @internal + * @covers \Meritoo\CommonBundle\Twig\HtmlRuntime + */ +class HtmlRuntimeTest extends KernelTestCase +{ + use BaseTestCaseTrait; + + private HtmlRuntime $htmlRuntime; + + public function provideAttributes(): \Generator + { + yield 'Empty array' => [ + [], + null, + ]; + + yield 'Non empty' => [ + ['test1' => 'lorem', 'test2' => 'ipsum'], + 'test1="lorem" test2="ipsum"', + ]; + } + + /** + * @dataProvider provideAttributes + */ + public function testAttributes2string(array $attributes, ?string $expected): void + { + static::assertSame($expected, $this->htmlRuntime->attributes2string($attributes)); + } + + public function testConstructor(): void + { + static::assertHasNoConstructor(HtmlRuntime::class); + } + + public function testIsInstanceOfRuntimeExtensionInterface(): void + { + static::assertInstanceOf(RuntimeExtensionInterface::class, $this->htmlRuntime); + } + + protected function setUp(): void + { + parent::setUp(); + static::bootKernel(); + + /** @var HtmlRuntime $htmlRuntime */ + $htmlRuntime = static::getContainer()->get(HtmlRuntime::class); + + $this->htmlRuntime = $htmlRuntime; + } +} diff --git a/tests/Twig/MenuRuntimeTest.php b/tests/Twig/MenuRuntimeTest.php index a2a10a7..a9a1a0d 100644 --- a/tests/Twig/MenuRuntimeTest.php +++ b/tests/Twig/MenuRuntimeTest.php @@ -10,8 +10,8 @@ namespace Meritoo\Test\CommonBundle\Twig; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Contract\Service\MenuServiceInterface; use Meritoo\CommonBundle\Twig\MenuRuntime; use PHPUnit\Framework\MockObject\MockObject; @@ -41,9 +41,9 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( MenuRuntime::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, + 1, 1, - 1 ); } diff --git a/tests/Type/Date/DateLengthTest.php b/tests/Type/Date/DateLengthTest.php deleted file mode 100644 index 57c2d58..0000000 --- a/tests/Type/Date/DateLengthTest.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\CommonBundle\Type\Date\DateLength - */ -class DateLengthTest extends BaseTypeTestCase -{ - /** - * {@inheritdoc} - */ - public function provideTypeToVerify(): Generator - { - yield [ - DateLength::isCorrectType(''), - false, - ]; - - yield [ - DateLength::isCorrectType(null), - false, - ]; - - yield [ - DateLength::isCorrectType('0'), - false, - ]; - - yield [ - DateLength::isCorrectType('1'), - false, - ]; - - yield [ - DateLength::isCorrectType('date'), - true, - ]; - - yield [ - DateLength::isCorrectType('datetime'), - true, - ]; - - yield [ - DateLength::isCorrectType('time'), - true, - ]; - } - - /** - * {@inheritdoc} - */ - protected function getAllExpectedTypes(): array - { - return [ - 'DATE' => DateLength::DATE, - 'DATETIME' => DateLength::DATETIME, - 'TIME' => DateLength::TIME, - ]; - } - - /** - * {@inheritdoc} - */ - protected function getTestedTypeInstance(): BaseType - { - return new DateLength(); - } -} diff --git a/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php b/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php deleted file mode 100644 index c1cd6e4..0000000 --- a/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php +++ /dev/null @@ -1,167 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\CommonBundle\Type\DependencyInjection\ConfigurationFileType - */ -class ConfigurationFileTypeTest extends BaseTypeTestCase -{ - /** - * Provides name and type of configuration file - * - * @return Generator - */ - public function provideFileNameAndType(): Generator - { - yield [ - 'example.yaml', - 'yaml', - ]; - - yield [ - 'example.xml', - 'xml', - ]; - - yield [ - 'example.php', - 'php', - ]; - } - - /** - * Provides name of configuration file with unknown extension - * - * @return Generator - */ - public function provideFileNameWithUnknownExtension(): Generator - { - yield [ - '', - '', - ]; - - yield [ - '0', - '', - ]; - - yield [ - 'example.jpg', - '', - ]; - - yield [ - 'example.yml', - '', - ]; - } - - /** - * {@inheritdoc} - */ - public function provideTypeToVerify(): Generator - { - yield [ - ConfigurationFileType::isCorrectType(''), - false, - ]; - - yield [ - ConfigurationFileType::isCorrectType(null), - false, - ]; - - yield [ - ConfigurationFileType::isCorrectType('0'), - false, - ]; - - yield [ - ConfigurationFileType::isCorrectType('1'), - false, - ]; - - yield [ - ConfigurationFileType::isCorrectType('jpg'), - false, - ]; - - yield [ - ConfigurationFileType::isCorrectType('php'), - true, - ]; - - yield [ - ConfigurationFileType::isCorrectType('xml'), - true, - ]; - - yield [ - ConfigurationFileType::isCorrectType('yaml'), - true, - ]; - } - - /** - * @param string $fileName Name of configuration file - * @param string $expected Expected type of configuration file - * - * @dataProvider provideFileNameAndType - */ - public function testGetTypeFromFileName(string $fileName, string $expected): void - { - static::assertSame($expected, ConfigurationFileType::getTypeFromFileName($fileName)); - } - - /** - * @param string $fileName Name of configuration file - * @dataProvider provideFileNameWithUnknownExtension - */ - public function testGetTypeFromFileNameWithUnknownExtension(string $fileName): void - { - $this->expectException(UnknownConfigurationFileTypeException::class); - ConfigurationFileType::getTypeFromFileName($fileName); - } - - /** - * {@inheritdoc} - */ - protected function getAllExpectedTypes(): array - { - return [ - 'PHP' => ConfigurationFileType::PHP, - 'XML' => ConfigurationFileType::XML, - 'YAML' => ConfigurationFileType::YAML, - ]; - } - - /** - * {@inheritdoc} - */ - protected function getTestedTypeInstance(): BaseType - { - return new ConfigurationFileType(); - } -} diff --git a/tests/ValueObject/PaginationTest.php b/tests/ValueObject/PaginationTest.php index 227cd5f..86fa58a 100644 --- a/tests/ValueObject/PaginationTest.php +++ b/tests/ValueObject/PaginationTest.php @@ -11,8 +11,8 @@ namespace Meritoo\Test\CommonBundle\ValueObject; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\CommonBundle\Exception\ValueObject\Pagination\IncorrectCurrentPageException; use Meritoo\CommonBundle\Exception\ValueObject\Pagination\IncorrectPerPageException; use Meritoo\CommonBundle\Exception\ValueObject\Pagination\IncorrectTotalAmountException; @@ -181,10 +181,10 @@ public function providePaginationToValidatePageNumber(): ?Generator /** * @param string $description - * @param int $expected - * @param int $totalAmount - * @param int $perPage - * @param int $currentPage + * @param int $expected + * @param int $totalAmount + * @param int $perPage + * @param int $currentPage * * @dataProvider providePaginationToCalculateOffset */ @@ -193,7 +193,7 @@ public function testCalculateOffset( int $expected, int $totalAmount, int $perPage, - int $currentPage = 1 + int $currentPage = 1, ): void { $pagination = new Pagination($totalAmount, $perPage, $currentPage); static::assertSame($pagination->calculateOffset(), $expected, $description); @@ -201,10 +201,10 @@ public function testCalculateOffset( /** * @param string $description - * @param int $expected - * @param int $totalAmount - * @param int $perPage - * @param int $currentPage + * @param int $expected + * @param int $totalAmount + * @param int $perPage + * @param int $currentPage * * @dataProvider providePaginationToCalculatePagesCount */ @@ -213,7 +213,7 @@ public function testCalculatePagesCount( int $expected, int $totalAmount, int $perPage, - int $currentPage = 1 + int $currentPage = 1, ): void { $pagination = new Pagination($totalAmount, $perPage, $currentPage); static::assertSame($pagination->calculatePagesCount(), $expected, $description); @@ -223,16 +223,16 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( Pagination::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3, - 2 + 2, ); } /** - * @param int $totalAmount - * @param int $perPage - * @param int $currentPage + * @param int $totalAmount + * @param int $perPage + * @param int $currentPage * @param string $expectedExceptionClass * * @dataProvider provideIncorrectParametersToCreate @@ -241,7 +241,7 @@ public function testCreateUsingIncorrectParameters( int $totalAmount, int $perPage, int $currentPage, - string $expectedExceptionClass + string $expectedExceptionClass, ): void { $this->expectException($expectedExceptionClass); new Pagination($totalAmount, $perPage, $currentPage); @@ -249,10 +249,10 @@ public function testCreateUsingIncorrectParameters( /** * @param string $description - * @param int $expected - * @param int $totalAmount - * @param int $perPage - * @param int $currentPage + * @param int $expected + * @param int $totalAmount + * @param int $perPage + * @param int $currentPage * * @dataProvider providePaginationToCurrentPage */ @@ -261,7 +261,7 @@ public function testGetCurrentPage( int $expected, int $totalAmount, int $perPage, - int $currentPage = 1 + int $currentPage = 1, ): void { $pagination = new Pagination($totalAmount, $perPage, $currentPage); static::assertSame($pagination->getCurrentPage(), $expected, $description); @@ -277,11 +277,11 @@ public function testGetPerPage(): void /** * @param string $description - * @param bool $expected - * @param int $page - * @param int $totalAmount - * @param int $perPage - * @param int $currentPage + * @param bool $expected + * @param int $page + * @param int $totalAmount + * @param int $perPage + * @param int $currentPage * * @dataProvider providePaginationToValidatePageNumber */ @@ -291,7 +291,7 @@ public function testIsValidPage( int $page, int $totalAmount, int $perPage, - int $currentPage = 1 + int $currentPage = 1, ): void { $pagination = new Pagination($totalAmount, $perPage, $currentPage); static::assertSame($pagination->isValidPage($page), $expected, $description);