diff --git a/composer.json b/composer.json index 39267d8..fa9a58b 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ "ext-mbstring": "*" }, "require-dev": { - "composer/composer": "^1.6.0", + "composer/composer": "^1.6.0 || ^1.7.1", "mockery/mockery": "^1.0.0", - "narrowspark/automatic-common": "^0.3.0", - "narrowspark/coding-standard": "^1.1.0", + "narrowspark/automatic-common": "^0.6.1", + "narrowspark/coding-standard": "^1.2.0", "narrowspark/testing-helper": "^7.0.0", "phpunit/phpunit": "^7.2.0" }, @@ -49,11 +49,11 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { + "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend", "coverage": "phpunit --coverage-html=\"build/logs\"", "cs": "php-cs-fixer fix", "phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1", - "test": "phpunit", - "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend" + "test": "phpunit" }, "support": { "issues": "https://github.com/narrowspark/configurators/issues", diff --git a/src/AbstractClassConfigurator.php b/src/AbstractClassConfigurator.php index 603f00e..a06eb25 100644 --- a/src/AbstractClassConfigurator.php +++ b/src/AbstractClassConfigurator.php @@ -157,7 +157,7 @@ protected function getConfFile(string $type): string { $type = $type === 'global' ? '' : $type; - return self::expandTargetDir($this->options, '%CONFIG_DIR%/' . $type . '/' . static::$configFileName . '.php'); + return self::expandTargetDir($this->options, '%CONFIG_DIR%' . \DIRECTORY_SEPARATOR . $type . \DIRECTORY_SEPARATOR . static::$configFileName . '.php'); } /** @@ -170,7 +170,12 @@ protected function getConfFile(string $type): string * * @return string */ - abstract protected function generateFileContent(PackageContract $package, string $filePath, array $classes, string $env): string; + abstract protected function generateFileContent( + PackageContract $package, + string $filePath, + array $classes, + string $env + ): string; /** * Replace a string in content. diff --git a/src/ProxyConfigurator.php b/src/ProxyConfigurator.php index bd2384b..cc0e7d4 100644 --- a/src/ProxyConfigurator.php +++ b/src/ProxyConfigurator.php @@ -42,8 +42,12 @@ public static function getName(): string /** * {@inheritdoc} */ - protected function generateFileContent(PackageContract $package, string $filePath, array $classes, string $env): string - { + protected function generateFileContent( + PackageContract $package, + string $filePath, + array $classes, + string $env + ): string { if (\file_exists($filePath)) { $content = (string) \file_get_contents($filePath); diff --git a/src/ServiceProviderConfigurator.php b/src/ServiceProviderConfigurator.php index db271fc..f1ff02c 100644 --- a/src/ServiceProviderConfigurator.php +++ b/src/ServiceProviderConfigurator.php @@ -37,8 +37,12 @@ public static function getName(): string /** * {@inheritdoc} */ - protected function generateFileContent(PackageContract $package, string $filePath, array $classes, string $type): string - { + protected function generateFileContent( + PackageContract $package, + string $filePath, + array $classes, + string $type + ): string { if (\file_exists($filePath)) { $content = (string) \file_get_contents($filePath); diff --git a/src/Traits/GetSortedClassesTrait.php b/src/Traits/GetSortedClassesTrait.php index 064ee2e..d68f941 100644 --- a/src/Traits/GetSortedClassesTrait.php +++ b/src/Traits/GetSortedClassesTrait.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace Narrowspark\Automatic\Configurator\Traits; +use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; trait GetSortedClassesTrait @@ -18,7 +19,7 @@ protected function getSortedClasses(PackageContract $package, string $key): arra { $sortedProviders = []; - foreach ((array) $package->getConfig($key) as $provider => $environments) { + foreach ((array) $package->getConfig(ConfiguratorContract::TYPE, $key) as $provider => $environments) { $class = \mb_strpos($provider, '::class') !== false ? $provider : $provider . '::class'; foreach ($environments as $environment) { diff --git a/tests/ProxyConfiguratorTest.php b/tests/ProxyConfiguratorTest.php index 88b58be..505a2d6 100644 --- a/tests/ProxyConfiguratorTest.php +++ b/tests/ProxyConfiguratorTest.php @@ -82,8 +82,10 @@ public function testConfigureWithGlobalProxy(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global'], + ], ], ]); @@ -100,8 +102,10 @@ public function testConfigureWithGlobalAndLocalProxy(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global', 'local'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global', 'local'], + ], ], ]); @@ -123,8 +127,10 @@ public function testSkipMarkedFiles(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global'], + ], ], ]); @@ -143,8 +149,10 @@ public function testUpdateExistedFileWithGlobalProxy(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global'], + ], ], ]); @@ -158,8 +166,10 @@ public function testUpdateExistedFileWithGlobalProxy(): void $package = new Package('test2', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - Package::class => ['global'], + 'configurators' => [ + 'proxies' => [ + Package::class => ['global'], + ], ], ]); @@ -177,8 +187,10 @@ public function testUpdateAExistedFileWithGlobalAndLocalProxy(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global', 'local'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global', 'local'], + ], ], ]); @@ -194,8 +206,10 @@ public function testUpdateAExistedFileWithGlobalAndLocalProxy(): void $package = new Package('test2', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - Package::class => ['global', 'local'], + 'configurators' => [ + 'proxies' => [ + Package::class => ['global', 'local'], + ], ], ]); @@ -216,7 +230,9 @@ public function testConfigureWithEmptyProxiesConfig(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ + 'configurators' => [ + 'proxies' => [ + ], ], ]); @@ -229,8 +245,10 @@ public function testUnconfigureWithGlobalProxies(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global'], + ], ], ]); @@ -244,8 +262,10 @@ public function testUnconfigureWithGlobalProxies(): void $package = new Package('test2', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - Package::class => ['global'], + 'configurators' => [ + 'proxies' => [ + Package::class => ['global'], + ], ], ]); @@ -263,9 +283,11 @@ public function testUnconfigureAndConfigureAgain(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'proxies' => [ - self::class => ['global'], - Package::class => ['local'], + 'configurators' => [ + 'proxies' => [ + self::class => ['global'], + Package::class => ['local'], + ], ], ]); diff --git a/tests/ServiceProviderConfiguratorTest.php b/tests/ServiceProviderConfiguratorTest.php index f3064e3..51496fe 100644 --- a/tests/ServiceProviderConfiguratorTest.php +++ b/tests/ServiceProviderConfiguratorTest.php @@ -82,8 +82,10 @@ public function testConfigureWithGlobalProvider(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global'], + 'configurators' => [ + 'providers' => [ + self::class => ['global'], + ], ], ]); @@ -100,8 +102,10 @@ public function testConfigureWithGlobalAndLocalProvider(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global', 'local'], + 'configurators' => [ + 'providers' => [ + self::class => ['global', 'local'], + ], ], ]); @@ -123,8 +127,10 @@ public function testSkipMarkedFiles(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global'], + 'configurators' => [ + 'providers' => [ + self::class => ['global'], + ], ], ]); @@ -143,8 +149,10 @@ public function testUpdateAExistedFileWithGlobalProvider(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global'], + 'configurators' => [ + 'providers' => [ + self::class => ['global'], + ], ], ]); @@ -156,8 +164,10 @@ public function testUpdateAExistedFileWithGlobalProvider(): void $package = new Package('test2', '^1.0.0'); $package->setConfig([ - 'providers' => [ - Package::class => ['global'], + 'configurators' => [ + 'providers' => [ + Package::class => ['global'], + ], ], ]); @@ -173,8 +183,10 @@ public function testUpdateAExistedFileWithGlobalAndLocalProvider(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global', 'local'], + 'configurators' => [ + 'providers' => [ + self::class => ['global', 'local'], + ], ], ]); @@ -190,8 +202,10 @@ public function testUpdateAExistedFileWithGlobalAndLocalProvider(): void $package = new Package('test2', '^1.0.0'); $package->setConfig([ - 'providers' => [ - Package::class => ['global', 'local'], + 'configurators' => [ + 'providers' => [ + Package::class => ['global', 'local'], + ], ], ]); @@ -212,7 +226,9 @@ public function testConfigureWithEmptyProvidersConfig(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ + 'configurators' => [ + 'providers' => [ + ], ], ]); @@ -269,8 +285,10 @@ public function testUnconfigureWithGlobalProviders(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global'], + 'configurators' => [ + 'providers' => [ + self::class => ['global'], + ], ], ]); @@ -279,8 +297,10 @@ public function testUnconfigureWithGlobalProviders(): void $package = new Package('test2', '^1.0.0'); $package->setConfig([ - 'providers' => [ - Package::class => ['global'], + 'configurators' => [ + 'providers' => [ + Package::class => ['global'], + ], ], ]); @@ -296,9 +316,11 @@ public function testUnconfigureAndConfigureAgain(): void { $package = new Package('test', '^1.0.0'); $package->setConfig([ - 'providers' => [ - self::class => ['global'], - Package::class => ['local'], + 'configurators' => [ + 'providers' => [ + self::class => ['global'], + Package::class => ['local'], + ], ], ]); diff --git a/tests/Traits/GetSortedClassesTraitTest.php b/tests/Traits/GetSortedClassesTraitTest.php index 4ca3956..d193209 100644 --- a/tests/Traits/GetSortedClassesTraitTest.php +++ b/tests/Traits/GetSortedClassesTraitTest.php @@ -18,7 +18,7 @@ public function testGetSortedClasses(): void $package = $this->mock(PackageContract::class); $package->shouldReceive('getConfig') ->once() - ->with('providers') + ->with('configurators', 'providers') ->andReturn([ self::class => ['global'], Configurator::class => ['global', 'test'],