|
@@ -22,9 +22,9 @@ use PhpCsFixer\Test\AbstractFixerTestCase;
|
|
|
final class NewWithBracesFixerTest extends AbstractFixerTestCase
|
|
|
{
|
|
|
/**
|
|
|
- * @dataProvider provideStandardCases
|
|
|
+ * @dataProvider provideCases
|
|
|
*/
|
|
|
- public function testStandard($expected, $input = null)
|
|
|
+ public function testFix($expected, $input = null)
|
|
|
{
|
|
|
$this->doTest($expected, $input);
|
|
|
}
|
|
@@ -33,12 +33,30 @@ final class NewWithBracesFixerTest extends AbstractFixerTestCase
|
|
|
* @dataProvider provide54Cases
|
|
|
* @requires PHP 5.4
|
|
|
*/
|
|
|
- public function test54($expected, $input = null)
|
|
|
+ public function testFix54($expected, $input = null)
|
|
|
{
|
|
|
$this->doTest($expected, $input);
|
|
|
}
|
|
|
|
|
|
- public function provideStandardCases()
|
|
|
+ /**
|
|
|
+ * @dataProvider provide56Cases
|
|
|
+ * @requires PHP 5.6
|
|
|
+ */
|
|
|
+ public function testFix56($expected, $input = null)
|
|
|
+ {
|
|
|
+ $this->doTest($expected, $input);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dataProvider provide70Cases
|
|
|
+ * @requires PHP 7.0
|
|
|
+ */
|
|
|
+ public function testFix70($expected, $input = null)
|
|
|
+ {
|
|
|
+ $this->doTest($expected, $input);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function provideCases()
|
|
|
{
|
|
|
return array(
|
|
|
array(
|
|
@@ -126,6 +144,104 @@ final class NewWithBracesFixerTest extends AbstractFixerTestCase
|
|
|
'<?php $b = new \StdClass() /**/?>',
|
|
|
'<?php $b = new \StdClass /**/?>',
|
|
|
),
|
|
|
+ array(
|
|
|
+ '<?php $a = new Foo() instanceof Foo;',
|
|
|
+ '<?php $a = new Foo instanceof Foo;',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ $a = new Foo() + 1;
|
|
|
+ $a = new Foo() - 1;
|
|
|
+ $a = new Foo() * 1;
|
|
|
+ $a = new Foo() / 1;
|
|
|
+ $a = new Foo() % 1;
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ $a = new Foo + 1;
|
|
|
+ $a = new Foo - 1;
|
|
|
+ $a = new Foo * 1;
|
|
|
+ $a = new Foo / 1;
|
|
|
+ $a = new Foo % 1;
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ $a = new Foo()++;
|
|
|
+ $a = new Foo()--;
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ $a = new Foo++;
|
|
|
+ $a = new Foo--;
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ $a = new Foo() & 1;
|
|
|
+ $a = new Foo() | 1;
|
|
|
+ $a = new Foo() ^ 1;
|
|
|
+ $a = new Foo() << 1;
|
|
|
+ $a = new Foo() >> 1;
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ $a = new Foo & 1;
|
|
|
+ $a = new Foo | 1;
|
|
|
+ $a = new Foo ^ 1;
|
|
|
+ $a = new Foo << 1;
|
|
|
+ $a = new Foo >> 1;
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ $a = new Foo() and 1;
|
|
|
+ $a = new Foo() or 1;
|
|
|
+ $a = new Foo() xor 1;
|
|
|
+ $a = new Foo() && 1;
|
|
|
+ $a = new Foo() || 1;
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ $a = new Foo and 1;
|
|
|
+ $a = new Foo or 1;
|
|
|
+ $a = new Foo xor 1;
|
|
|
+ $a = new Foo && 1;
|
|
|
+ $a = new Foo || 1;
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ if (new DateTime() > $this->startDate) {}
|
|
|
+ if (new DateTime() >= $this->startDate) {}
|
|
|
+ if (new DateTime() < $this->startDate) {}
|
|
|
+ if (new DateTime() <= $this->startDate) {}
|
|
|
+ if (new DateTime() == $this->startDate) {}
|
|
|
+ if (new DateTime() != $this->startDate) {}
|
|
|
+ if (new DateTime() <> $this->startDate) {}
|
|
|
+ if (new DateTime() === $this->startDate) {}
|
|
|
+ if (new DateTime() !== $this->startDate) {}
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ if (new DateTime > $this->startDate) {}
|
|
|
+ if (new DateTime >= $this->startDate) {}
|
|
|
+ if (new DateTime < $this->startDate) {}
|
|
|
+ if (new DateTime <= $this->startDate) {}
|
|
|
+ if (new DateTime == $this->startDate) {}
|
|
|
+ if (new DateTime != $this->startDate) {}
|
|
|
+ if (new DateTime <> $this->startDate) {}
|
|
|
+ if (new DateTime === $this->startDate) {}
|
|
|
+ if (new DateTime !== $this->startDate) {}
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php $a = new \stdClass() ? $b : $c;',
|
|
|
+ '<?php $a = new \stdClass ? $b : $c;',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php foreach (new Collection() as $x) {}',
|
|
|
+ '<?php foreach (new Collection as $x) {}',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ '<?php $a = [(string) new Foo() => 1];',
|
|
|
+ '<?php $a = [(string) new Foo => 1];',
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -142,4 +258,32 @@ final class NewWithBracesFixerTest extends AbstractFixerTestCase
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ public function provide56Cases()
|
|
|
+ {
|
|
|
+ return array(
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ $a = new Foo() ** 1;
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ $a = new Foo ** 1;
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function provide70Cases()
|
|
|
+ {
|
|
|
+ return array(
|
|
|
+ array(
|
|
|
+ '<?php
|
|
|
+ $a = new Foo() <=> 1;
|
|
|
+ ',
|
|
|
+ '<?php
|
|
|
+ $a = new Foo <=> 1;
|
|
|
+ ',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|