public function testThatCustomSymfonyFinderWorks() { $finder = new SymfonyFinder(); $finder->in(__DIR__ . '/Fixtures/FinderDirectory'); $config = Config::create()->finder($finder); $iterator = $config->getFinder()->getIterator(); $this->assertSame(1, count($iterator)); $iterator->rewind(); $this->assertSame('somefile.php', $iterator->current()->getFilename()); }
/** * @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()); }
/** * @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()); }
/** * 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); }
/** * @dataProvider provideAddCustomFixersCases */ public function testAddCustomFixers($expected, $suite) { $config = Config::create(); $config->addCustomFixers($suite); $this->assertSame($expected, $config->getCustomFixers()); }