diff --git a/.gitignore b/.gitignore index 367f914..cf9c44f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor/ composer.lock phpunit.xml build/ +.php-cs-fixer.cache \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..f4b1812 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,42 @@ +setRiskyAllowed(false) + ->setRules([ + '@PSR2' => true, + '@Symfony' => true, + 'header_comment' => [ + 'header' => '', + 'separate' => 'none', + ], + 'single_blank_line_before_namespace' => true, + 'no_extra_blank_lines' => [ + 'tokens' => [ + 'break', + 'continue', + 'extra', + 'return', + 'throw', + 'use', + 'parenthesis_brace_block', + 'square_brace_block', + 'curly_brace_block' + ] + ], + 'phpdoc_align' => false, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'cast_spaces' => true, + 'binary_operator_spaces' => false, + 'increment_style' => false, + 'yoda_style' => false, + 'trailing_comma_in_multiline' => true, + 'single_line_throw' => false, + ]) + ->setFinder( + (new PhpCsFixer\Finder()) + ->exclude([ + 'vendor', + ]) + ->in(__DIR__) + ); \ No newline at end of file diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 6976e37..0000000 --- a/.php_cs +++ /dev/null @@ -1,63 +0,0 @@ -setUsingCache(true) - ->setFinder( - Finder::create() - ->exclude([ - 'vendor', - ]) - ->in(__DIR__) - ) - ->setRules([ - '@PSR2' => true, - 'class_definition' => [ - 'multiLineExtendsEachSingleLine' => true, - ], - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => [ - 'align_double_arrow' => false, - 'align_equals' => false, - ], - 'concat_space' => [ - 'spacing' => 'one', - ], - 'general_phpdoc_annotation_remove' => [ - 'author', - 'package', - ], - 'no_multiline_whitespace_before_semicolons' => true, - 'no_null_property_initialization' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => [ - 'order' => [ - 'use_trait', - 'constant_public', - 'constant_protected', - 'constant_private', - 'property_public', - 'property_protected', - 'property_private', - 'construct' - ] - ], - 'ordered_imports' => [ - 'sortAlgorithm' => 'alpha' - ], - 'phpdoc_order' => true, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last' - ], - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_annotation_without_dot' => true, - 'yoda_style' => false, - 'blank_line_before_statement' => [ - 'statements' => [ - 'return' - ] - ], - 'no_blank_lines_after_class_opening' => true - ]); diff --git a/composer.json b/composer.json index 367d98b..605758b 100644 --- a/composer.json +++ b/composer.json @@ -4,16 +4,16 @@ "type": "library", "license": "MIT", "require": { - "php": "^7.1", - "ulrichsg/getopt-php": "^3.2" + "php": "^7.4 || ^8.0", + "ulrichsg/getopt-php": "^4.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "phpunit/phpunit": "^7.5", - "vlucas/phpdotenv": "^2.4" + "friendsofphp/php-cs-fixer": "~v3.12.0", + "phpunit/phpunit": "^9.5", + "vlucas/phpdotenv": "v3.6.10" }, "suggest": { - "vlucas/phpdotenv": "Required for DotEnvV2FileReaderAdapter." + "vlucas/phpdotenv": "Required for DotEnvFileReaderAdapter" }, "autoload": { "psr-4": { diff --git a/src/Decorator/EnvProviderDecorator.php b/src/Decorator/EnvProviderDecorator.php index d3ccb7b..9ca23d9 100644 --- a/src/Decorator/EnvProviderDecorator.php +++ b/src/Decorator/EnvProviderDecorator.php @@ -9,10 +9,7 @@ final class EnvProviderDecorator { - /** - * @var EnvResolvingStrategyInterface|null $resolvingStrategy - */ - private static $resolvingStrategy; + private static ?EnvResolvingStrategyInterface $resolvingStrategy; public static function init(EnvResolvingStrategyInterface $resolvingStrategy): void { @@ -25,9 +22,7 @@ public static function resetStrategy(): void } /** - * @param string $envName * @throws EnvProviderDecoratorException - * @return string */ public static function getEnv(string $envName): string { diff --git a/src/Factory/FileBasedEnvResolvingStrategyFactory.php b/src/Factory/FileBasedEnvResolvingStrategyFactory.php index bac097b..8cb2da3 100644 --- a/src/Factory/FileBasedEnvResolvingStrategyFactory.php +++ b/src/Factory/FileBasedEnvResolvingStrategyFactory.php @@ -34,7 +34,7 @@ public static function createStrategy( return new FileBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector($serverHeaderToSearch), - new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build()), ]), new DotEnvV2FileReaderAdapter( new PathResolver($basePathToEnvFile, new SuffixAppendFormatter(DIRECTORY_SEPARATOR)), diff --git a/src/Factory/HostBasedEnvResolvingStrategyFactory.php b/src/Factory/HostBasedEnvResolvingStrategyFactory.php index 3ca8238..91d4702 100644 --- a/src/Factory/HostBasedEnvResolvingStrategyFactory.php +++ b/src/Factory/HostBasedEnvResolvingStrategyFactory.php @@ -31,11 +31,11 @@ public static function createStrategy( return new HostBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector($serverHeaderToSearch), - new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build()), ]), new FormatterPipeline([ new PrefixAppendFormatter($delimiter), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]) ); } diff --git a/src/FileReader/DotEnvV2FileReaderAdapter.php b/src/FileReader/DotEnvV2FileReaderAdapter.php index a8b005a..7fb3f57 100644 --- a/src/FileReader/DotEnvV2FileReaderAdapter.php +++ b/src/FileReader/DotEnvV2FileReaderAdapter.php @@ -4,6 +4,8 @@ namespace Lamoda\MultiEnv\FileReader; +use Dotenv\Dotenv; +use Dotenv\Exception\ExceptionInterface; use Lamoda\MultiEnv\FileReader\Exception\EnvFileReaderException; use Lamoda\MultiEnv\FileReader\FileNameResolver\FileNameResolverInterface; use Lamoda\MultiEnv\FileReader\PathResolver\PathResolverInterface; @@ -11,26 +13,17 @@ final class DotEnvV2FileReaderAdapter implements EnvFileReaderInterface { - /** - * @var PathResolverInterface - */ - private $pathResolver; + private PathResolverInterface $pathResolver; - /** - * @var FileNameResolverInterface - */ - private $fileNameResolver; + private FileNameResolverInterface $fileNameResolver; - /** - * @var bool - */ - private $isEnvFileAlreadyLoaded; + private bool $isEnvFileAlreadyLoaded; public function __construct(PathResolverInterface $pathResolver, FileNameResolverInterface $fileNameResolver) { // @codeCoverageIgnoreStart - if (!class_exists(\Dotenv\Dotenv::class)) { - throw EnvFileReaderException::becauseAdapterCanNotBeCreated(__CLASS__, \Dotenv\Dotenv::class); + if (!class_exists(Dotenv::class)) { + throw EnvFileReaderException::becauseAdapterCanNotBeCreated(__CLASS__, Dotenv::class); } // @codeCoverageIgnoreEnd $this->pathResolver = $pathResolver; @@ -45,13 +38,13 @@ public function readEnvFile(HostId $hostId): void } try { - $dotEnv = new \Dotenv\Dotenv( + $dotEnv = Dotenv::create( $this->pathResolver->resolvePathToEnvFile($hostId), $this->fileNameResolver->resolveEnvFileName($hostId) ); $dotEnv->overload(); $this->isEnvFileAlreadyLoaded = true; - } catch (\Dotenv\Exception\ExceptionInterface $exception) { + } catch (ExceptionInterface $exception) { throw EnvFileReaderException::becauseEnvFileCanNotBeProcessed($exception); } } diff --git a/src/FileReader/Exception/EnvFileReaderException.php b/src/FileReader/Exception/EnvFileReaderException.php index c58a16a..abe7fe2 100644 --- a/src/FileReader/Exception/EnvFileReaderException.php +++ b/src/FileReader/Exception/EnvFileReaderException.php @@ -14,7 +14,7 @@ public static function becauseEnvFileCanNotBeProcessed(?Throwable $previous): se return new self('Can\'t process file with env', 0, $previous); } - public static function becauseAdapterCanNotBeCreated(string $adapterName, string $required) + public static function becauseAdapterCanNotBeCreated(string $adapterName, string $required): self { return new self('Can\t create adapter "' . $adapterName . '". It\'s require "' . $required . '"'); } diff --git a/src/FileReader/FileNameResolver/FileNameResolver.php b/src/FileReader/FileNameResolver/FileNameResolver.php index a177f3f..431b231 100644 --- a/src/FileReader/FileNameResolver/FileNameResolver.php +++ b/src/FileReader/FileNameResolver/FileNameResolver.php @@ -10,15 +10,10 @@ final class FileNameResolver implements FileNameResolverInterface { public const DEFAULT_FILE_NAME = '.env'; - /** - * @var string - */ - private $originalFileName; - - /** - *@var FormatterInterface|null - */ - private $formatter; + + private string $originalFileName; + + private ?FormatterInterface $formatter; public function __construct(string $originalFileName = self::DEFAULT_FILE_NAME, FormatterInterface $formatter = null) { diff --git a/src/FileReader/PathResolver/PathResolver.php b/src/FileReader/PathResolver/PathResolver.php index d2dfa07..91f0da5 100644 --- a/src/FileReader/PathResolver/PathResolver.php +++ b/src/FileReader/PathResolver/PathResolver.php @@ -9,15 +9,9 @@ final class PathResolver implements PathResolverInterface { - /** - * @var string - */ - private $originalPath; + private string $originalPath; - /** - * @var FormatterInterface|null - */ - private $formatter; + private ?FormatterInterface $formatter; public function __construct(string $originalPath, FormatterInterface $formatter = null) { diff --git a/src/Formatter/CharReplaceFormatter.php b/src/Formatter/CharReplaceFormatter.php index 1d35065..b51d746 100644 --- a/src/Formatter/CharReplaceFormatter.php +++ b/src/Formatter/CharReplaceFormatter.php @@ -8,15 +8,9 @@ final class CharReplaceFormatter implements FormatterInterface { - /** - * @var string - */ - private $search; + private string $search; - /** - * @var string - */ - private $replace; + private string $replace; public function __construct(string $search, string $replace) { diff --git a/src/Formatter/FormatterPipeline.php b/src/Formatter/FormatterPipeline.php index 8069fd0..468934f 100644 --- a/src/Formatter/FormatterPipeline.php +++ b/src/Formatter/FormatterPipeline.php @@ -11,7 +11,7 @@ final class FormatterPipeline implements FormatterInterface /** * @var FormatterInterface[] */ - private $formatters; + private array $formatters; public function __construct(array $formatters) { diff --git a/src/Formatter/PrefixAppendFormatter.php b/src/Formatter/PrefixAppendFormatter.php index 125339c..a250332 100644 --- a/src/Formatter/PrefixAppendFormatter.php +++ b/src/Formatter/PrefixAppendFormatter.php @@ -9,10 +9,7 @@ final class PrefixAppendFormatter implements FormatterInterface { - /** - * @var string $delimiter - */ - private $delimiter; + private string $delimiter; public function __construct(string $delimiter = '') { @@ -20,10 +17,7 @@ public function __construct(string $delimiter = '') } /** - * @param string $originalName - * @param HostId $hostId * @throws FormatterException - * @return string */ public function formatName(string $originalName, HostId $hostId): string { diff --git a/src/Formatter/SuffixAppendFormatter.php b/src/Formatter/SuffixAppendFormatter.php index 93039e1..4f52ebb 100644 --- a/src/Formatter/SuffixAppendFormatter.php +++ b/src/Formatter/SuffixAppendFormatter.php @@ -9,10 +9,7 @@ final class SuffixAppendFormatter implements FormatterInterface { - /** - * @var string $delimiter - */ - private $delimiter; + private string $delimiter; public function __construct(string $delimiter = '') { @@ -20,10 +17,7 @@ public function __construct(string $delimiter = '') } /** - * @param string $originalName - * @param HostId $hostId * @throws FormatterException - * @return string */ public function formatName(string $originalName, HostId $hostId): string { diff --git a/src/HostDetector/CliArgsBasedHostDetector.php b/src/HostDetector/CliArgsBasedHostDetector.php index 40037c8..0e2cd92 100644 --- a/src/HostDetector/CliArgsBasedHostDetector.php +++ b/src/HostDetector/CliArgsBasedHostDetector.php @@ -10,24 +10,13 @@ final class CliArgsBasedHostDetector implements HostDetectorInterface { - /** - * @var string $needle - */ - private $needle; + private string $needle; - /** - * @var GetOpt $getOptAdapter - */ - private $getOptAdapter; + private GetOpt $getOptAdapter; - /** - * @var bool $isCliArgumentsParsed - */ - private $isCliArgumentsParsed = false; + private bool $isCliArgumentsParsed = false; /** - * @param string $needle - * @param GetOpt $getOptAdapter * @throws HostDetectorException */ public function __construct(string $needle, GetOpt $getOptAdapter) @@ -46,15 +35,13 @@ public function getCurrentHost(): HostId $this->isCliArgumentsParsed = true; } - $hostId = (string)$this->getOptAdapter->getOption($this->needle); + $hostId = (string) $this->getOptAdapter->getOption($this->needle); $hostId = trim($hostId, '='); return new HostId($hostId); } /** - * @param string $needle - * @param GetOpt $getOptAdapter * @throws HostDetectorException */ private function validateInitialParams(string $needle, GetOpt $getOptAdapter): void @@ -63,7 +50,7 @@ private function validateInitialParams(string $needle, GetOpt $getOptAdapter): v throw HostDetectorException::becauseEmptyNeedlePassed(self::class); } - if ((bool)$getOptAdapter->get(GetOpt::SETTING_STRICT_OPTIONS) !== false) { + if ((bool) $getOptAdapter->get(GetOpt::SETTING_STRICT_OPTIONS) !== false) { throw HostDetectorException::becauseGetOptAdapterConfiguredIncorrect( GetOpt::class, GetOpt::SETTING_STRICT_OPTIONS, diff --git a/src/HostDetector/FirstSuccessfulHostDetector.php b/src/HostDetector/FirstSuccessfulHostDetector.php index b212e58..37bb251 100644 --- a/src/HostDetector/FirstSuccessfulHostDetector.php +++ b/src/HostDetector/FirstSuccessfulHostDetector.php @@ -9,9 +9,9 @@ final class FirstSuccessfulHostDetector implements HostDetectorInterface { /** - * @var array|HostDetectorInterface[] $detectors + * @var array|HostDetectorInterface[] */ - private $detectors = []; + private array $detectors = []; public function __construct(array $detectors = []) { @@ -22,7 +22,7 @@ public function getCurrentHost(): HostId { foreach ($this->detectors as $detector) { $hostId = $detector->getCurrentHost(); - if ((string)$hostId !== '') { + if ((string) $hostId !== '') { return $hostId; } } diff --git a/src/HostDetector/HostIdMapper.php b/src/HostDetector/HostIdMapper.php index 2c9ef3d..6d8741c 100644 --- a/src/HostDetector/HostIdMapper.php +++ b/src/HostDetector/HostIdMapper.php @@ -8,17 +8,14 @@ final class HostIdMapper implements HostDetectorInterface { - /** - * @var HostDetectorInterface - */ - private $inner; + private HostDetectorInterface $inner; + /** * @var string[] */ - private $hostIdMap; + private array $hostIdMap; /** - * @param HostDetectorInterface $inner * @param string[] $hostIdMap */ public function __construct(HostDetectorInterface $inner, array $hostIdMap = []) @@ -30,8 +27,8 @@ public function __construct(HostDetectorInterface $inner, array $hostIdMap = []) public function getCurrentHost(): HostId { $innerHostId = $this->inner->getCurrentHost(); - $value = $this->hostIdMap[(string)$innerHostId] ?? ''; + $value = $this->hostIdMap[(string) $innerHostId] ?? ''; return new HostId($value); } -} \ No newline at end of file +} diff --git a/src/HostDetector/ServerHeadersBasedHostDetector.php b/src/HostDetector/ServerHeadersBasedHostDetector.php index aedcac9..589137a 100644 --- a/src/HostDetector/ServerHeadersBasedHostDetector.php +++ b/src/HostDetector/ServerHeadersBasedHostDetector.php @@ -9,13 +9,9 @@ final class ServerHeadersBasedHostDetector implements HostDetectorInterface { - /** - * @var string $needle - */ - private $needle; + private string $needle; /** - * @param string $needle * @throws HostDetectorException */ public function __construct(string $needle) @@ -31,7 +27,7 @@ public function __construct(string $needle) public function getCurrentHost(): HostId { - $hostId = (string)($_SERVER[$this->needle] ?? ''); + $hostId = (string) ($_SERVER[$this->needle] ?? ''); return new HostId($hostId); } diff --git a/src/Model/HostId.php b/src/Model/HostId.php index 94e5345..24d0eb4 100644 --- a/src/Model/HostId.php +++ b/src/Model/HostId.php @@ -6,10 +6,7 @@ final class HostId { - /** - * @var string $id - */ - private $id; + private string $id; public function __construct(string $id) { diff --git a/src/Strategy/FileBasedEnvResolvingStrategy.php b/src/Strategy/FileBasedEnvResolvingStrategy.php index 412bef8..79a4cbc 100644 --- a/src/Strategy/FileBasedEnvResolvingStrategy.php +++ b/src/Strategy/FileBasedEnvResolvingStrategy.php @@ -9,20 +9,11 @@ final class FileBasedEnvResolvingStrategy implements EnvResolvingStrategyInterface { - /** - * @var HostDetectorInterface - */ - private $hostDetector; - - /** - * @var EnvFileReaderInterface - */ - private $envFileReader; - - /** - * @var EnvResolvingStrategyInterface - */ - private $envResolvingStrategy; + private HostDetectorInterface $hostDetector; + + private EnvFileReaderInterface $envFileReader; + + private EnvResolvingStrategyInterface $envResolvingStrategy; public function __construct( HostDetectorInterface $hostDetector, diff --git a/src/Strategy/FirstSuccessfulEnvResolvingStrategy.php b/src/Strategy/FirstSuccessfulEnvResolvingStrategy.php index 57850ef..4bf9f4e 100644 --- a/src/Strategy/FirstSuccessfulEnvResolvingStrategy.php +++ b/src/Strategy/FirstSuccessfulEnvResolvingStrategy.php @@ -7,9 +7,9 @@ final class FirstSuccessfulEnvResolvingStrategy implements EnvResolvingStrategyInterface { /** - * @var array|EnvResolvingStrategyInterface[] $strategies + * @var array|EnvResolvingStrategyInterface[] */ - private $strategies = []; + private array $strategies = []; public function __construct(array $strategies = []) { diff --git a/src/Strategy/HostBasedEnvResolvingStrategy.php b/src/Strategy/HostBasedEnvResolvingStrategy.php index 248a21f..e28eb1e 100644 --- a/src/Strategy/HostBasedEnvResolvingStrategy.php +++ b/src/Strategy/HostBasedEnvResolvingStrategy.php @@ -10,15 +10,9 @@ final class HostBasedEnvResolvingStrategy implements EnvResolvingStrategyInterface { - /** - * @var HostDetectorInterface - */ - private $hostDetector; + private HostDetectorInterface $hostDetector; - /** - * @var FormatterInterface $envNameFormatter - */ - private $envNameFormatter; + private FormatterInterface $envNameFormatter; public function __construct(HostDetectorInterface $hostDetector, FormatterInterface $envNameFormatter) { @@ -27,15 +21,13 @@ public function __construct(HostDetectorInterface $hostDetector, FormatterInterf } /** - * @param string $envName * @throws FormatterException - * @return string */ public function getEnv(string $envName): string { $hostId = $this->hostDetector->getCurrentHost(); $envName = $this->envNameFormatter->formatName($envName, $hostId); - return (string)getenv($envName); + return (string) getenv($envName); } } diff --git a/src/Strategy/RawEnvResolvingStrategy.php b/src/Strategy/RawEnvResolvingStrategy.php index f56a026..2a26d4c 100644 --- a/src/Strategy/RawEnvResolvingStrategy.php +++ b/src/Strategy/RawEnvResolvingStrategy.php @@ -8,6 +8,6 @@ final class RawEnvResolvingStrategy implements EnvResolvingStrategyInterface { public function getEnv(string $envName): string { - return (string)getenv($envName); + return (string) getenv($envName); } } diff --git a/tests/Functional/Factory/FileBasedEnvResolvingStrategyFactoryTest.php b/tests/Functional/Factory/FileBasedEnvResolvingStrategyFactoryTest.php index 9dacc72..7b950ab 100644 --- a/tests/Functional/Factory/FileBasedEnvResolvingStrategyFactoryTest.php +++ b/tests/Functional/Factory/FileBasedEnvResolvingStrategyFactoryTest.php @@ -12,7 +12,9 @@ class FileBasedEnvResolvingStrategyFactoryTest extends TestCase { - use TestHeadersManager, TestCliArgsManager, TestEnvFileManager; + use TestHeadersManager; + use TestCliArgsManager; + use TestEnvFileManager; protected function tearDown(): void { @@ -22,12 +24,6 @@ protected function tearDown(): void } /** - * @param string $envToSearch - * @param string $expected - * @param array $testHeaders - * @param array $testCliArgs - * @param array $testEnvs - * @param array $builderConfig * @dataProvider createStrategyDataProvider */ public function testCreateStrategy( @@ -62,22 +58,22 @@ public function createStrategyDataProvider(): array ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'wrong_host' - ] + 'value' => 'wrong_host', + ], ], 'testEnvs' => [ 'relativePathToFile' => 'correct_id', 'fileName' => '.env', 'envs' => [ 'TEST_ENV' => 'some_value', - 'ANOTHER_ENV' => 'incorrect' + 'ANOTHER_ENV' => 'incorrect', ], ], 'builderConfig' => [ 'header' => 'HTTP_X_HOST_ID', 'cliArg' => 'host_id', 'envFile' => '.env', - 'filePath' => $this->getBasePathToDataFolder() + 'filePath' => $this->getBasePathToDataFolder(), ], ], 'commonEnvFileNotInRootFoundByCliArg' => [ @@ -86,8 +82,8 @@ public function createStrategyDataProvider(): array 'headers' => [], 'cliArgs' => [ 'host_id' => [ - 'value' => 'correct_host_id' - ] + 'value' => 'correct_host_id', + ], ], 'testEnvs' => [ 'relativePathToFile' => 'correct_host_id', @@ -95,14 +91,14 @@ public function createStrategyDataProvider(): array 'envs' => [ 'TEST_ENV' => 'incorrect', 'WRONG_ENV' => 'some_value', - 'RANDOM_ENV' => 'correct' + 'RANDOM_ENV' => 'correct', ], ], 'builderConfig' => [ 'header' => 'HTTP_X_HOST_ID', 'cliArg' => 'host_id', 'envFile' => '.env', - 'filePath' => $this->getBasePathToDataFolder() + 'filePath' => $this->getBasePathToDataFolder(), ], ], ]; diff --git a/tests/Functional/Factory/HostBasedEnvResolvingStrategyFactoryTest.php b/tests/Functional/Factory/HostBasedEnvResolvingStrategyFactoryTest.php index 4f6fa96..b47a041 100644 --- a/tests/Functional/Factory/HostBasedEnvResolvingStrategyFactoryTest.php +++ b/tests/Functional/Factory/HostBasedEnvResolvingStrategyFactoryTest.php @@ -12,7 +12,9 @@ class HostBasedEnvResolvingStrategyFactoryTest extends TestCase { - use TestHeadersManager, TestCliArgsManager, TestEnvManager; + use TestHeadersManager; + use TestCliArgsManager; + use TestEnvManager; protected function tearDown(): void { @@ -22,12 +24,6 @@ protected function tearDown(): void } /** - * @param string $envToSearch - * @param string $expected - * @param array $testHeaders - * @param array $testCliArgs - * @param array $testEnvs - * @param array $builderConfig * @dataProvider createStrategyDataProvider */ public function testCreateStrategy( @@ -58,48 +54,48 @@ public function createStrategyDataProvider(): array 'expected' => 'correct', 'headers' => [ 'HTTP_X_HOST_ID' => 'test_id', - 'HOST_ID' => 'moscow' + 'HOST_ID' => 'moscow', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'wrong_id' - ] + 'value' => 'wrong_id', + ], ], 'envs' => [ 'DB_HOST' => 'wrong', 'test_id___DB_HOST' => 'correct', - 'wrong_id___DB_HOST' => 'wrong' + 'wrong_id___DB_HOST' => 'wrong', ], 'builderConfig' => [ 'header' => 'HTTP_X_HOST_ID', 'cliArg' => 'host_id', - 'delimiter' => '___' - ] + 'delimiter' => '___', + ], ], 'foundByCli' => [ 'envToSearch' => 'DB_HOST', 'expected' => 'correct', 'headers' => [ 'TEST_ID' => 'test_id', - 'HOST_ID' => 'moscow' + 'HOST_ID' => 'moscow', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'correct_id' - ] + 'value' => 'correct_id', + ], ], 'envs' => [ 'DB_HOST' => 'wrong', 'test_id___DB_HOST' => 'wrong', 'wrong_id___DB_HOST' => 'wrong', - 'correct_id___DB_HOST' => 'correct' + 'correct_id___DB_HOST' => 'correct', ], 'builderConfig' => [ 'header' => 'HTTP_X_HOST_ID', 'cliArg' => 'host_id', - 'delimiter' => '___' - ] - ] + 'delimiter' => '___', + ], + ], ]; } } diff --git a/tests/Functional/FileReader/DotEnvV2FileReaderAdapterTest.php b/tests/Functional/FileReader/DotEnvV2FileReaderAdapterTest.php index 76c6328..14cd2f5 100644 --- a/tests/Functional/FileReader/DotEnvV2FileReaderAdapterTest.php +++ b/tests/Functional/FileReader/DotEnvV2FileReaderAdapterTest.php @@ -26,14 +26,6 @@ protected function tearDown(): void } /** - * @param string $relativePathToFile - * @param string $fileName - * @param PathResolver $pathResolver - * @param FileNameResolver $fileNameResolver - * @param HostId $hostId - * @param array $envsToWrite - * @param string $envToSearch - * @param string $expectedValue * @dataProvider readEnvFileDataProvider */ public function testReadEnvFileHappyPath( @@ -65,7 +57,7 @@ public function readEnvFileDataProvider(): array 'hostId' => new HostId('some_host'), 'envsToWrite' => [ 'TEST_ENV' => 'some_value', - 'ANOTHER_TEST_ENV' => 'another_value' + 'ANOTHER_TEST_ENV' => 'another_value', ], 'envToSearch' => 'TEST_ENV', 'expected' => 'some_value', @@ -76,16 +68,16 @@ public function readEnvFileDataProvider(): array 'pathResolver' => new PathResolver($this->getBasePathToDataFolder()), 'fileNameResolver' => new FileNameResolver(FileNameResolver::DEFAULT_FILE_NAME, new FormatterPipeline([ new PrefixAppendFormatter('.'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ])), 'hostId' => new HostId('some_value'), 'envsToWrite' => [ 'TEST_ENV' => 'different_value', 'TEST_ENV1' => 'wrong', - 'TEST_ENV2' => 'another_wrong' + 'TEST_ENV2' => 'another_wrong', ], 'envToSearch' => 'TEST_ENV', - 'expected' => 'different_value' + 'expected' => 'different_value', ], 'fileInRootWithSuffix' => [ 'relativePathToFile' => '', @@ -93,15 +85,15 @@ public function readEnvFileDataProvider(): array 'pathResolver' => new PathResolver($this->getBasePathToDataFolder()), 'fileNameResolver' => new FileNameResolver(FileNameResolver::DEFAULT_FILE_NAME, new FormatterPipeline([ new SuffixAppendFormatter('-'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ])), 'hostId' => new HostId('some-host'), 'envsToWrite' => [ 'ENV_TO_SEARCH' => 'some_value', - 'WRONG_ENV' => 'wrong' + 'WRONG_ENV' => 'wrong', ], 'envToSearch' => 'ENV_TO_SEARCH', - 'expected' => 'some_value' + 'expected' => 'some_value', ], 'defaultFileNotInRoot' => [ 'relativePathToFile' => 'test_host', @@ -111,10 +103,10 @@ public function readEnvFileDataProvider(): array 'hostId' => new HostId('test_host'), 'envToWrite' => [ 'SOME_ENV' => 'correct_value', - 'INCORRECT_ENV' => 'incorrect_value' + 'INCORRECT_ENV' => 'incorrect_value', ], 'envToSearch' => 'SOME_ENV', - 'expected' => 'correct_value' + 'expected' => 'correct_value', ], 'notDefaultFileNotInRoot' => [ 'relativePathToFile' => 'test-id', @@ -122,24 +114,20 @@ public function readEnvFileDataProvider(): array 'pathResolve' => new PathResolver($this->getBasePathToDataFolder(), new SuffixAppendFormatter(DIRECTORY_SEPARATOR)), 'fileNameResolver' => new FileNameResolver('env', new FormatterPipeline([ new PrefixAppendFormatter('-'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ])), 'hostId' => new HostId('test-id'), 'entToWrite' => [ 'SOME_ENV' => 'totally_correct_value', - 'TEST_ENV' => 'test_value' + 'TEST_ENV' => 'test_value', ], 'envToSearch' => 'SOME_ENV', - 'expected' => 'totally_correct_value' - ] + 'expected' => 'totally_correct_value', + ], ]; } /** - * @param string $envToSearch - * @param string $expected - * @param array $startEnv - * @param array $finalEnv * @dataProvider readFileOnlyOnceDataProvider */ public function testThatAdapterReadFileOnlyOnce( @@ -171,24 +159,17 @@ public function readFileOnlyOnceDataProvider(): array 'expected' => 'correct_value', 'startEnvs' => [ 'TEST_ENV' => 'correct_value', - 'ANOTHER_ENV' => 'test_value' + 'ANOTHER_ENV' => 'test_value', ], 'endEnvs' => [ 'TEST_ENV' => 'incorrect_value', - 'ANOTHER_ENV' => 'some_value' - ] - ] + 'ANOTHER_ENV' => 'some_value', + ], + ], ]; } /** - * @param string $relativePathToFile - * @param string $fileName - * @param PathResolver $pathResolver - * @param FileNameResolver $fileNameResolver - * @param HostId $hostId - * @param array $envToWrite - * @param \Throwable $expected * @dataProvider exceptionRaisedDataProvider */ public function testExceptionRaisedWhenFileCantBeLoad( @@ -218,14 +199,14 @@ public function exceptionRaisedDataProvider(): array 'pathResolver' => new PathResolver($this->getBasePathToDataFolder(), new SuffixAppendFormatter(DIRECTORY_SEPARATOR)), 'fileNameResolver' => new FileNameResolver(FileNameResolver::DEFAULT_FILE_NAME, new FormatterPipeline([ new SuffixAppendFormatter('-'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ])), 'hostId' => new HostId('test'), 'envToWrite' => [ - 'TEST_ENV' => 'some_value' + 'TEST_ENV' => 'some_value', ], - 'expected' => EnvFileReaderException::becauseEnvFileCanNotBeProcessed(null) - ] + 'expected' => EnvFileReaderException::becauseEnvFileCanNotBeProcessed(null), + ], ]; } } diff --git a/tests/Functional/FileReader/FileNameResolver/FileNameResolverTest.php b/tests/Functional/FileReader/FileNameResolver/FileNameResolverTest.php index ed89dbc..10dd89d 100644 --- a/tests/Functional/FileReader/FileNameResolver/FileNameResolverTest.php +++ b/tests/Functional/FileReader/FileNameResolver/FileNameResolverTest.php @@ -16,10 +16,6 @@ class FileNameResolverTest extends TestCase { /** - * @param string $originalFileName - * @param FormatterInterface|null $formatter - * @param HostId $hostId - * @param string $expected * @dataProvider fileNameResolveDataProvider */ public function testFileNameResolve( @@ -39,70 +35,70 @@ public function fileNameResolveDataProvider(): array 'originalName' => '', 'formatter' => null, 'hostId' => new HostId(''), - 'expected' => '.env' + 'expected' => '.env', ], 'notEmptyOriginalName' => [ 'originalName' => '.some_not_default_file_name.env', 'formatter' => null, 'hostId' => new HostId(''), - 'expected' => '.some_not_default_file_name.env' + 'expected' => '.some_not_default_file_name.env', ], 'notEmptyOriginalNameWithoutDot' => [ 'originalName' => 'another_file_name.env', 'formatter' => null, 'hostId' => new HostId(''), - 'expected' => 'another_file_name.env' + 'expected' => 'another_file_name.env', ], 'emptyFormatterOnly' => [ 'originalName' => '.test_file', 'formatter' => null, 'hostId' => new HostId('test_host'), - 'expected' => '.test_file' + 'expected' => '.test_file', ], 'prefixFormatter' => [ 'originalName' => '.env', 'formatter' => new PrefixAppendFormatter('.'), 'hostId' => new HostId('test_host'), - 'expected' => '.test_host.env' + 'expected' => '.test_host.env', ], 'prefixFormatterWithoutDot' => [ 'originalName' => 'some-name', 'formatter' => new PrefixAppendFormatter('-'), 'hostId' => new HostId('some-host'), - 'expected' => 'some-host-some-name' + 'expected' => 'some-host-some-name', ], 'prefixFormatterWithoutDotAndDelimiter' => [ 'originalName' => 'env', 'formatter' => new PrefixAppendFormatter(''), 'hostId' => new HostId('test'), - 'expected' => 'testenv' + 'expected' => 'testenv', ], 'suffixFormatter' => [ 'originalName' => '.env', 'formatter' => new SuffixAppendFormatter('-'), 'hostId' => new HostId('test_name'), - 'expected' => '.env-test_name' + 'expected' => '.env-test_name', ], 'suffixFormatterWithoutDot' => [ 'originalName' => 'test-env-file', 'formatter' => new SuffixAppendFormatter('_'), 'hostId' => new HostId('some_host'), - 'expected' => 'test-env-file_some_host' + 'expected' => 'test-env-file_some_host', ], 'suffixFormatterWithoutDotAndDelimiter' => [ 'originalName' => 'env', 'formatter' => new SuffixAppendFormatter(''), 'hostId' => new HostId('env'), - 'expected' => 'envenv' + 'expected' => 'envenv', ], 'formatterPipeline' => [ 'originalName' => 'test-file', 'formatter' => new FormatterPipeline([ new SuffixAppendFormatter('-'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]), 'hostId' => new HostId('env'), - 'expected' => 'test_file_env' + 'expected' => 'test_file_env', ], 'anotherFormatterPipeline' => [ 'originalName' => '.env', @@ -110,11 +106,11 @@ public function fileNameResolveDataProvider(): array new SuffixAppendFormatter('-'), new PrefixAppendFormatter('||'), new CharReplaceFormatter('|', '_'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]), 'hostId' => new HostId('test'), - 'expected' => '.test__env_test' - ] + 'expected' => '.test__env_test', + ], ]; } } diff --git a/tests/Functional/FileReader/PathResolver/PathResolverTest.php b/tests/Functional/FileReader/PathResolver/PathResolverTest.php index fadc2ea..bb76ad5 100644 --- a/tests/Functional/FileReader/PathResolver/PathResolverTest.php +++ b/tests/Functional/FileReader/PathResolver/PathResolverTest.php @@ -16,10 +16,6 @@ class PathResolverTest extends TestCase { /** - * @param string $originalPath - * @param FormatterInterface|null $formatter - * @param HostId $hostId - * @param string $expected * @dataProvider pathResolveDataProvider */ public function testPathResolve( @@ -39,51 +35,51 @@ public function pathResolveDataProvider(): array 'originalPath' => '', 'formatter' => null, 'hostId' => new HostId(''), - 'expected' => '' + 'expected' => '', ], 'notEmptyOriginalPath' => [ 'originalPath' => '/var/config', 'formatter' => null, 'hostId' => new HostId(''), - 'expected' => '/var/config' + 'expected' => '/var/config', ], 'onlyFormatterEmpty' => [ 'originalPath' => '/var/test/env', 'formatter' => null, 'hostId' => new HostId('some_element'), - 'expected' => '/var/test/env' + 'expected' => '/var/test/env', ], 'prefixFormatter' => [ 'originalPath' => '/bin/console', 'formatter' => new PrefixAppendFormatter(DIRECTORY_SEPARATOR), 'hostId' => new HostId('test-element'), - 'expected' => 'test-element' . DIRECTORY_SEPARATOR . '/bin/console' + 'expected' => 'test-element' . DIRECTORY_SEPARATOR . '/bin/console', ], 'suffixFormatter' => [ 'originalPath' => '/test/some-folder', 'formatter' => new SuffixAppendFormatter(DIRECTORY_SEPARATOR), 'hostId' => new HostId('test-instance'), - 'expected' => '/test/some-folder' . DIRECTORY_SEPARATOR . 'test-instance' + 'expected' => '/test/some-folder' . DIRECTORY_SEPARATOR . 'test-instance', ], 'formatterPipeline' => [ 'originalPath' => '/root/another-folder', 'formatter' => new FormatterPipeline([ new SuffixAppendFormatter(DIRECTORY_SEPARATOR), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]), 'hostId' => new HostId('test-folder'), - 'expected' => '/root/another_folder' . DIRECTORY_SEPARATOR . 'test_folder' + 'expected' => '/root/another_folder' . DIRECTORY_SEPARATOR . 'test_folder', ], 'anotherFormatterPipeline' => [ 'originalPath' => '/test/env', 'formatter' => new FormatterPipeline([ new PrefixAppendFormatter(DIRECTORY_SEPARATOR), new SuffixAppendFormatter('---'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]), 'hostId' => new HostId('some-folder'), - 'expected' => 'some_folder' . DIRECTORY_SEPARATOR . '/test/env___some_folder' - ] + 'expected' => 'some_folder' . DIRECTORY_SEPARATOR . '/test/env___some_folder', + ], ]; } } diff --git a/tests/Functional/HostDetector/FirstSuccessfulHostDetectorTest.php b/tests/Functional/HostDetector/FirstSuccessfulHostDetectorTest.php index c08435c..1eee865 100644 --- a/tests/Functional/HostDetector/FirstSuccessfulHostDetectorTest.php +++ b/tests/Functional/HostDetector/FirstSuccessfulHostDetectorTest.php @@ -16,7 +16,8 @@ class FirstSuccessfulHostDetectorTest extends TestCase { - use TestHeadersManager, TestCliArgsManager; + use TestHeadersManager; + use TestCliArgsManager; protected function tearDown(): void { @@ -26,10 +27,6 @@ protected function tearDown(): void } /** - * @param array $hostDetectors - * @param HostId $expected - * @param array $headers - * @param array $cliArgs * @dataProvider getCurrentHostDataProvider */ public function testGetCurrentHost(array $hostDetectors, HostId $expected, array $headers, array $cliArgs): void @@ -42,7 +39,6 @@ public function testGetCurrentHost(array $hostDetectors, HostId $expected, array /** * @throws HostDetectorException - * @return array */ public function getCurrentHostDataProvider(): array { @@ -51,142 +47,142 @@ public function getCurrentHostDataProvider(): array 'detectors' => [], 'expected' => new HostId(''), 'headers' => [], - 'cliArgs' => [] + 'cliArgs' => [], ], 'emptyHeaderAndCliArgs' => [ 'detectors' => [ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ], 'expected' => new HostId(''), 'headers' => [], - 'cliArgs' => [] + 'cliArgs' => [], ], 'headersOnlySet' => [ 'detectors' => [ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ], 'expected' => new HostId('host_id_from_header'), 'headers' => [ 'HTTP_X_TEST_TEST' => 'some_value', 'HTTP_X_HOST_ID' => 'host_id_from_header', - 'X_HOST_ID' => 'wrong_host_id' + 'X_HOST_ID' => 'wrong_host_id', ], - 'cliArgs' => [] + 'cliArgs' => [], ], 'headersOnlySetAndHaveZeroValue' => [ 'detectors' => [ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ], 'expected' => new HostId('0'), 'headers' => [ 'HTTP_X_TEST_TEST' => 'some_value', 'HTTP_X_HOST_ID' => '0', - 'X_HOST_ID' => 'wrong_host_id' + 'X_HOST_ID' => 'wrong_host_id', ], - 'cliArgs' => [] + 'cliArgs' => [], ], 'headersOnlySetAnotherOrderOfDetectors' => [ 'detectors' => [ new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), - new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID') + new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), ], 'expected' => new HostId('host_id_from_header'), 'headers' => [ 'X_TEST_HEADER' => 'test', 'HTTP_X_HOST_ID' => 'host_id_from_header', - 'ANOTHER_HEADER' => 'test1' + 'ANOTHER_HEADER' => 'test1', ], - 'cliArgs' => [] + 'cliArgs' => [], ], 'cliOnlySet' => [ 'detectors' => [ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ], 'expected' => new HostId('host_id_from_cli'), 'headers' => [], 'cliArgs' => [ 'a' => [ 'useKeyValueSeparator' => false, - 'value' => 'test' + 'value' => 'test', ], 'bb' => [ 'useKeyValueSeparator' => true, - 'value' => 'someValue' + 'value' => 'someValue', ], 'host_id' => [ 'useKeyValueSeparator' => true, - 'value' => 'host_id_from_cli' - ] - ] + 'value' => 'host_id_from_cli', + ], + ], ], 'cliOrderSetAnotherOrderOfDetectors' => [ 'detectors' => [ new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), - new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID') + new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), ], 'expected' => new HostId('host_id_from_cli'), 'headers' => [], 'cliArgs' => [ 'test' => [ 'useKeyValueSeparator' => true, - 'value' => 'test_value' + 'value' => 'test_value', ], 'host_id' => [ 'useKeyValueSeparator' => false, - 'value' => 'host_id_from_cli' + 'value' => 'host_id_from_cli', ], 'another_test' => [ 'useKeyValueSeparator' => true, - 'value' => 'test-test' - ] - ] + 'value' => 'test-test', + ], + ], ], 'headersAndCliArgsSetHeaderBasedDetectorComeFirst' => [ 'detectors' => [ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ], 'expected' => new HostId('host_id_from_header'), 'headers' => [ 'HTTP_X_HOST_ID' => 'host_id_from_header', - 'X_TEST_HEADER' => 'test-value' + 'X_TEST_HEADER' => 'test-value', ], 'cliArgs' => [ 'host_id' => [ 'useKeyValueSeparator' => true, - 'value' => 'host_id_from_cli' + 'value' => 'host_id_from_cli', ], 'test' => [ 'useKeyValueSeparator' => false, - 'value' => 'test-cli-value' - ] - ] + 'value' => 'test-cli-value', + ], + ], ], 'headersAndCliArgsSetCliArgsBasedDetectorComeFirst' => [ 'detectors' => [ new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), - new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID') + new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), ], 'expected' => new HostId('host_id_from_cli'), 'headers' => [ 'HTTP_X_HOST_ID' => 'host_id_from_header', - 'X_TEST_HEADER' => 'test-value' + 'X_TEST_HEADER' => 'test-value', ], 'cliArgs' => [ 'host_id' => [ 'useKeyValueSeparator' => true, - 'value' => 'host_id_from_cli' + 'value' => 'host_id_from_cli', ], 'test' => [ 'useKeyValueSeparator' => false, - 'value' => 'test-cli-value' - ] - ] - ] + 'value' => 'test-cli-value', + ], + ], + ], ]; } } diff --git a/tests/Functional/Strategy/FileBasedEnvResolvingStrategyTest.php b/tests/Functional/Strategy/FileBasedEnvResolvingStrategyTest.php index 1153927..dfa2c36 100644 --- a/tests/Functional/Strategy/FileBasedEnvResolvingStrategyTest.php +++ b/tests/Functional/Strategy/FileBasedEnvResolvingStrategyTest.php @@ -27,7 +27,9 @@ final class FileBasedEnvResolvingStrategyTest extends TestCase { - use TestHeadersManager, TestCliArgsManager, TestEnvFileManager; + use TestHeadersManager; + use TestCliArgsManager; + use TestEnvFileManager; protected function tearDown(): void { @@ -37,14 +39,6 @@ protected function tearDown(): void } /** - * @param string $envToSearch - * @param string $expected - * @param array $testHeaders - * @param array $testCliArgs - * @param array $testEnvs - * @param HostDetectorInterface $hostDetector - * @param EnvFileReaderInterface $envFileReader - * @param EnvResolvingStrategyInterface $envResolvingStrategy * @dataProvider envResolvingDataProvider */ public function testEnvResolvingByStrategy( @@ -72,27 +66,27 @@ public function envResolvingDataProvider(): array 'envToSearch' => 'TEST_ENV', 'expected' => 'correct_value', 'headers' => [ - 'HTTP_X_HOST_ID' => 'test_host' + 'HTTP_X_HOST_ID' => 'test_host', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'some_other_host' - ] + 'value' => 'some_other_host', + ], ], 'testEnvs' => [ 'relativePathToFile' => '', 'fileName' => '.env', 'envs' => [ 'TEST_ENV' => 'correct_value', - 'WRONG_ENV' => 'wrong' - ] + 'WRONG_ENV' => 'wrong', + ], ], 'hostDetector' => new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), 'fileReader' => new DotEnvV2FileReaderAdapter( new PathResolver($this->getBasePathToDataFolder()), new FileNameResolver() ), - 'strategy' => new RawEnvResolvingStrategy() + 'strategy' => new RawEnvResolvingStrategy(), ], 'commonEnvFileNotInRootFoundByHeader' => [ 'envToSearch' => 'TEST_ENV', @@ -102,15 +96,15 @@ public function envResolvingDataProvider(): array ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'wrong_host' - ] + 'value' => 'wrong_host', + ], ], 'testEnvs' => [ 'relativePathToFile' => 'correct_id', 'fileName' => '.env', 'envs' => [ 'TEST_ENV' => 'some_value', - 'ANOTHER_ENV' => 'incorrect' + 'ANOTHER_ENV' => 'incorrect', ], ], 'hostDetector' => new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), @@ -118,18 +112,18 @@ public function envResolvingDataProvider(): array new PathResolver($this->getBasePathToDataFolder(), new SuffixAppendFormatter(DIRECTORY_SEPARATOR)), new FileNameResolver() ), - 'strategy' => new RawEnvResolvingStrategy() + 'strategy' => new RawEnvResolvingStrategy(), ], 'commonEnvFileNotInRootFoundByCliArg' => [ 'envToSearch' => 'RANDOM_ENV', 'expected' => 'correct', 'headers' => [ - 'HTTP_X_HOST_ID' => 'incorrect_id' + 'HTTP_X_HOST_ID' => 'incorrect_id', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'correct_host_id' - ] + 'value' => 'correct_host_id', + ], ], 'testEnvs' => [ 'relativePathToFile' => 'correct_host_id', @@ -137,7 +131,7 @@ public function envResolvingDataProvider(): array 'envs' => [ 'TEST_ENV' => 'incorrect', 'WRONG_ENV' => 'some_value', - 'RANDOM_ENV' => 'correct' + 'RANDOM_ENV' => 'correct', ], ], 'hostDetector' => new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), @@ -145,7 +139,7 @@ public function envResolvingDataProvider(): array new PathResolver($this->getBasePathToDataFolder(), new SuffixAppendFormatter(DIRECTORY_SEPARATOR)), new FileNameResolver() ), - 'strategy' => new RawEnvResolvingStrategy() + 'strategy' => new RawEnvResolvingStrategy(), ], 'uncommonEnvFileInRootFoundByHeader' => [ 'envToSearch' => 'TEST_ENV', @@ -155,14 +149,14 @@ public function envResolvingDataProvider(): array ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'incorrect_instance_id' - ] + 'value' => 'incorrect_instance_id', + ], ], 'testEnvs' => [ 'relativePathToFile' => '', 'fileName' => '.test_instance_id_env', 'envs' => [ - 'TEST_ENV' => 'test_env_value' + 'TEST_ENV' => 'test_env_value', ], ], 'hostDetector' => new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), @@ -170,7 +164,7 @@ public function envResolvingDataProvider(): array new PathResolver($this->getBasePathToDataFolder()), new FileNameResolver('.env', new PrefixAppendFormatter('_')) ), - 'strategy' => new RawEnvResolvingStrategy() + 'strategy' => new RawEnvResolvingStrategy(), ], 'uncommonEnvFileInRootFoundByCliArg' => [ 'envToSearch' => 'SOME_ENV', @@ -178,28 +172,28 @@ public function envResolvingDataProvider(): array 'headers' => [], 'cliArgs' => [ 'host_id' => [ - 'value' => 'instance_id' - ] + 'value' => 'instance_id', + ], ], 'testEnvs' => [ 'relativePathToFile' => '', 'fileName' => 'instance_id.env', 'envs' => [ - 'SOME_ENV' => 'test' - ] + 'SOME_ENV' => 'test', + ], ], 'hostDetector' => new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), 'fileReader' => new DotEnvV2FileReaderAdapter( new PathResolver($this->getBasePathToDataFolder()), new FileNameResolver('env', new PrefixAppendFormatter('.')) ), - 'strategy' => new RawEnvResolvingStrategy() + 'strategy' => new RawEnvResolvingStrategy(), ], 'commonEnvInRootWithEnvWithPrefixes' => [ 'envToSearch' => 'TEST_ENV', 'expected' => 'correct_value', 'headers' => [ - 'HTTP_X_HOST_ID' => 'test_instance' + 'HTTP_X_HOST_ID' => 'test_instance', ], 'cliArgs' => [], 'testEnvs' => [ @@ -207,8 +201,8 @@ public function envResolvingDataProvider(): array 'fileName' => '.env', 'envs' => [ 'test_instance___TEST_ENV' => 'correct_value', - 'TEST_ENV' => 'wrong_value' - ] + 'TEST_ENV' => 'wrong_value', + ], ], 'hostDetector' => new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), 'fileReader' => new DotEnvV2FileReaderAdapter( @@ -219,10 +213,10 @@ public function envResolvingDataProvider(): array new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), new FormatterPipeline([ new PrefixAppendFormatter('---'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]) - ) - ] + ), + ], ]; } } diff --git a/tests/Functional/Strategy/FirstSuccessfulEnvResolvingStrategyTest.php b/tests/Functional/Strategy/FirstSuccessfulEnvResolvingStrategyTest.php index b95cc2a..30084e8 100644 --- a/tests/Functional/Strategy/FirstSuccessfulEnvResolvingStrategyTest.php +++ b/tests/Functional/Strategy/FirstSuccessfulEnvResolvingStrategyTest.php @@ -5,7 +5,6 @@ namespace Lamoda\MultiEnvTests\Functional\Strategy; use Lamoda\MultiEnv\Formatter\CharReplaceFormatter; -use Lamoda\MultiEnv\Formatter\FormatterInterface; use Lamoda\MultiEnv\Formatter\FormatterPipeline; use Lamoda\MultiEnv\Formatter\PrefixAppendFormatter; use Lamoda\MultiEnv\HostDetector\CliArgsBasedHostDetector; @@ -23,9 +22,11 @@ class FirstSuccessfulEnvResolvingStrategyTest extends TestCase { - use TestHeadersManager, TestCliArgsManager, TestEnvManager; + use TestHeadersManager; + use TestCliArgsManager; + use TestEnvManager; - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->removeTestHeaders(); @@ -34,12 +35,6 @@ protected function tearDown() } /** - * @param string $envToSearch - * @param array $strategies - * @param array $testHeaders - * @param array $testCliArgs - * @param array $testEnvs - * @param string $expected * @dataProvider getEnvDataProvider */ public function testGetEnv( @@ -59,13 +54,12 @@ public function testGetEnv( /** * @throws HostDetectorException - * @return array */ public function getEnvDataProvider(): array { $formatter = new FormatterPipeline([ new PrefixAppendFormatter('-'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]); return [ @@ -73,19 +67,19 @@ public function getEnvDataProvider(): array 'env' => 'DB_HOST', 'strategies' => [], 'headers' => [ - 'HTTP_X_HOST_ID' => 'moscow' + 'HTTP_X_HOST_ID' => 'moscow', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'piter' - ] + 'value' => 'piter', + ], ], 'envs' => [ 'DB_HOST' => 'wrong', 'MOSCOW_DB_HOST' => 'wrong-wrong', - 'PITER_DB_HOST' => 'definitely_wrong' + 'PITER_DB_HOST' => 'definitely_wrong', ], - 'expected' => '' + 'expected' => '', ], 'rawStrategyGoFirstAndWork' => [ 'env' => 'DB_HOST', @@ -97,22 +91,22 @@ public function getEnvDataProvider(): array new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), $formatter - ) + ), ], 'headers' => [ - 'HTTP_X_HOST_ID' => 'moscow' + 'HTTP_X_HOST_ID' => 'moscow', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'piter' - ] + 'value' => 'piter', + ], ], 'envs' => [ 'DB_HOST' => 'correct', 'MOSCOW_DB_HOST' => 'wrong', - 'PITER_DB_HOST' => 'incorrect' + 'PITER_DB_HOST' => 'incorrect', ], - 'expected' => 'correct' + 'expected' => 'correct', ], 'rawStrategyGoFirstAndDontWork' => [ 'env' => 'DB_HOST', @@ -121,24 +115,24 @@ public function getEnvDataProvider(): array new HostBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), $formatter - ) + ), ], 'headers' => [ - 'HTTP_X_HOST_ID' => 'moscow' + 'HTTP_X_HOST_ID' => 'moscow', ], 'cliArgs' => [ 'host-id' => [ - 'value' => 'piter' - ] + 'value' => 'piter', + ], ], 'envs' => [ 'piter_DB_HOST' => 'wrong', - 'moscow_DB_HOST' => 'correct' + 'moscow_DB_HOST' => 'correct', ], - 'expected' => 'correct' + 'expected' => 'correct', ], 'hostBasedGoFirstAndWork' => [ 'env' => 'DB_HOST', @@ -146,26 +140,26 @@ public function getEnvDataProvider(): array new HostBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), $formatter ), new RawEnvResolvingStrategy(), ], 'headers' => [ - 'HTTP_X_HOST_ID' => 'MOSCOW' + 'HTTP_X_HOST_ID' => 'MOSCOW', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'PITER' - ] + 'value' => 'PITER', + ], ], 'envs' => [ 'DB_HOST' => 'incorrect', 'MOSCOW_DB_HOST' => '0', - 'PITER_DB_HOST' => 'incorrect' + 'PITER_DB_HOST' => 'incorrect', ], - 'expected' => '0' + 'expected' => '0', ], 'hostBasedGoFirstAndWorkCli' => [ 'env' => 'DB_HOST', @@ -173,26 +167,26 @@ public function getEnvDataProvider(): array new HostBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), $formatter ), new RawEnvResolvingStrategy(), ], 'headers' => [ - 'HTTP_X_HOST_ID_1' => 'MOSCOW' + 'HTTP_X_HOST_ID_1' => 'MOSCOW', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'PITER' - ] + 'value' => 'PITER', + ], ], 'envs' => [ 'DB_HOST' => 'incorrect', 'MOSCOW_DB_HOST' => 'incorrect', - 'PITER_DB_HOST' => 'correct' + 'PITER_DB_HOST' => 'correct', ], - 'expected' => 'correct' + 'expected' => 'correct', ], 'hostBasedGoFirstAndDontWork' => [ 'env' => 'DB_HOST', @@ -200,22 +194,22 @@ public function getEnvDataProvider(): array new HostBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'), - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), $formatter ), new RawEnvResolvingStrategy(), ], 'headers' => [ - 'HTTP_X_HOST_ID' => 'moscow' + 'HTTP_X_HOST_ID' => 'moscow', ], 'cliArgs' => [], 'envs' => [ 'DB_HOST' => 'correct', - 'PITER_DB_HOST' => 'incorrect' + 'PITER_DB_HOST' => 'incorrect', ], - 'expected' => 'correct' - ] + 'expected' => 'correct', + ], ]; } } diff --git a/tests/Functional/Strategy/HostBasedEnvResolvingStrategyTest.php b/tests/Functional/Strategy/HostBasedEnvResolvingStrategyTest.php index 5b6f1e4..494db01 100644 --- a/tests/Functional/Strategy/HostBasedEnvResolvingStrategyTest.php +++ b/tests/Functional/Strategy/HostBasedEnvResolvingStrategyTest.php @@ -23,7 +23,9 @@ class HostBasedEnvResolvingStrategyTest extends TestCase { - use TestHeadersManager, TestCliArgsManager, TestEnvManager; + use TestHeadersManager; + use TestCliArgsManager; + use TestEnvManager; public function tearDown(): void { @@ -34,13 +36,6 @@ public function tearDown(): void } /** - * @param string $env - * @param HostDetectorInterface $hostDetector - * @param FormatterInterface $nameFormatter - * @param array $testHeaders - * @param array $testCliArgs - * @param array $testEnvs - * @param string $expected * @dataProvider getEnvDataProvider */ public function testGetEnv( @@ -61,13 +56,12 @@ public function testGetEnv( /** * @throws HostDetectorException - * @return array */ public function getEnvDataProvider(): array { $nameFormatter = new FormatterPipeline([ new PrefixAppendFormatter('-'), - new CharReplaceFormatter('-', '_') + new CharReplaceFormatter('-', '_'), ]); $headerBasedDetector = new ServerHeadersBasedHostDetector('HTTP_X_HOST_ID'); @@ -79,7 +73,7 @@ public function getEnvDataProvider(): array 'headers' => [], 'cliArgs' => [], 'envs' => [], - 'expected' => '' + 'expected' => '', ], 'getEnvBasedOnHeadersHeaderNotExistEnvExist' => [ 'env' => 'DB_HOST', @@ -89,9 +83,9 @@ public function getEnvDataProvider(): array 'cliArgs' => [], 'envs' => [ 'DB_HOST' => 'correct_value', - 'moscow2_DB_HOST' => 'incorrect_value' + 'moscow2_DB_HOST' => 'incorrect_value', ], - 'expected' => '' + 'expected' => '', ], 'getEnvBasedOnHeadersHeaderExistEnvNotExist' => [ 'env' => 'DB_HOST', @@ -99,13 +93,13 @@ public function getEnvDataProvider(): array 'nameFormatter' => $nameFormatter, 'headers' => [ 'HTTP_X_HOST_ID' => 'moscow2', - 'HTTP_X_HOST' => 'wrong_id' + 'HTTP_X_HOST' => 'wrong_id', ], 'cliArgs' => [], 'envs' => [ - 'DB_HOST' => 'wrong_value' + 'DB_HOST' => 'wrong_value', ], - 'expected' => '' + 'expected' => '', ], 'getEnvBasedOnHeadersEnvExist' => [ 'env' => 'DB_HOST', @@ -113,14 +107,14 @@ public function getEnvDataProvider(): array 'nameFormatter' => $nameFormatter, 'header' => [ 'HTTP_X_HOST_ID' => 'moscow2', - 'HTTP_X_HOST' => 'wrong_host' + 'HTTP_X_HOST' => 'wrong_host', ], 'cliArgs' => [], 'envs' => [ 'moscow2_DB_HOST' => 'correct_db_host', - 'DB_HOST' => 'incorrect_db_host' + 'DB_HOST' => 'incorrect_db_host', ], - 'expected' => 'correct_db_host' + 'expected' => 'correct_db_host', ], 'getEnvBasedOnCliArgArgNotExistEnvNotExist' => [ 'env' => 'DB_HOST', @@ -129,7 +123,7 @@ public function getEnvDataProvider(): array 'headers' => [], 'cliArgs' => [], 'envs' => [], - 'expected' => '' + 'expected' => '', ], 'getEnvBasedOnCliArgsArgNotExitsEnvExist' => [ 'env' => 'DB_HOST', @@ -139,9 +133,9 @@ public function getEnvDataProvider(): array 'cliArgs' => [], 'envs' => [ 'DB_HOST' => 'correct_value', - 'moscow_DB_HOST' => 'incorrect_value' + 'moscow_DB_HOST' => 'incorrect_value', ], - 'expected' => '' + 'expected' => '', ], 'getEnvBasedOnCliArgsArgExistEnvNotExist' => [ 'env' => 'DB_HOST', @@ -150,17 +144,17 @@ public function getEnvDataProvider(): array 'headers' => [], 'cliArgs' => [ 'host_id' => [ - 'value' => 'moscow2' + 'value' => 'moscow2', ], 'test_cli_arg' => [ - 'value' => 'moscow3' - ] + 'value' => 'moscow3', + ], ], 'envs' => [ 'DB_HOST' => 'wrong_value', - 'moscow3_DB_HOST' => 'wrong_value' + 'moscow3_DB_HOST' => 'wrong_value', ], - 'expected' => '' + 'expected' => '', ], 'getEnvBasedOnCliArgsArgExistEnvExist' => [ 'env' => 'DB_HOST', @@ -169,93 +163,93 @@ public function getEnvDataProvider(): array 'headers' => [], 'cliArgs' => [ 'host_id' => [ - 'value' => 'moscow2' + 'value' => 'moscow2', ], 'host_id_test' => [ - 'value' => 'moscow3' - ] + 'value' => 'moscow3', + ], ], 'envs' => [ 'DB_HOST' => 'wrong_value', 'moscow2_DB_HOST' => 'correct_value', - 'moscow3_DB_HOST' => 'incorrect_value' + 'moscow3_DB_HOST' => 'incorrect_value', ], - 'expected' => 'correct_value' + 'expected' => 'correct_value', ], 'getEnvBasedOnHeaderHeaderExist' => [ 'env' => 'DB_HOST', 'hostDetector' => new FirstSuccessfulHostDetector([ $headerBasedDetector, - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), 'nameFormatter' => $nameFormatter, 'headers' => [ 'HTTP_X_HOST_ID' => 'kursk', - 'HOST_ID' => 'moscow' + 'HOST_ID' => 'moscow', ], 'cliArgs' => [ 'host_id' => [ 'value' => 'piter', - 'useKeyValueSeparator' => true - ] + 'useKeyValueSeparator' => true, + ], ], 'envs' => [ 'DB_HOST' => 'wrong0', 'kursk_DB_HOST' => 'correct', 'moscow_DB_HOST' => 'wrong1', - 'piter_DB_HOST' => 'wrong2' + 'piter_DB_HOST' => 'wrong2', ], - 'expected' => 'correct' + 'expected' => 'correct', ], 'getEnvBasedOnHeaderHeaderNotExist' => [ 'env' => 'DB_HOST', 'hostDetector' => new FirstSuccessfulHostDetector([ $headerBasedDetector, - new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()) + new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), ]), 'nameFormatter' => $nameFormatter, 'headers' => [ - 'HOST_ID' => 'test' + 'HOST_ID' => 'test', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'test-1' - ] + 'value' => 'test-1', + ], ], 'envs' => [ 'DB_HOST' => 'incorrect', 'test_DB_HOST' => 'wrong', - 'test_1_DB_HOST' => 'correct' + 'test_1_DB_HOST' => 'correct', ], - 'expected' => 'correct' + 'expected' => 'correct', ], 'getEnvBasedOnCliArgsArgExist' => [ 'env' => 'DB_HOST', 'hostDetector' => new FirstSuccessfulHostDetector([ new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), - $headerBasedDetector + $headerBasedDetector, ]), 'nameFormatter' => $nameFormatter, 'headers' => [ - 'HTTP_X_HOST_ID' => 'piter' + 'HTTP_X_HOST_ID' => 'piter', ], 'cliArgs' => [ 'host_id' => [ - 'value' => 'MOSCOW' - ] + 'value' => 'MOSCOW', + ], ], 'envs' => [ 'DB_HOST' => 'wrong_value', 'piter_DB_HOST' => 'incorrect_value', - 'MOSCOW_DB_HOST' => 'correct' + 'MOSCOW_DB_HOST' => 'correct', ], - 'expected' => 'correct' + 'expected' => 'correct', ], 'getEnvBasedOnCliArgsArgNotExist' => [ 'env' => 'DB_HOST', 'hostDetector' => new FirstSuccessfulHostDetector([ new CliArgsBasedHostDetector('host_id', GetOptAdapterFactory::build()), - $headerBasedDetector + $headerBasedDetector, ]), 'nameFormatter' => $nameFormatter, 'headers' => [ @@ -263,24 +257,20 @@ public function getEnvDataProvider(): array ], 'cliArgs' => [ 'host' => [ - 'value' => 'kursk' - ] + 'value' => 'kursk', + ], ], 'envs' => [ 'DB_HOST' => 'wrong', 'piter_DB_HOST' => 'correct', - 'kursk_DB_HOST' => 'incorrect' + 'kursk_DB_HOST' => 'incorrect', ], - 'expected' => 'correct' - ] + 'expected' => 'correct', + ], ]; } /** - * @param string $env - * @param HostDetectorInterface $hostDetector - * @param FormatterInterface $nameFormatter - * @param \Exception $expected * @dataProvider exceptionRaisedWhenGetEnvMethodCalled */ public function testExceptionRaisedWhenGetEnvMethodCalled( @@ -302,7 +292,7 @@ public function exceptionRaisedWhenGetEnvMethodCalled(): array 'env' => '', 'hostDetector' => new FirstSuccessfulHostDetector(), 'nameFormatter' => new PrefixAppendFormatter('-'), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], ]; } diff --git a/tests/Support/TestCliArgsManager.php b/tests/Support/TestCliArgsManager.php index 58661af..5d17f09 100644 --- a/tests/Support/TestCliArgsManager.php +++ b/tests/Support/TestCliArgsManager.php @@ -6,7 +6,7 @@ trait TestCliArgsManager { - private $testCliArgs = []; + private array $testCliArgs = []; public function addTestCliArgs(array $cliArgs): void { diff --git a/tests/Support/TestEnvFileManager.php b/tests/Support/TestEnvFileManager.php index d51a497..4351fe8 100644 --- a/tests/Support/TestEnvFileManager.php +++ b/tests/Support/TestEnvFileManager.php @@ -8,7 +8,7 @@ trait TestEnvFileManager { - private $basePathToData = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data/env'; + private string $basePathToData = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data/env'; public function createFileWithEnvs(array $envs, string $pathToDir = '', string $fileName = '.env'): void { diff --git a/tests/Support/TestEnvManager.php b/tests/Support/TestEnvManager.php index e02d737..bf57a0f 100644 --- a/tests/Support/TestEnvManager.php +++ b/tests/Support/TestEnvManager.php @@ -6,10 +6,7 @@ trait TestEnvManager { - /** - * @var array $testEnv - */ - private $testEnv = []; + private array $testEnv = []; public function addTestEnv(array $testEnvs): void { diff --git a/tests/Support/TestHeadersManager.php b/tests/Support/TestHeadersManager.php index fd3e307..373318c 100644 --- a/tests/Support/TestHeadersManager.php +++ b/tests/Support/TestHeadersManager.php @@ -6,7 +6,7 @@ trait TestHeadersManager { - private $testHeaders = []; + private array $testHeaders = []; public function addTestHeaders(array $headers): void { diff --git a/tests/Unit/Formatter/PrefixFormatterTest.php b/tests/Unit/Formatter/PrefixFormatterTest.php index 10d34ad..f3a478f 100644 --- a/tests/Unit/Formatter/PrefixFormatterTest.php +++ b/tests/Unit/Formatter/PrefixFormatterTest.php @@ -12,10 +12,6 @@ class PrefixFormatterTest extends TestCase { /** - * @param string $delimiter - * @param string $originalName - * @param HostId $hostId - * @param string $expected * @dataProvider formatEnvNameDataProvider */ public function testFormatEnvName(string $delimiter, string $originalName, HostId $hostId, string $expected): void @@ -31,64 +27,60 @@ public function formatEnvNameDataProvider(): array 'delimiter' => '', 'originalName' => 'DB_HOST', 'hostId' => new HostId(''), - 'expected' => 'DB_HOST' + 'expected' => 'DB_HOST', ], 'notEmptyOriginalNameHaveBracedSpaces' => [ 'delimiter' => '', 'originalName' => ' DB_HOST ', 'hostId' => new HostId(''), - 'expected' => 'DB_HOST' + 'expected' => 'DB_HOST', ], 'notEmptyOriginalNameHaveDashSeparator' => [ 'delimiter' => '', 'originalName' => 'DB-HOST', 'hostId' => new HostId(''), - 'expected' => 'DB-HOST' + 'expected' => 'DB-HOST', ], 'notEmptyOriginalNameAndDelimiter' => [ 'delimiter' => '__', 'originalName' => 'DB_HOST', 'hostId' => new HostId(''), - 'expected' => '__DB_HOST' + 'expected' => '__DB_HOST', ], 'notEmptyOriginalNameAndDelimiterAllHaveDashInValue' => [ 'delimiter' => '---', 'originalName' => '--DB-HOST--', 'hostId' => new HostId(''), - 'expected' => '-----DB-HOST--' + 'expected' => '-----DB-HOST--', ], 'notEmptyAll' => [ 'delimiter' => '__', 'originalName' => 'DB_HOST', 'hostId' => new HostId('TEST_HOST'), - 'expected' => 'TEST_HOST__DB_HOST' + 'expected' => 'TEST_HOST__DB_HOST', ], 'notEmptyAllDelimiterIsDash' => [ 'delimiter' => '-', 'originalName' => 'DB_HOST', 'hostId' => new HostId('TEST_HOST'), - 'expected' => 'TEST_HOST-DB_HOST' + 'expected' => 'TEST_HOST-DB_HOST', ], 'notEmptyAllHaveDash' => [ 'delimiter' => '-_-', 'originalName' => 'DB-HOST', 'hostId' => new HostId('TEST-HOST'), - 'expected' => 'TEST-HOST-_-DB-HOST' + 'expected' => 'TEST-HOST-_-DB-HOST', ], 'notEmptyAllOriginalNameAndHostIdInLowerCase' => [ 'delimiter' => '_', 'originalName' => 'db_host', 'hostId' => new HostId('test_host'), - 'expected' => 'test_host_db_host' - ] + 'expected' => 'test_host_db_host', + ], ]; } /** - * @param string $delimiter - * @param string $originalName - * @param HostId $hostId - * @param \Exception $expected * @dataProvider exceptionRaisedWhileEnvNameFormatDataProvider */ public function testExceptionRaisedWhileEnvNameFormat( @@ -110,19 +102,19 @@ public function exceptionRaisedWhileEnvNameFormatDataProvider(): array 'delimiter' => '', 'originalName' => '', 'hostId' => new HostId(''), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], 'notEmptyDelimiter' => [ 'delimiter' => '---', 'originalName' => '', 'hostId' => new HostId(''), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], 'notEmptyDelimiterAndHostId' => [ 'delimiter' => '---', 'originalName' => '', 'hostId' => new HostId('test_host'), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], ]; } diff --git a/tests/Unit/Formatter/SuffixFormatterTest.php b/tests/Unit/Formatter/SuffixFormatterTest.php index d9bc416..2ad344c 100644 --- a/tests/Unit/Formatter/SuffixFormatterTest.php +++ b/tests/Unit/Formatter/SuffixFormatterTest.php @@ -13,10 +13,6 @@ class SuffixFormatterTest extends TestCase { /** - * @param string $delimiter - * @param string $originalNam - * @param HostId $hostId - * @param string $expected * @dataProvider suffixFormattingDataProvider */ public function testSuffixFormatting(string $delimiter, string $originalNam, HostId $hostId, string $expected): void @@ -32,64 +28,60 @@ public function suffixFormattingDataProvider(): array 'delimiter' => '', 'originalName' => 'DB_HOST', 'hostId' => new HostId(''), - 'expected' => 'DB_HOST' + 'expected' => 'DB_HOST', ], 'notEmptyOriginalNameHaveBracedSpaces' => [ 'delimiter' => '', 'originalName' => ' DB_HOST ', 'hostId' => new HostId(''), - 'expected' => 'DB_HOST' + 'expected' => 'DB_HOST', ], 'notEmptyOriginalNameHaveDashSeparator' => [ 'delimiter' => '', 'originalName' => 'DB-HOST', 'hostId' => new HostId(''), - 'expected' => 'DB-HOST' + 'expected' => 'DB-HOST', ], 'notEmptyOriginalNameAndDelimiter' => [ 'delimiter' => '__', 'originalName' => 'DB_HOST', 'hostId' => new HostId(''), - 'expected' => 'DB_HOST__' + 'expected' => 'DB_HOST__', ], 'notEmptyOriginalNameAndDelimiterAllHaveDashInValue' => [ 'delimiter' => '---', 'originalName' => '--DB-HOST--', 'hostId' => new HostId(''), - 'expected' => '--DB-HOST-----' + 'expected' => '--DB-HOST-----', ], 'notEmptyAll' => [ 'delimiter' => '__', 'originalName' => 'DB_HOST', 'hostId' => new HostId('TEST_HOST'), - 'expected' => 'DB_HOST__TEST_HOST' + 'expected' => 'DB_HOST__TEST_HOST', ], 'notEmptyAllDelimiterIsDash' => [ 'delimiter' => '-', 'originalName' => 'DB_HOST', 'hostId' => new HostId('TEST_HOST'), - 'expected' => 'DB_HOST-TEST_HOST' + 'expected' => 'DB_HOST-TEST_HOST', ], 'notEmptyAllHaveDash' => [ 'delimiter' => '-_-', 'originalName' => 'DB-HOST', 'hostId' => new HostId('TEST-HOST'), - 'expected' => 'DB-HOST-_-TEST-HOST' + 'expected' => 'DB-HOST-_-TEST-HOST', ], 'notEmptyAllOriginalNameAndHostIdInLowerCase' => [ 'delimiter' => '_', 'originalName' => 'db_host', 'hostId' => new HostId('test_host'), - 'expected' => 'db_host_test_host' - ] + 'expected' => 'db_host_test_host', + ], ]; } /** - * @param string $delimiter - * @param string $originalName - * @param HostId $hostId - * @param Exception $expected * @dataProvider exceptionRaisedWhileFormatDataProvider */ public function testExceptionRaisedWhileFormat( @@ -111,19 +103,19 @@ public function exceptionRaisedWhileFormatDataProvider(): array 'delimiter' => '', 'originalName' => '', 'hostId' => new HostId(''), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], 'notEmptyDelimiter' => [ 'delimiter' => '---', 'originalName' => '', 'hostId' => new HostId(''), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], 'notEmptyDelimiterAndHostId' => [ 'delimiter' => '---', 'originalName' => '', 'hostId' => new HostId('test_host'), - 'expected' => FormatterException::becauseEmptyNamePassed() + 'expected' => FormatterException::becauseEmptyNamePassed(), ], ]; } diff --git a/tests/Unit/HostDetector/CliArgsBasedHostDetectorTest.php b/tests/Unit/HostDetector/CliArgsBasedHostDetectorTest.php index 867443e..61e66f6 100644 --- a/tests/Unit/HostDetector/CliArgsBasedHostDetectorTest.php +++ b/tests/Unit/HostDetector/CliArgsBasedHostDetectorTest.php @@ -17,10 +17,7 @@ class CliArgsBasedHostDetectorTest extends TestCase { use TestCliArgsManager; - /** - * @var GetOpt $getOptAdapter - */ - private $getOptAdapter; + private GetOpt $getOptAdapter; protected function setUp(): void { @@ -35,7 +32,6 @@ protected function tearDown(): void } /** - * @param string $needle * @dataProvider successfulCreationDataProvider */ public function testSuccessfulCreation(string $needle): void @@ -55,15 +51,13 @@ public function successfulCreationDataProvider(): array ], 'needleWithSystemSymbols' => [ 'needle' => " \t\n\n\t\0\x0B testNeedleTest \t\t\t\t\t\r\t\n\n\0\x0B", - ] + ], ]; } /** - * @param string $needle - * @param GetOpt $getOptAdapter - * @param \Exception $expectedException * @throws HostDetectorException + * * @dataProvider exceptionRaisedWhenConstructCalledWithWrongNeedle */ public function testExceptionRaisedWhenConstructCalledWithWrongNeedle( @@ -89,31 +83,29 @@ public function exceptionRaisedWhenConstructCalledWithWrongNeedle(): array 'emptyNeedle' => [ 'needle' => '', 'getOptAdapter' => new GetOpt(null, [GetOpt::SETTING_STRICT_OPTIONS => false]), - 'expectedException' => $emptyNeedleException + 'expectedException' => $emptyNeedleException, ], 'emptyNeedleWithSpaces' => [ 'needle' => ' ', 'getOptAdapter' => new GetOpt(null, [GetOpt::SETTING_STRICT_OPTIONS => false]), - 'expectedException' => $emptyNeedleException + 'expectedException' => $emptyNeedleException, ], 'emptyNeedleWithSystemChars' => [ 'needle' => "\t\n\r\n\n\n\r\t\n \n\t\r\0\x0B ", 'getOptAdapter' => new GetOpt(null, [GetOpt::SETTING_STRICT_OPTIONS => false]), - 'expectedException' => $emptyNeedleException + 'expectedException' => $emptyNeedleException, ], 'correctNeedleIncorrectGetOpt' => [ 'needle' => 'test', 'getOptAdapter' => new GetOpt(), - 'expectedException' => $incorrectGetOptAdapterParamsException - ] + 'expectedException' => $incorrectGetOptAdapterParamsException, + ], ]; } /** - * @param string $needle - * @param array $cliArgs - * @param HostId $expected * @throws HostDetectorException + * * @dataProvider getCurrentHostDataProvider */ public function testGetCurrentHost(string $needle, array $cliArgs, HostId $expected): void @@ -121,7 +113,7 @@ public function testGetCurrentHost(string $needle, array $cliArgs, HostId $expec $detector = new CliArgsBasedHostDetector($needle, $this->getOptAdapter); $this->addTestCliArgs($cliArgs); $hostId = $detector->getCurrentHost(); - $this->assertEquals((string)$expected, (string)$hostId); + $this->assertEquals((string) $expected, (string) $hostId); } public function getCurrentHostDataProvider(): array @@ -130,92 +122,92 @@ public function getCurrentHostDataProvider(): array 'emptyArgs' => [ 'needle' => 'host_id', 'cliArgs' => [], - 'expected' => new HostId('') + 'expected' => new HostId(''), ], 'notEmptySingleCliArg' => [ 'needle' => 'host_id', 'cliArgs' => [ 'host_id' => [ 'useKeyValueSeparator' => true, - 'value' => 'test-host-id' - ] + 'value' => 'test-host-id', + ], ], - 'expected' => new HostId('test-host-id') + 'expected' => new HostId('test-host-id'), ], 'noEmptyMultipleCliArgsWithSeparators' => [ 'needle' => 'a', 'cliArgs' => [ 'file' => [ 'useKeyValueSeparator' => true, - 'value' => '/temp/test_file.php' + 'value' => '/temp/test_file.php', ], 'a' => [ 'useKeyValueSeparator' => true, - 'value' => 'test-result' + 'value' => 'test-result', ], 'bbb' => [ 'useKeyValueSeparator' => true, - 'value' => 'anotherTestValue' - ] + 'value' => 'anotherTestValue', + ], ], - 'expected' => new HostId('test-result') + 'expected' => new HostId('test-result'), ], 'notEmptyMultipleCliArgsWithoutSeparators' => [ 'needle' => 'bbc', 'cliArgs' => [ 'a' => [ 'useKeyValueSeparator' => false, - 'value' => 'test' + 'value' => 'test', ], 'b' => [ 'useKeyValueSeparator' => false, - 'value' => 'test1' + 'value' => 'test1', ], 'bb' => [ 'useKeyValueSeparator' => false, - 'value' => 'test2' + 'value' => 'test2', ], 'bc' => [ 'useKeyValueSeparator' => false, - 'value' => 'test3' + 'value' => 'test3', ], 'bbc' => [ 'useKeyValueSeparator' => false, - 'value' => 'test4' + 'value' => 'test4', ], 'abbc' => [ 'useKeyValueSeparator' => false, - 'value' => 'test5' + 'value' => 'test5', ], ], - 'expected' => new HostId('test4') + 'expected' => new HostId('test4'), ], 'notEmptyMultipleCliArgsMixed' => [ 'needle' => 'abc', 'cliArgs' => [ 'a' => [ 'useKeyValueSeparator' => true, - 'value' => 'test-test' + 'value' => 'test-test', ], 'b' => [ 'useKeyValueSeparator' => false, - 'value' => 'test-test1' + 'value' => 'test-test1', ], 'ab' => [ 'useKeyValueSeparator' => false, - 'value' => 'test-test2' + 'value' => 'test-test2', ], 'bb' => [ 'useKeyValueSeparator' => true, - 'value' => 'test-test3' + 'value' => 'test-test3', ], 'abc' => [ 'useKeyValueSeparator' => true, - 'value' => 'test-test-test' + 'value' => 'test-test-test', ], ], - 'expected' => new HostId('test-test-test') - ] + 'expected' => new HostId('test-test-test'), + ], ]; } diff --git a/tests/Unit/HostDetector/HostIdMapperTest.php b/tests/Unit/HostDetector/HostIdMapperTest.php index 9ec3e4a..f2136d2 100644 --- a/tests/Unit/HostDetector/HostIdMapperTest.php +++ b/tests/Unit/HostDetector/HostIdMapperTest.php @@ -16,10 +16,7 @@ final class HostIdMapperTest extends TestCase */ private $inner; - /** - * @var HostIdMapper - */ - private $mapper; + private HostIdMapper $mapper; protected function setUp(): void { @@ -61,4 +58,4 @@ public function dataGetCurrentHost(): iterable new HostId(''), ]; } -} \ No newline at end of file +} diff --git a/tests/Unit/HostDetector/ServerHeadersBasedHostDetectorTest.php b/tests/Unit/HostDetector/ServerHeadersBasedHostDetectorTest.php index 34db9ed..4a459ca 100644 --- a/tests/Unit/HostDetector/ServerHeadersBasedHostDetectorTest.php +++ b/tests/Unit/HostDetector/ServerHeadersBasedHostDetectorTest.php @@ -21,7 +21,6 @@ protected function tearDown(): void } /** - * @param string $needle * @dataProvider successCreationDataProvider */ public function testSuccessfulCreation(string $needle): void @@ -41,14 +40,13 @@ public function successCreationDataProvider(): array ], 'needleWithWithSystemSymbols' => [ 'needle' => " \t\n\r\0\x0B test-test-test \t\n\r\0\x0B ", - ] + ], ]; } /** - * @param string $needle - * @param \Exception $expectedException * @dataProvider exceptionRaisedWhenConstructCalledWithWrongNeedle + * * @throws HostDetectorException */ public function testExceptionRaisedWhenConstructCalledWithWrongNeedle( @@ -67,24 +65,22 @@ public function exceptionRaisedWhenConstructCalledWithWrongNeedle(): array return [ 'emptyNeedle' => [ 'needle' => '', - 'expectedException' => $expectedException + 'expectedException' => $expectedException, ], 'onlySpacesInNeedle' => [ 'needle' => ' ', - 'expectedException' => $expectedException + 'expectedException' => $expectedException, ], 'differentCharacters' => [ 'needle' => "\t\n\r\0\x0B", - 'expectedException' => $expectedException - ] + 'expectedException' => $expectedException, + ], ]; } /** - * @param string $needle - * @param array $headers - * @param HostId $expectedHost * @throws HostDetectorException + * * @dataProvider getCurrentHostDataProvider */ public function testGetCurrentHost(string $needle, array $headers, HostId $expectedHost): void @@ -92,7 +88,7 @@ public function testGetCurrentHost(string $needle, array $headers, HostId $expec $detector = new ServerHeadersBasedHostDetector($needle); $this->addTestHeaders($headers); $currentHost = $detector->getCurrentHost(); - $this->assertEquals((string)$expectedHost, (string)$currentHost); + $this->assertEquals((string) $expectedHost, (string) $currentHost); } public function getCurrentHostDataProvider(): array @@ -103,26 +99,26 @@ public function getCurrentHostDataProvider(): array 'headers' => [ 'HTTP_HOST' => 'localhost', 'HTTP_X_TEST_HEADER' => 'some-value', - 'HTTP_X_HOST_ID' => 'test' + 'HTTP_X_HOST_ID' => 'test', ], - 'expectedHost' => new HostId('test') + 'expectedHost' => new HostId('test'), ], 'needleExistAnotherSet' => [ 'needle' => 'X_TEST', 'headers' => [ 'HTTP_HOST' => 'test_host', - 'X_TEST' => 'x_test' + 'X_TEST' => 'x_test', ], - 'expectedHost' => new HostId('x_test') + 'expectedHost' => new HostId('x_test'), ], 'needleNotExist' => [ 'needle' => 'TEST', 'headers' => [ 'HTTP_HOST' => 'localhost', 'HTTP_X_TEST_HEADER' => 'x-test', - 'HTTP_X_ANOTHER_TEST_HEADER' => 'x-another-test' + 'HTTP_X_ANOTHER_TEST_HEADER' => 'x-another-test', ], - 'expectedHost' => new HostId('') + 'expectedHost' => new HostId(''), ], 'needleInDifferentRegister' => [ 'needle' => 'http_x_host_id', @@ -131,22 +127,22 @@ public function getCurrentHostDataProvider(): array 'HTTP_X_TEST' => 'some-value', 'HTTP_X_HOST_ID' => 'test1', ], - 'expectedHost' => new HostId('') + 'expectedHost' => new HostId(''), ], 'needleNotMath' => [ 'needle' => 'HTTP-X-TEST', 'headers' => [ 'HTTP_HOST' => 'localhost', 'HTTP_X_TEST' => 'some_test_value', - 'HTTP_X_HOST_ID' => 'host_id' + 'HTTP_X_HOST_ID' => 'host_id', ], - 'expectedHost' => new HostId('') + 'expectedHost' => new HostId(''), ], 'emptyHeaders' => [ 'needle' => 'HTTP_X_TEST', 'headers' => [], - 'expectedHost' => new HostId('') - ] + 'expectedHost' => new HostId(''), + ], ]; } } diff --git a/tests/Unit/Model/HostIdTest.php b/tests/Unit/Model/HostIdTest.php index 9ad0f69..f12e81c 100644 --- a/tests/Unit/Model/HostIdTest.php +++ b/tests/Unit/Model/HostIdTest.php @@ -10,14 +10,12 @@ class HostIdTest extends TestCase { /** - * @param string $hostId - * @param string $expected * @dataProvider creationDataProvider */ public function testCreation(string $hostId, string $expected): void { $model = new HostId($hostId); - $this->assertEquals($expected, (string)$model); + $this->assertEquals($expected, (string) $model); } public function creationDataProvider(): array @@ -25,7 +23,7 @@ public function creationDataProvider(): array return [ 'empty' => [ 'hostId' => '', - 'expected' => '' + 'expected' => '', ], 'filledWithSpaces' => [ 'hostId' => ' ', @@ -33,16 +31,16 @@ public function creationDataProvider(): array ], 'filledWithSystemSymbols' => [ 'hostId' => "\t\n\r\0\x0B", - 'expected' => '' + 'expected' => '', ], 'filled' => [ 'hostId' => 'testValue', - 'expected' => 'testValue' + 'expected' => 'testValue', ], 'filledAnother' => [ 'hostId' => ' testValue1', - 'expected' => 'testValue1' - ] + 'expected' => 'testValue1', + ], ]; } } diff --git a/tests/Unit/Strategy/RawEnvResolvingStrategyTest.php b/tests/Unit/Strategy/RawEnvResolvingStrategyTest.php index 074551d..01acf61 100644 --- a/tests/Unit/Strategy/RawEnvResolvingStrategyTest.php +++ b/tests/Unit/Strategy/RawEnvResolvingStrategyTest.php @@ -11,10 +11,8 @@ class RawEnvResolvingStrategyTest extends TestCase { use TestEnvManager; - /** - * @var RawEnvResolvingStrategy $strategy - */ - private $strategy; + + private RawEnvResolvingStrategy $strategy; protected function setUp(): void { @@ -29,9 +27,6 @@ protected function tearDown(): void } /** - * @param string $envToSearch - * @param string $expected - * @param array $testEnv * @dataProvider getEnvDataProvider */ public function testGetEnv(string $envToSearch, string $expected, array $testEnv): void @@ -46,15 +41,15 @@ public function getEnvDataProvider(): array 'emptyAll' => [ 'envToSearch' => '', 'expected' => '', - 'testEnvs' => [] + 'testEnvs' => [], ], 'emptyEnvToSearch' => [ 'envToSearch' => '', 'expected' => '', 'testEnvs' => [ 'PHP_TEST_ENV' => 'test-value', - 'PHP_ANOTHER_TEST_ENV' => 'test-value1' - ] + 'PHP_ANOTHER_TEST_ENV' => 'test-value1', + ], ], 'envToSearchContainsOnlySystemSymbols' => [ 'envToSearch' => "\t\r\n\0\x0B ", @@ -62,49 +57,49 @@ public function getEnvDataProvider(): array 'testEnvs' => [ 'PHP_TEST' => 'test', 'PHP_SOME_ENV' => 'test1', - 'PHP_DB_HOST' => 'test2' - ] + 'PHP_DB_HOST' => 'test2', + ], ], 'envNotContainsInEnvList' => [ 'envToSearch' => 'PHP_UNIQ_ENV', 'expected' => '', 'testEnvs' => [ 'PHP_TEST' => 'test', - 'PHP_TEST1' => 'test1' - ] + 'PHP_TEST1' => 'test1', + ], ], 'envContains' => [ 'envToSearch' => 'PHP_UNIQ_ENV', 'expected' => 'uniq_env_value', 'testEnvs' => [ 'PHP_SOME_ENV_TEST' => 'some,value', - 'PHP_UNIQ_ENV' => 'uniq_env_value' - ] + 'PHP_UNIQ_ENV' => 'uniq_env_value', + ], ], 'envContainsButPassedInIncorrectFormat' => [ 'envToSearch' => 'PHP-UNIQ-ENV ', 'expected' => '', 'testEnvs' => [ 'PHP_ENV' => 'yep,its_env_value', - 'PHP_UNIQ_ENV' => 'some-random,value' - ] + 'PHP_UNIQ_ENV' => 'some-random,value', + ], ], 'envToSearchInLowerRegister' => [ 'envToSearch' => 'php_test_env', 'expected' => 'success', 'testEnvs' => [ 'PHP_ENV' => 'some value', - 'php_test_env' => 'success' - ] + 'php_test_env' => 'success', + ], ], 'envToSearchInUpperRegister' => [ 'envToSearch' => 'PHP_TEST_ENV', 'expected' => 'success', 'testEnvs' => [ 'PHP_ENV' => 'some value', - 'PHP_TEST_ENV' => 'success' - ] - ] + 'PHP_TEST_ENV' => 'success', + ], + ], ]; } }