123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\Alias;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\AbstractFunctionReferenceFixer
- * @covers \PhpCsFixer\Fixer\Alias\PowToExponentiationFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Alias\PowToExponentiationFixer>
- */
- final class PowToExponentiationFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string}>
- */
- public static function provideFixCases(): iterable
- {
- yield [
- '<?php 1**2;',
- '<?php pow(1,2);',
- ];
- yield [
- '<?php 1**2?>',
- '<?php pow(1,2)?>',
- ];
- yield [
- '<?php 1.2**2.3;',
- '<?php pow(1.2,2.3);',
- ];
- yield [
- '<?php echo (-2)** 3;',
- '<?php echo pow(-2, 3);',
- ];
- yield [
- '<?php echo (-2)**( -3);',
- '<?php echo pow(-2, -3);',
- ];
- yield [
- '<?php echo (-2)**( 1-3);',
- '<?php echo pow(-2, 1-3);',
- ];
- yield [
- '<?php echo (-2)**( -1-3);',
- '<?php echo pow(-2, -1-3);',
- ];
- yield [
- '<?php $a = 3** +2;',
- '<?php $a = pow(3, +2);',
- ];
- yield [
- '<?php $a--**++$b;',
- '<?php pow($a--,++$b);',
- ];
- yield [
- '<?php 1//
- #
- **2/**/ /** */;',
- '<?php pow(1//
- #
- ,2/**/ /** */);',
- ];
- yield [
- '<?php /**/a(3/**/,4)**$pow;//pow(1,2);',
- '<?php pow/**/(a(3/**/,4),$pow);//pow(1,2);',
- ];
- yield [
- '<?php \a\pow(5,6);7**8?>',
- '<?php \a\pow(5,6);pow(7,8)?>',
- ];
- yield [
- '<?php (9**10)**(11**12);',
- '<?php pow(pow(9,10),pow(11,12));',
- ];
- yield [
- '<?php (1 + 2)**( 3 * 4);',
- '<?php pow(1 + 2, 3 * 4);',
- ];
- yield [
- '<?php ($b = 4)** 3;',
- '<?php pow($b = 4, 3);',
- ];
- yield [
- '<?php 13**14;',
- '<?php \pow(13,14);',
- ];
- yield [
- '<?php $a = 15 + (16** 17)** 18;',
- '<?php $a = 15 + \pow(\pow(16, 17), 18);',
- ];
- yield [
- '<?php $a = $b** $c($d + 1);',
- '<?php $a = pow($b, $c($d + 1));',
- ];
- yield [
- '<?php $a = ($a+$b)** ($c-$d);',
- '<?php $a = pow(($a+$b), ($c-$d));',
- ];
- yield [
- "<?php \$a = 2**( '1'.'2'). 2;",
- "<?php \$a = pow(2, '1'.'2'). 2;",
- ];
- yield [
- '<?php A::B** 2;\A\B\C::B** 2;',
- '<?php pow(A::B, 2);pow(\A\B\C::B, 2);',
- ];
- yield [
- '<?php $obj->{$bar}** $obj->{$foo};',
- '<?php pow($obj->{$bar}, $obj->{$foo});',
- ];
- yield [
- '<?php echo ${$bar}** ${$foo};',
- '<?php echo pow(${$bar}, ${$foo});',
- ];
- yield [
- '<?php echo $a[2^3+1]->test(1,2)** $b[2+$c];',
- '<?php echo pow($a[2^3+1]->test(1,2), $b[2+$c]);',
- ];
- yield [
- '<?php (int)"2"**(float)"3.0";',
- '<?php pow((int)"2",(float)"3.0");',
- ];
- yield [
- '<?php namespace\Foo::BAR** 2;',
- '<?php pow(namespace\Foo::BAR, 2);',
- ];
- yield [
- '<?php (-1)**( (-2)**( (-3)**( (-4)**( (-5)**( (-6)**( (-7)**( (-8)**( (-9)** 3))))))));',
- '<?php pow(-1, pow(-2, pow(-3, pow(-4, pow(-5, pow(-6, pow(-7, pow(-8, pow(-9, 3)))))))));',
- ];
- yield [
- '<?php
- $z = 1**2;
- $a = 1**( 2**( 3**( 4**( 5**( 6**( 7**( 8**( 9** 3))))))));
- $b = 1**( 2**( 3**( 4**( 5**( 6**( 7**( 8**( 9** 3))))))));
- $d = 1**2;
- ',
- '<?php
- $z = pow(1,2);
- $a = \pow(1, \poW(2, \pOw(3, \pOW(4, \Pow(5, \PoW(6, \POw(7, \POW(8, \pow(9, 3)))))))));
- $b = \pow(1, \pow(2, \pow(3, \pow(4, \pow(5, \pow(6, \pow(7, \pow(8, \pow(9, 3)))))))));
- $d = pow(1,2);
- ',
- ];
- yield [
- '<?php $b = 3** __LINE__;',
- '<?php $b = pow(3, __LINE__);',
- ];
- yield [
- '<?php
- ($a-$b)**(
- ($a-$b)**(
- ($a-$b)**(
- ($a-$b)**(
- ($a-$b)**($a-$b)
- ))));',
- '<?php
- pow($a-$b,
- pow($a-$b,
- pow($a-$b,
- pow($a-$b,
- pow($a-$b,$a-$b)
- ))));',
- ];
- yield [
- '<?php (-1)**( $a** pow(1,2,3, ($a-3)** 4));',
- '<?php pow(-1, pow($a, pow(1,2,3, pow($a-3, 4))));',
- ];
- yield [
- '<?php 1**2 /**/ ?>',
- '<?php pow(1,2) /**/ ?>',
- ];
- yield [
- '<?php ($$a)**( $$b);',
- '<?php pow($$a, $$b);',
- ];
- yield [
- '<?php [1, 2, 3, 4][$x]** 2;',
- '<?php pow([1, 2, 3, 4][$x], 2);',
- ];
- yield [
- '<?php echo +$a** 2;',
- '<?php echo pow(+$a, 2);',
- ];
- yield [
- '<?php
- interface Test
- {
- public function pow($a, $b);
- }',
- ];
- yield [
- '<?php
- interface Test
- {
- public function &pow($a, $b);
- }',
- ];
- yield [
- '<?php echo $a[1]** $b[2+5];',
- '<?php echo pow($a[1], $b[2+5]);',
- ];
- yield [
- '<?php pow($b, ...$a);',
- ];
- yield [
- '<?php echo +$a** 2;',
- '<?php echo pow(+$a, 2,);',
- ];
- yield [
- '<?php echo +$a** 2/*1*//*2*/;',
- '<?php echo pow(+$a, 2/*1*/,/*2*/);',
- ];
- yield [
- '<?php echo 10_0** 2;',
- '<?php echo pow(10_0, 2);',
- ];
- yield [
- '<?php pow(); ++$a;++$a;++$a;++$a;++$a;++$a;// pow(1,2);',
- ];
- yield [
- '<?php pow(5); ++$a;++$a;++$a;++$a;++$a;++$a;# pow(1,2);',
- ];
- yield [
- '<?php pow(5,1,1); ++$a;++$a;++$a;++$a;++$a;++$a;/* pow(1,2); */',
- ];
- yield [
- '<?php \a\pow(4,3); ++$a;++$a;++$a;++$a;++$a;++$a;/** pow(1,2); */',
- ];
- }
- /**
- * @dataProvider provideFixPre80Cases
- *
- * @requires PHP <8.0
- */
- public function testFixPre80(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{string, string}>
- */
- public static function provideFixPre80Cases(): iterable
- {
- yield [
- '<?php echo $a{1}** $b{2+5};',
- '<?php echo pow($a{1}, $b{2+5});',
- ];
- }
- /**
- * @requires PHP 8.0
- *
- * @dataProvider provideFix80Cases
- */
- public function testFix80(string $expected, string $input): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{string, string}>
- */
- public static function provideFix80Cases(): iterable
- {
- yield [
- '<?php echo $a[2^3+1]?->test(1,2)** $b[2+$c];',
- '<?php echo pow($a[2^3+1]?->test(1,2), $b[2+$c]);',
- ];
- }
- }
|