Skip to content

Commit

Permalink
#1433 Allow to set both global settings in config file at the same ti…
Browse files Browse the repository at this point in the history
…me (#1434)
  • Loading branch information
lapisangularis committed Nov 20, 2020
1 parent 125d2a9 commit 8c9a21e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Mutator/MutatorResolver.php
Expand Up @@ -70,20 +70,16 @@ public function resolve(array $mutatorSettings): array
/** @var string[] $globalSetting */
$globalSetting = $setting;

$globalSettings = ['ignore' => $globalSetting];
$globalSettings['ignore'] = $globalSetting;
unset($mutatorSettings[self::GLOBAL_IGNORE_SETTING]);

break;
}

if ($mutatorOrProfileOrGlobalSettingKey === self::GLOBAL_IGNORE_SOURCE_CODE_BY_REGEX_SETTING) {
/** @var string[] $globalSetting */
$globalSetting = $setting;

$globalSettings = ['ignoreSourceCodeByRegex' => $globalSetting];
$globalSettings['ignoreSourceCodeByRegex'] = $globalSetting;
unset($mutatorSettings[self::GLOBAL_IGNORE_SOURCE_CODE_BY_REGEX_SETTING]);

break;
}
}

Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/Mutator/MutatorResolverTest.php
Expand Up @@ -292,6 +292,43 @@ public function test_it_can_resolve_mutators_with_global_ignore_source_code_by_r
$this->assertSame(['ignoreSourceCodeByRegex' => ['A::B', 'B::C']], $resolvedMutators[IdenticalEqual::class]);
}

public function test_it_can_resolve_mutators_with_both_global_settings_at_the_same_time(): void
{
$resolvedMutators = $this->mutatorResolver->resolve([
'global-ignore' => ['A::B'],
'global-ignoreSourceCodeByRegex' => ['A::B'],
MutatorName::getName(Plus::class) => true,
MutatorName::getName(For_::class) => false,
MutatorName::getName(IdenticalEqual::class) => [
'ignore' => ['B::C'],
'ignoreSourceCodeByRegex' => ['B::C'],
],
]);

$this->assertSameMutatorsByClass(
[
Plus::class,
IdenticalEqual::class,
],
$resolvedMutators
);

$this->assertSame(
[
'ignore' => ['A::B'],
'ignoreSourceCodeByRegex' => ['A::B'],
],
$resolvedMutators[Plus::class]
);
$this->assertSame(
[
'ignore' => ['A::B', 'B::C'],
'ignoreSourceCodeByRegex' => ['A::B', 'B::C'],
],
$resolvedMutators[IdenticalEqual::class]
);
}

public function test_it_always_enrich_global_settings_for_a_mutator_regardless_of_the_order(): void
{
$resolvedMutators = $this->mutatorResolver->resolve([
Expand Down

0 comments on commit 8c9a21e

Please sign in to comment.