1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/tests/FileManipulation/ParamNameMismatchTest.php

129 lines
4.7 KiB
PHP
Raw Normal View History

2020-08-14 21:25:21 +02:00
<?php
2020-08-14 21:25:21 +02:00
namespace Psalm\Tests\FileManipulation;
class ParamNameMismatchTest extends FileManipulationTestCase
2020-08-14 21:25:21 +02:00
{
public function providerValidCodeParse(): array
2020-08-14 21:25:21 +02:00
{
return [
'fixMismatchingParamName74' => [
'input' => '<?php
2020-08-14 21:25:21 +02:00
class A {
public function foo(string $str, bool $b = false) : void {}
}
class AChild extends A {
public function foo(string $string, bool $b = false) : void {
$str = $string;
$string = $string === "hello" ? "foo" : "bar";
echo $string;
echo $str;
}
}',
'output' => '<?php
2020-08-14 21:25:21 +02:00
class A {
public function foo(string $str, bool $b = false) : void {}
}
class AChild extends A {
public function foo(string $str, bool $b = false) : void {
$str_new = $str;
$str = $str === "hello" ? "foo" : "bar";
echo $str;
echo $str_new;
}
}',
'php_version' => '7.1',
'issues_to_fix' => ['ParamNameMismatch'],
'safe_types' => true,
2020-08-14 21:25:21 +02:00
],
'fixIfNewNameAlreadyExists74' => [
'input' => '<?php
2020-08-14 21:25:21 +02:00
class A {
public function foo(string $str, bool $b = false) : void {}
}
class AChild extends A {
public function foo(string $string, bool $b = false) : void {
$str_new = $string;
}
}',
'output' => '<?php
2020-08-14 21:25:21 +02:00
class A {
public function foo(string $str, bool $b = false) : void {}
}
class AChild extends A {
public function foo(string $str, bool $b = false) : void {
$str_new = $str;
}
}',
'php_version' => '7.1',
'issues_to_fix' => ['ParamNameMismatch'],
'safe_types' => true,
2020-08-14 21:25:21 +02:00
],
'noFixIfNewNameAndOldNameAlreadyExists74' => [
'input' => '<?php
2020-08-14 21:25:21 +02:00
class A {
public function foo(string $str, bool $b = false) : void {}
}
class AChild extends A {
public function foo(string $string, bool $b = false) : void {
$str = $string;
$str_new = $string;
}
}',
'output' => '<?php
2020-08-14 21:25:21 +02:00
class A {
public function foo(string $str, bool $b = false) : void {}
}
class AChild extends A {
public function foo(string $string, bool $b = false) : void {
$str = $string;
$str_new = $string;
}
}',
'php_version' => '7.1',
'issues_to_fix' => ['ParamNameMismatch'],
'safe_types' => true,
2020-08-14 21:25:21 +02:00
],
2020-08-14 22:26:55 +02:00
'fixMismatchingParamNameWithDocblockType74' => [
'input' => '<?php
2020-08-14 22:26:55 +02:00
class A {
/**
* @param string $str
*/
public function foo($str, bool $b = false) : void {}
}
class AChild extends A {
/**
* @param string $string
*/
public function foo($string, bool $b = false) : void {}
}',
'output' => '<?php
2020-08-14 22:26:55 +02:00
class A {
/**
* @param string $str
*/
public function foo($str, bool $b = false) : void {}
}
class AChild extends A {
/**
* @param string $str
*/
public function foo($str, bool $b = false) : void {}
}',
'php_version' => '7.1',
'issues_to_fix' => ['ParamNameMismatch'],
'safe_types' => true,
2020-08-14 22:26:55 +02:00
],
2020-08-14 21:25:21 +02:00
];
}
}