Author: Fabien Potencier (fabien@symfony.com)
Author: Katsuhiro Ogawa (ko.fivestar@gmail.com)
Author: Dariusz Rumiński (dariusz.ruminski@gmail.com)
Inheritance: implements phpcsfixer\ConfigInterface
コード例 #1
0
 public function testResolveRulesWithConfigAndOption()
 {
     $this->config->setRules(array('braces' => true, 'strict_comparison' => false));
     $this->resolver->setOption('rules', 'blank_line_before_return');
     $this->resolver->resolve();
     $this->assertSameRules(array('blank_line_before_return' => true), $this->resolver->getRules());
 }
コード例 #2
0
ファイル: RunnerTest.php プロジェクト: thekabal/tki
 /**
  * @covers PhpCsFixer\Runner\Runner::fix
  * @covers PhpCsFixer\Runner\Runner::fixFile
  */
 public function testThatFixInvalidFileReportsToErrorManager()
 {
     $config = Config::create()->finder(Finder::create()->in(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest' . DIRECTORY_SEPARATOR . 'invalid'))->fixers(array(new Fixer\ClassNotation\VisibilityRequiredFixer(), new Fixer\Import\NoUnusedImportsFixer()))->setUsingCache(false);
     $errorsManager = new ErrorsManager();
     $runner = new Runner($config, new NullDiffer(), null, $errorsManager, new Linter(), true);
     $changed = $runner->fix();
     $pathToInvalidFile = 'somefile.php';
     $this->assertCount(0, $changed);
     $errors = $errorsManager->getInvalidErrors();
     $this->assertCount(1, $errors);
     $error = $errors[0];
     $this->assertInstanceOf('PhpCsFixer\\Error\\Error', $error);
     $this->assertSame(Error::TYPE_INVALID, $error->getType());
     $this->assertSame($pathToInvalidFile, $error->getFilePath());
 }
コード例 #3
0
ファイル: FixerTest.php プロジェクト: cryode/PHP-CS-Fixer
 /**
  * @covers PhpCsFixer\Fixer::fix
  * @covers PhpCsFixer\Fixer::fixFile
  */
 public function testThatFixInvalidFileReportsToErrorManager()
 {
     $fixer = new Fixer();
     $fixer->setLinter(new Linter());
     $config = Config::create()->finder(new \DirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest' . DIRECTORY_SEPARATOR . 'invalid'))->fixers(array(new \PhpCsFixer\Fixer\PSR2\VisibilityRequiredFixer(), new \PhpCsFixer\Fixer\Symfony\NoUnusedImportsFixer()))->setUsingCache(false);
     $changed = $fixer->fix($config, true, true);
     $pathToInvalidFile = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest' . DIRECTORY_SEPARATOR . 'invalid' . DIRECTORY_SEPARATOR . 'somefile.php';
     $this->assertCount(0, $changed);
     $errors = $fixer->getErrorsManager()->getInvalidErrors();
     $this->assertCount(1, $errors);
     $error = $errors[0];
     $this->assertInstanceOf('PhpCsFixer\\Error\\Error', $error);
     $this->assertSame(Error::TYPE_INVALID, $error->getType());
     $this->assertSame($pathToInvalidFile, $error->getFilePath());
 }
コード例 #4
0
 public function __construct(string $name = 'narrowspark')
 {
     parent::__construct($name);
 }
コード例 #5
0
ファイル: Psr0FixerTest.php プロジェクト: cryode/PHP-CS-Fixer
    public function testHandlePartialNamespaces()
    {
        $fixer = $this->getFixer();
        $config = new Config();
        $config->setDir(__DIR__ . '/../../../src/');
        $fixer->setConfig($config);
        $file = $this->getTestFile(__DIR__ . '/../../../src/Fixer/Contrib/Psr0Fixer.php');
        $expected = <<<'EOF'
<?php
namespace Foo\Bar\Baz\Fixer\Contrib;
class Psr0Fixer {}
EOF;
        $input = <<<'EOF'
<?php
namespace Foo\Bar\Baz\FIXER\Contrib;
class Psr0Fixer {}
EOF;
        $this->doTest($expected, $input, $file, $fixer);
        $expected = <<<'EOF'
<?php
namespace /* hi there */ Foo\Bar\Baz\Fixer\Contrib;
class /* hi there */ Psr0Fixer {}
EOF;
        $input = <<<'EOF'
<?php
namespace /* hi there */ Foo\Bar\Baz\FIXER\Contrib;
class /* hi there */ Psr0Fixer {}
EOF;
        $this->doTest($expected, $input, $file, $fixer);
        $config->setDir(__DIR__ . '/../../../src/Fixer/Contrib');
        $expected = <<<'EOF'
<?php
namespace Foo\Bar\Baz;
class Psr0Fixer {}
EOF;
        $this->doTest($expected, null, $file, $fixer);
    }
コード例 #6
0
 /**
  * Use php cs fixer to have a nice formatting of generated files
  *
  * @param string $directory
  *
  * @return array|void
  */
 protected function fix($directory)
 {
     if (!class_exists('PhpCsFixer\\Config')) {
         return;
     }
     /** @var Config $fixerConfig */
     $fixerConfig = $this->fixerConfig;
     if (null === $fixerConfig) {
         $fixerConfig = Config::create()->setRiskyAllowed(true)->setRules(array('@Symfony' => true, 'simplified_null_return' => false, 'concat_without_spaces' => false, 'double_arrow_multiline_whitespaces' => false, 'unalign_equals' => false, 'unalign_double_arrow' => false, 'align_double_arrow' => true, 'align_equals' => true, 'concat_with_spaces' => true, 'ordered_imports' => true, 'phpdoc_order' => true, 'short_array_syntax' => true));
         $resolver = new ConfigurationResolver();
         $resolver->setDefaultConfig($fixerConfig);
         $resolver->resolve();
     }
     $finder = new Finder();
     $finder->in($directory);
     $fixerConfig->finder($finder);
     $fixer = new Fixer();
     return $fixer->fix($fixerConfig);
 }
コード例 #7
0
 /**
  * @param string $header
  */
 public function __construct($header = null)
 {
     parent::__construct('refinery29');
     $this->header = $header;
     $this->setRiskyAllowed(true);
 }
コード例 #8
0
ファイル: ConfigTest.php プロジェクト: amiss18/PHP-CS-Fixer
 /**
  * @dataProvider provideAddCustomFixersCases
  */
 public function testAddCustomFixers($expected, $suite)
 {
     $config = Config::create();
     $config->addCustomFixers($suite);
     $this->assertSame($expected, $config->getCustomFixers());
 }
コード例 #9
0
 public function __construct(string $name = 'narrowspark', string $description = 'The configuration for Narrowspark PHP applications')
 {
     parent::__construct($name, $description);
 }