Skip to content

Commit

Permalink
PhpUnitDedicateAssertInternalTypeFixer - recover target option
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Dec 16, 2020
1 parent 7bc3a25 commit cb29f72
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 2 additions & 0 deletions doc/ruleSets/PHPUnit75MigrationRisky.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Rules

- `@PHPUnit60Migration:risky <./PHPUnit60MigrationRisky.rst>`_
- `php_unit_dedicate_assert_internal_type <./../rules/php_unit/php_unit_dedicate_assert_internal_type.rst>`_
config:
``['target' => '7.5']``
10 changes: 6 additions & 4 deletions doc/rules/php_unit/php_unit_dedicate_assert_internal_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Configuration
``target``
~~~~~~~~~~

.. warning:: This option is deprecated and will be removed on next major version. Option was not used.

Target version of PHPUnit.

Allowed values: ``'7.5'``, ``'newest'``
Expand Down Expand Up @@ -53,7 +51,11 @@ Rule sets
The rule is part of the following rule sets:

@PHPUnit75Migration:risky
Using the `@PHPUnit75Migration:risky <./../../ruleSets/PHPUnit75MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert_internal_type`` rule with the default config.
Using the `@PHPUnit75Migration:risky <./../../ruleSets/PHPUnit75MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert_internal_type`` rule with the config below:

``['target' => '7.5']``

@PHPUnit84Migration:risky
Using the `@PHPUnit84Migration:risky <./../../ruleSets/PHPUnit84MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert_internal_type`` rule with the default config.
Using the `@PHPUnit84Migration:risky <./../../ruleSets/PHPUnit84MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert_internal_type`` rule with the config below:

``['target' => '7.5']``
2 changes: 0 additions & 2 deletions src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ public function getPriority()
*/
protected function createConfigurationDefinition()
{
// @todo 3.0 drop `ConfigurationDefinitionFixerInterface`
return new FixerConfigurationResolver([
(new FixerOptionBuilder('target', 'Target version of PHPUnit.'))
->setAllowedTypes(['string'])
->setAllowedValues([PhpUnitTargetVersion::VERSION_7_5, PhpUnitTargetVersion::VERSION_NEWEST])
->setDefault(PhpUnitTargetVersion::VERSION_NEWEST)
->setDeprecationMessage('Option was not used.')
->getOption(),
]);
}
Expand Down
4 changes: 3 additions & 1 deletion src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function getRules()
{
return [
'@PHPUnit60Migration:risky' => true,
'php_unit_dedicate_assert_internal_type' => true,
'php_unit_dedicate_assert_internal_type' => [
'target' => '7.5',
],
];
}

Expand Down
9 changes: 2 additions & 7 deletions tests/RuleSet/RuleSetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\FixerConfiguration\DeprecatedFixerOption;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixer\RuleSet\RuleSets;
Expand Down Expand Up @@ -197,7 +196,7 @@ private static function assertPHPUnitVersionIsLargestAllowed($setName, $ruleName
}

if (!isset($allowedVersionsForFixer)) {
static::markTestSkipped(sprintf('The fixer "%s" does not have option "target".', $fixer->getName()));
throw new \Exception(sprintf('The fixer "%s" does not have option "target".', $fixer->getName()));
}

$allowedVersionsForRuleset = array_filter(
Expand Down Expand Up @@ -274,10 +273,6 @@ private function getDefaultPHPUnitTargetOfRule($ruleName)
$fixer = self::getFixerByName($ruleName);

foreach ($fixer->getConfigurationDefinition()->getOptions() as $option) {
if ($option instanceof DeprecatedFixerOption) {
continue;
}

if ('target' === $option->getName()) {
$targetVersion = $option->getDefault();

Expand All @@ -286,7 +281,7 @@ private function getDefaultPHPUnitTargetOfRule($ruleName)
}

if (null === $targetVersion) {
static::markTestSkipped(sprintf('The fixer "%s" does not have option "target".', $fixer->getName()));
throw new \Exception(sprintf('The fixer "%s" does not have option "target".', $fixer->getName()));
}

return $targetVersion;
Expand Down

0 comments on commit cb29f72

Please sign in to comment.