Skip to content

Commit

Permalink
DX: add missing non-default code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Jun 21, 2020
1 parent c0d6a34 commit 950c8a2
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function getDefinition()
new CodeSample(
"<?php\n/**\n * @Foo ( )\n */\nclass Bar {}\n\n/**\n * @Foo(\"bar\" ,\"baz\")\n */\nclass Bar2 {}\n\n/**\n * @Foo(foo = \"foo\", bar = {\"foo\":\"foo\", \"bar\"=\"bar\"})\n */\nclass Bar3 {}\n"
),
new CodeSample(
"<?php\n/**\n * @Foo(foo = \"foo\", bar = {\"foo\":\"foo\", \"bar\"=\"bar\"})\n */\nclass Bar {}\n",
['after_array_assignments_equals' => false, 'before_array_assignments_equals' => false]
),
],
'There must not be any space around parentheses; commas must be preceded by no space and followed by one space; there must be no space around named arguments assignment operator; there must be one space around array assignment operator.'
);
Expand Down
10 changes: 10 additions & 0 deletions src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ function my_foo()
',
new VersionSpecification(70200)
),
new VersionSpecificCodeSample(
'<?php
/** @return Foo */
function foo() {}
/** @return string */
function bar() {}
',
new VersionSpecification(70100),
['scalar_types' => false]
),
],
null,
'This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2] `@return` annotation is mandatory for the fixer to make changes, signatures of methods without it (no docblock, inheritdocs) will not be fixed. [3] Manual actions are required if inherited signatures are not properly documented. [4] `@inheritdocs` support is under construction.'
Expand Down
8 changes: 7 additions & 1 deletion src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ public function getDefinition()
{
return new FixerDefinition(
'All PHPUnit test classes should be marked as internal.',
[new CodeSample("<?php\nclass MyTest extends TestCase {}\n")]
[
new CodeSample("<?php\nclass MyTest extends TestCase {}\n"),
new CodeSample(
"<?php\nclass MyTest extends TestCase {}\nfinal class FinalTest extends TestCase {}\nabstract class AbstractTest extends TestCase {}\n",
['types' => ['final']]
),
]
);
}

Expand Down
19 changes: 12 additions & 7 deletions src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ final class PhpUnitNamespacedFixer extends AbstractFixer implements Configuratio
*/
public function getDefinition()
{
return new FixerDefinition(
'PHPUnit classes MUST be used in namespaced version, e.g. `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.',
[
new CodeSample(
'<?php
$codeSample = '<?php
final class MyTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
PHPUnit_Framework_Assert::assertTrue(true);
}
}
'
),
';

return new FixerDefinition(
'PHPUnit classes MUST be used in namespaced version, e.g. `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.',
[
new CodeSample($codeSample),
new CodeSample($codeSample, ['target' => PhpUnitTargetVersion::VERSION_4_8]),
],
"PHPUnit v6 has finally fully switched to namespaces.\n"
."You could start preparing the upgrade by switching from non-namespaced TestCase to namespaced one.\n"
Expand Down
15 changes: 8 additions & 7 deletions src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,7 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractFixer implemen
*/
public function getDefinition()
{
return new FixerDefinition(
'Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type, either `$this->`, `self::` or `static::`.',
[
new CodeSample(
'<?php
$codeSample = '<?php
final class MyTest extends \PHPUnit_Framework_TestCase
{
public function testMe()
Expand All @@ -288,8 +284,13 @@ public function testMe()
static::assertSame(1, 2);
}
}
'
),
';

return new FixerDefinition(
'Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type, either `$this->`, `self::` or `static::`.',
[
new CodeSample($codeSample),
new CodeSample($codeSample, ['call_type' => self::CALL_TYPE_THIS]),
],
null,
'Risky when PHPUnit methods are overridden or not accessible, or when project has PHPUnit incompatibilities.'
Expand Down
14 changes: 13 additions & 1 deletion src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@ public function getDefinition()
'<?php
/**
* @internal
* @author someone
* @author John Doe
*/
function foo() {}
',
['annotations' => ['author']]
),
new CodeSample(
'<?php
/**
* @author John Doe
* @package ACME API
* @subpackage Authorization
* @version 1.0
*/
function foo() {}
',
['annotations' => ['package', 'subpackage']]
),
]
);
}
Expand Down
20 changes: 18 additions & 2 deletions src/Fixer/Phpdoc/PhpdocScalarFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function getDefinition()
{
return new FixerDefinition(
'Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.',
[new CodeSample('<?php
[
new CodeSample('<?php
/**
* @param integer $a
* @param boolean $b
Expand All @@ -58,7 +59,22 @@ function sample($a, $b, $c)
{
return sample2($a, $b, $c);
}
')]
'),
new CodeSample(
'<?php
/**
* @param integer $a
* @param boolean $b
* @param real $c
*/
function sample($a, $b, $c)
{
return sample2($a, $b, $c);
}
',
['types' => ['boolean']]
),
]
);
}

Expand Down
10 changes: 10 additions & 0 deletions src/Fixer/Phpdoc/PhpdocTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public function getDefinition()
*/
'
),
new CodeSample(
'<?php
/**
* @param BOOL $foo
*
* @return MIXED
*/
',
['groups' => ['simple', 'alias']]
),
]
);
}
Expand Down
13 changes: 3 additions & 10 deletions tests/AutoReview/FixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,10 @@ public function testFixerDefinitions(AbstractFixer $fixer)
static::assertArrayHasKey($fixerName, $this->allowedRequiredOptions, sprintf('[%s] Has no sample for default configuration.', $fixerName));
}

$fixerNamesWithKnownMissingSamplesWithConfig = [
'doctrine_annotation_spaces',
'general_phpdoc_annotation_remove',
'is_null',
// It may only shrink, never add anything to it.
$fixerNamesWithKnownMissingSamplesWithConfig = [ // @TODO 3.0 - remove this
'is_null', // has only one option which is deprecated
'php_unit_dedicate_assert_internal_type',
'php_unit_internal_class',
'php_unit_namespaced',
'php_unit_test_case_static_method_calls',
'phpdoc_scalar',
'phpdoc_to_return_type',
'phpdoc_types',
];

if (\count($configSamplesProvided) < 2) {
Expand Down

0 comments on commit 950c8a2

Please sign in to comment.