mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
[CI] Add check for duplicated fixture after before content
This commit is contained in:
parent
a97a57e577
commit
05b6df31e6
2
.github/workflows/code_checks.yml
vendored
2
.github/workflows/code_checks.yml
vendored
@ -102,6 +102,8 @@ jobs:
|
||||
php ci/check_services_in_yaml_configs.php
|
||||
- run: |
|
||||
php ci/run_all_sets.php
|
||||
- run: |
|
||||
php ci/check_keep_fixtures.php
|
||||
|
||||
phpstan_types_checks:
|
||||
runs-on: ubuntu-latest
|
||||
|
54
ci/check_keep_fixtures.php
Normal file
54
ci/check_keep_fixtures.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Testing\PHPUnit\FixtureSplitter;
|
||||
use Symplify\PackageBuilder\Console\ShellCode;
|
||||
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
|
||||
use Symplify\SmartFileSystem\Finder\FinderSanitizer;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$finder = new Symfony\Component\Finder\Finder();
|
||||
$finder->files();
|
||||
$finder->name('*.php.inc');
|
||||
$finder->in(__DIR__ . '/../tests');
|
||||
$finder->in(__DIR__ . '/../packages/*/tests');
|
||||
|
||||
$finderSanitizer = new FinderSanitizer();
|
||||
$smartFileInfos = $finderSanitizer->sanitize($finder);
|
||||
|
||||
$symfonyStyleFactory = new SymfonyStyleFactory();
|
||||
$symfonyStyle = $symfonyStyleFactory->create();
|
||||
|
||||
$errors = [];
|
||||
|
||||
/** @var \Symfony\Component\Finder\SplFileInfo $smartFileInfo */
|
||||
foreach ($smartFileInfos as $smartFileInfo) {
|
||||
if (!Strings::match($smartFileInfo->getContents(), FixtureSplitter::SPLIT_LINE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// original → expected
|
||||
[$originalContent, $expectedContent] = Strings::split($smartFileInfo->getContents(), FixtureSplitter::SPLIT_LINE);
|
||||
if ($originalContent !== $expectedContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$errors[] = $smartFileInfo->getRelativeFilePathFromCwd();
|
||||
}
|
||||
|
||||
if ($errors === []) {
|
||||
exit(ShellCode::SUCCESS);
|
||||
}
|
||||
|
||||
$symfonyStyle->warning(sprintf(
|
||||
'These files have same content before "%s" and after it. Remove the content after "%s"',
|
||||
FixtureSplitter::SPLIT_LINE,
|
||||
FixtureSplitter::SPLIT_LINE
|
||||
));
|
||||
|
||||
$symfonyStyle->listing($errors);
|
||||
|
||||
exit(ShellCode::ERROR);
|
@ -10,20 +10,3 @@ function renameMethodCallBasedOnParameterNoop()
|
||||
$config = $object->getParam('other');
|
||||
$object->withParam('other', 'value');
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHP\Tests\Rector\MethodCall\RenameMethodCallBasedOnParameterRector;
|
||||
|
||||
function renameMethodCallBasedOnParameterNoop()
|
||||
{
|
||||
$object = new Source\SomeModelType;
|
||||
|
||||
$config = $object->getParam($value);
|
||||
$config = $object->getParam('other');
|
||||
$object->withParam('other', 'value');
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -15,25 +15,3 @@ function simplifyEmptyCheck()
|
||||
|
||||
echo is_array($objects) && is_array($objects);
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodeQuality\Tests\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector\Fixture;
|
||||
|
||||
function simplifyEmptyCheck()
|
||||
{
|
||||
$invalid = is_array($var) && in_array('foo', $var);
|
||||
$almostValid = is_array($var) && count($var) > 0;
|
||||
$invalid2 = isset($this->events[$event]) && !empty($this->events[$event]);
|
||||
$completelyInvalid = !$value instanceof \Foo && !$value instanceof \Bar;
|
||||
|
||||
if (empty($this->orders) && empty($this->unionOrders)) {
|
||||
throw new \RuntimeException('You must specify an orderBy clause when using this function.');
|
||||
}
|
||||
|
||||
echo is_array($objects) && is_array($objects);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -26,36 +26,3 @@ function simplifyEmptyCheck2()
|
||||
$objects = [];
|
||||
is_array($objects) && is_array($objects);
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodeQuality\Tests\Rector\FuncCall\SimplifyEmptyArrayCheckRector\Fixture;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function isntEmptyArray($values): bool
|
||||
{
|
||||
return is_array($values) && !empty($values);
|
||||
}
|
||||
|
||||
public function isntEmptyArray2($values): bool
|
||||
{
|
||||
return !empty($values) && is_array($values);
|
||||
}
|
||||
|
||||
public function twoNegatives($values): bool
|
||||
{
|
||||
return !empty($values->foo) && !is_array($values->bar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function simplifyEmptyCheck2()
|
||||
{
|
||||
$objects = [];
|
||||
is_array($objects) && is_array($objects);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -10,20 +10,3 @@ function simplifyConditions3()
|
||||
$itemsWithoutTransportAndPayment[] = $orderItem;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
function simplifyConditions3()
|
||||
{
|
||||
if ($a === '-' && !$start && !($i < $l && $s[$i] === ']')) {
|
||||
echo 'maybe';
|
||||
}
|
||||
|
||||
if (!($orderItem instanceof OrderTransport || $orderItem instanceof OrderPayment)) {
|
||||
$itemsWithoutTransportAndPayment[] = $orderItem;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -20,30 +20,3 @@ function simplifyIfReturnBool8()
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
function simplifyIfReturnBool8()
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} elseif (is_string($value) && trim($value) === '') {
|
||||
return false;
|
||||
} elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) {
|
||||
return false;
|
||||
} elseif ($value instanceof stdClass) {
|
||||
return (string)$value->getPath() !== '';
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -8,18 +8,3 @@ function simplifyIfReturnBool9()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
function simplifyIfReturnBool9()
|
||||
{
|
||||
if ($dateTimePattern->getTimeType() !== null && $dateTimePattern->getTimeType() !== $timeType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -203,213 +203,3 @@ function ($values) {
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodeQuality\Tests\Rector\Return_\SimplifyUselessVariableRector\Fixture;
|
||||
|
||||
class NoError
|
||||
{
|
||||
private $noError = 'noError';
|
||||
|
||||
private static $static;
|
||||
|
||||
public function __construct($parameter)
|
||||
{
|
||||
self::$static = 'static';
|
||||
$this->$parameter = 'this';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$noErrorToo = null;
|
||||
function ($noError = 'noError') use ($noErrorToo) {
|
||||
|
||||
};
|
||||
|
||||
$used = true;
|
||||
|
||||
function foo($foo) {
|
||||
return preg_replace_callback('~~', function ($matches) {
|
||||
return $matches[0];
|
||||
}, $foo);
|
||||
}
|
||||
|
||||
return $used;
|
||||
|
||||
function ($values) {
|
||||
$foo = '';
|
||||
|
||||
foreach ($values as $value) {
|
||||
echo $foo . $value;
|
||||
}
|
||||
};
|
||||
|
||||
function () {
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
}
|
||||
};
|
||||
|
||||
function ($values) {
|
||||
foreach ($values as $value) {
|
||||
$foo = 'foo' . $value;
|
||||
}
|
||||
echo $foo;
|
||||
};
|
||||
|
||||
function ($values) {
|
||||
list($a, $b) = $values;
|
||||
return $a + $b;
|
||||
};
|
||||
|
||||
function ($values) {
|
||||
[$c, $d] = $values;
|
||||
return $c * $d;
|
||||
};
|
||||
|
||||
function ($values) {
|
||||
$current = 'current';
|
||||
$next = 'next';
|
||||
|
||||
while ($next) {
|
||||
if ($current) {
|
||||
|
||||
}
|
||||
|
||||
$current = false;
|
||||
|
||||
if (true) {
|
||||
foreach ($values as $value) {
|
||||
$next = $value;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
$previous = 'previous';
|
||||
} while ($previous);
|
||||
}
|
||||
};
|
||||
|
||||
function (&$parameter) {
|
||||
$parameter = 'value-by-reference';
|
||||
};
|
||||
|
||||
function () use (&$inheritedVariable) {
|
||||
$inheritedVariable = 'value-by-reference';
|
||||
};
|
||||
|
||||
function ($interval) {
|
||||
$j = 0;
|
||||
for ($i = $j; $i < 10; $i += $interval) {
|
||||
}
|
||||
};
|
||||
|
||||
function () {
|
||||
static $static = false;
|
||||
if ($static) {
|
||||
return;
|
||||
}
|
||||
|
||||
$static = true;
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = 'a';
|
||||
$b = 'b';
|
||||
|
||||
$this->compact;
|
||||
|
||||
return compact('a', "b");
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = '';
|
||||
echo "$a";
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = '';
|
||||
echo "${a}";
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = '';
|
||||
echo "$a()";
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = '';
|
||||
echo <<<TEXT
|
||||
$a
|
||||
TEXT;
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = '';
|
||||
echo <<<TEXT
|
||||
${a}
|
||||
TEXT;
|
||||
};
|
||||
|
||||
function () {
|
||||
$a = 10;
|
||||
max(1, $a += 10);
|
||||
};
|
||||
|
||||
class Whatever
|
||||
{
|
||||
|
||||
public function listFunction($a, $b) {
|
||||
list($this->a, $this->b) = [$a, $b];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function () {
|
||||
$i = 0;
|
||||
while ($i++ <= 10) {
|
||||
}
|
||||
};
|
||||
|
||||
function () {
|
||||
$i = 0;
|
||||
do {
|
||||
} while (++$i <= 10);
|
||||
};
|
||||
|
||||
function () {
|
||||
$i = 10;
|
||||
while ($i-- > 0) {
|
||||
}
|
||||
};
|
||||
|
||||
function () {
|
||||
$i = 10;
|
||||
do {
|
||||
} while (--$i > 0);
|
||||
};
|
||||
|
||||
function ($data) {
|
||||
$i = 0;
|
||||
$c = '';
|
||||
foreach ($data as $c) {
|
||||
$c = $i++;
|
||||
}
|
||||
echo $c;
|
||||
};
|
||||
|
||||
function ($values) {
|
||||
$expectedKey = 0;
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
if ($key !== $expectedKey++) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
?>
|
||||
|
@ -6,16 +6,3 @@ function unnecessaryTernaryExpression()
|
||||
{
|
||||
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodeQuality\Tests\Rector\Ternary\UnnecessaryTernaryExpressionRector\Fixture;
|
||||
|
||||
function unnecessaryTernaryExpression()
|
||||
{
|
||||
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -18,26 +18,3 @@ class NoOverrideException extends \Exception
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDelegatingParentCallRector\DifferentDefaults;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class DefaultOverrideException extends \Exception
|
||||
{
|
||||
public function __construct($message = "My special message", $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
class NoOverrideException extends \Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -7,17 +7,3 @@ function run_define()
|
||||
define(NAME, 'Tom');
|
||||
define('AGE', 1000);
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Php72\Tests\Rector\ConstFetch\BarewordStringRector\Fixture;
|
||||
|
||||
function run_define()
|
||||
{
|
||||
define(NAME, 'Tom');
|
||||
define('AGE', 1000);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -7,17 +7,3 @@ function regexFalsePositive()
|
||||
// keep
|
||||
preg_match("#^\d{4}-\d{2}-\d{2}$#", 'some text');
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Php73\Tests\Rector\FuncCall\RegexDashEscapeRector\Fixture;
|
||||
|
||||
function regexFalsePositive()
|
||||
{
|
||||
// keep
|
||||
preg_match("#^\d{4}-\d{2}-\d{2}$#", 'some text');
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -11,21 +11,3 @@ class AnyClass2
|
||||
$request->getSession()->getFlashBag()->add('success', 'message');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Symfony\Tests\Rector\Controller\AddFlashRector\Fixture;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AnyClass2
|
||||
{
|
||||
public function someAction(Request $request)
|
||||
{
|
||||
$request->getSession()->getFlashBag()->add('success', 'message');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -19,29 +19,3 @@ final class ContactType
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Symfony\Tests\Rector\Form\StringFormTypeToClassRector\Fixture;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
|
||||
final class ContactType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'sylius.ui.email',
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -8,16 +8,3 @@ namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ParamTypeDeclarationRe
|
||||
function param_no_type($noType)
|
||||
{
|
||||
}
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ParamTypeDeclarationRector\Fixture\Dunglas;
|
||||
|
||||
/**
|
||||
* @param $noType
|
||||
*/
|
||||
function param_no_type($noType)
|
||||
{
|
||||
}
|
||||
?>
|
||||
|
@ -6,16 +6,3 @@ namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationR
|
||||
function foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationRector\Fixture\Nikic\Null_;
|
||||
|
||||
/** @return null */
|
||||
function foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -13,7 +13,7 @@ final class FixtureSplitter
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const SPLIT_LINE = '#-----\n#';
|
||||
public const SPLIT_LINE = '#-----\n#';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
|
@ -11,21 +11,3 @@ class SomeTestCase
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
class SomeTestCase
|
||||
{
|
||||
/**
|
||||
* @return Synapse|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function getSynapseMock(int $output = 2): \PHPUnit_Framework_MockObject_MockObject
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user