123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- /*
- * 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\FunctionNotation;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer
- */
- final class SingleLineThrowFixerTest extends AbstractFixerTestCase
- {
- /**
- * @param string $expected
- * @param null|string $input
- *
- * @dataProvider provideFixCases
- */
- public function testFix($expected, $input = null)
- {
- $this->doTest($expected, $input);
- }
- public function provideFixCases()
- {
- yield ['<?php throw new Exception; foo(
- "Foo"
- );'];
- yield ['<?php throw new $exceptionName; foo(
- "Foo"
- );'];
- yield ['<?php throw $exception; foo(
- "Foo"
- );'];
- yield ['<?php throw new Exception("Foo", 0);'];
- yield [
- '<?php throw new Exception("Foo", 0);',
- '<?php throw new Exception(
- "Foo",
- 0
- );',
- ];
- yield [
- '<?php throw new Exception("Foo" . "Bar");',
- '<?php throw new Exception(
- "Foo"
- .
- "Bar"
- );',
- ];
- yield [
- '<?php throw new Exception(new ExceptionReport("Foo"), 0);',
- '<?php throw new Exception(
- new
- ExceptionReport("Foo"),
- 0
- );',
- ];
- yield [
- '<?php throw new Exception(sprintf("Error with number %s", 42));',
- '<?php throw new Exception(sprintf(
- "Error with number %s",
- 42
- ));',
- ];
- yield [
- '<?php throw new SomeVendor\\Exception("Foo");',
- '<?php throw new SomeVendor\\Exception(
- "Foo"
- );',
- ];
- yield [
- '<?php throw new \SomeVendor\\Exception("Foo");',
- '<?php throw new \SomeVendor\\Exception(
- "Foo"
- );',
- ];
- yield [
- '<?php throw $this->exceptionFactory->createAnException("Foo");',
- '<?php throw $this
- ->exceptionFactory
- ->createAnException(
- "Foo"
- );',
- ];
- yield [
- '<?php throw $this->getExceptionFactory()->createAnException("Foo");',
- '<?php throw $this
- ->getExceptionFactory()
- ->createAnException(
- "Foo"
- );',
- ];
- yield [
- '<?php throw $this->getExceptionFactory()->createAnException(function ($x, $y) { return $x === $y + 2; });',
- '<?php throw $this
- ->getExceptionFactory()
- ->createAnException(
- function
- (
- $x,
- $y
- )
- {
- return $x === $y + 2
- ;
- }
- );',
- ];
- yield [
- '<?php throw ExceptionFactory::createAnException("Foo");',
- '<?php throw ExceptionFactory
- ::
- createAnException(
- "Foo"
- );',
- ];
- yield [
- '<?php throw new Exception("Foo", 0);',
- '<?php throw
- new
- Exception
- (
- "Foo"
- ,
- 0
- );',
- ];
- yield [
- '<?php throw new $exceptionName("Foo");',
- '<?php throw new $exceptionName(
- "Foo"
- );',
- ];
- yield [
- '<?php throw new $exceptions[4];',
- '<?php throw new $exceptions[
- 4
- ];',
- ];
- yield [
- '<?php throw clone $exceptionName("Foo");',
- '<?php throw clone $exceptionName(
- "Foo"
- );',
- ];
- yield [
- '<?php throw new WeirdException("Foo", -20, "An elephant", 1, 2, 3, 4, 5, 6, 7, 8);',
- '<?php throw new WeirdException("Foo", -20, "An elephant",
- 1,
- 2,
- 3, 4, 5, 6, 7, 8
- );',
- ];
- yield [
- '<?php
- if ($foo) {
- throw new Exception("It is foo", 1);
- } else {
- throw new \Exception("It is not foo", 0);
- }
- ',
- '<?php
- if ($foo) {
- throw new Exception(
- "It is foo",
- 1
- );
- } else {
- throw new \Exception(
- "It is not foo", 0
- );
- }
- ',
- ];
- yield [
- '<?php throw new Exception( /* 0 */"Foo", /* 1 */0 /* 2 */); //3',
- '<?php throw new Exception( // 0
- "Foo", // 1
- 0 // 2
- ); //3',
- ];
- yield [
- '<?php throw new Exception( 0, /* 1 2 3 */ /*4*/ "Foo", /*5*/ /*6*/0 /*7*/);',
- '<?php throw new Exception( 0, /*
- 1
- 2
- 3
- */
- /*4*/ "Foo", /*5*/
- /*6*/0 /*7*/);',
- ];
- yield [
- '<?php throw new Exception( /* 0 */${"Foo" /* a */}, /*b */fnx/*c */(/*d */0/*e */)/*f */);',
- '<?php throw new Exception( // 0
- ${"Foo"
- # a
- }, #b
- fnx#c
- (#d
- 0#e
- )#f
- );',
- ];
- yield [
- "<?php throw new Exception('a'. 1);",
- "<?php throw new Exception('a'.
- 1
- );",
- ];
- }
- }
|