|
@@ -30,6 +30,7 @@ final class NoMixedEchoPrintFixerTest extends AbstractFixerTestCase
|
|
|
* @param null|string $input
|
|
|
*
|
|
|
* @dataProvider provideEchoToPrintFixCases
|
|
|
+ * @dataProvider provideEchoToPrintFixNewCases
|
|
|
*/
|
|
|
public function testFixEchoToPrint($expected, $input = null)
|
|
|
{
|
|
@@ -129,21 +130,28 @@ final class NoMixedEchoPrintFixerTest extends AbstractFixerTestCase
|
|
|
echo "bar";
|
|
|
',
|
|
|
],
|
|
|
- [
|
|
|
- "<div><?php print 'foo' ?></div>",
|
|
|
- "<div><?php echo 'foo' ?></div>",
|
|
|
- ],
|
|
|
[
|
|
|
'<?=$foo?>',
|
|
|
],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public static function provideEchoToPrintFixNewCases()
|
|
|
+ {
|
|
|
+ foreach (self::getCodeSnippetsToConvertBothWays() as $name => $codeSnippet) {
|
|
|
+ yield [
|
|
|
+ sprintf($codeSnippet, 'print'),
|
|
|
+ sprintf($codeSnippet, 'echo'),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param string $expected
|
|
|
* @param null|string $input
|
|
|
*
|
|
|
* @dataProvider providePrintToEchoFixCases
|
|
|
+ * @dataProvider providePrintToEchoFixNewCases
|
|
|
*/
|
|
|
public function testFixPrintToEcho($expected, $input = null)
|
|
|
{
|
|
@@ -267,13 +275,19 @@ final class NoMixedEchoPrintFixerTest extends AbstractFixerTestCase
|
|
|
print "bar";
|
|
|
',
|
|
|
],
|
|
|
- [
|
|
|
- "<div><?php echo 'foo' ?></div>",
|
|
|
- "<div><?php print 'foo' ?></div>",
|
|
|
- ],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public static function providePrintToEchoFixNewCases()
|
|
|
+ {
|
|
|
+ foreach (self::getCodeSnippetsToConvertBothWays() as $name => $codeSnippet) {
|
|
|
+ yield [
|
|
|
+ sprintf($codeSnippet, 'echo'),
|
|
|
+ sprintf($codeSnippet, 'print'),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @group legacy
|
|
|
* @expectedDeprecation Passing NULL to set default configuration is deprecated and will not be supported in 3.0, use an empty array instead.
|
|
@@ -335,4 +349,25 @@ final class NoMixedEchoPrintFixerTest extends AbstractFixerTestCase
|
|
|
|
|
|
static::assertSame($expected, $reflectionProperty->getValue($fixer));
|
|
|
}
|
|
|
+
|
|
|
+ private static function getCodeSnippetsToConvertBothWays()
|
|
|
+ {
|
|
|
+ yield 'inside of HTML' => '<div><?php %1$s "foo" ?></div>';
|
|
|
+
|
|
|
+ yield 'foreach without curly brackets' => '<?php
|
|
|
+ %1$s "There will be foos: ";
|
|
|
+ foreach ($foos as $foo)
|
|
|
+ %1$s $foo;
|
|
|
+ %1$s "End of foos";
|
|
|
+ ';
|
|
|
+
|
|
|
+ yield 'if and else without curly brackets' => '<?php
|
|
|
+ if ($foo)
|
|
|
+ %1$s "One";
|
|
|
+ elseif ($bar)
|
|
|
+ %1$s "Two";
|
|
|
+ else
|
|
|
+ %1$s "Three";
|
|
|
+ ';
|
|
|
+ }
|
|
|
}
|