Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
upgraded automatic-common to v0.6.0 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 9, 2018
1 parent de0685b commit 743b5e4
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 57 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/AbstractClassConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/ProxyConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/ServiceProviderConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Traits/GetSortedClassesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
66 changes: 44 additions & 22 deletions tests/ProxyConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -216,7 +230,9 @@ public function testConfigureWithEmptyProxiesConfig(): void
{
$package = new Package('test', '^1.0.0');
$package->setConfig([
'proxies' => [
'configurators' => [
'proxies' => [
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand Down
66 changes: 44 additions & 22 deletions tests/ServiceProviderConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -212,7 +226,9 @@ public function testConfigureWithEmptyProvidersConfig(): void
{
$package = new Package('test', '^1.0.0');
$package->setConfig([
'providers' => [
'configurators' => [
'providers' => [
],
],
]);

Expand Down Expand Up @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand All @@ -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'],
],
],
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Traits/GetSortedClassesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 743b5e4

Please sign in to comment.