ConfigTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Tests;
  11. use Symfony\Component\Finder\Finder as SymfonyFinder;
  12. use Symfony\CS\Config;
  13. use Symfony\CS\Finder;
  14. /**
  15. * @internal
  16. */
  17. final class ConfigTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testThatFinderWorksWithDirSetOnConfig()
  20. {
  21. $config = Config::create()->setDir(__DIR__.'/Fixtures/FinderDirectory');
  22. $iterator = $config->getFinder()->getIterator();
  23. $this->assertSame(1, count($iterator));
  24. $iterator->rewind();
  25. $this->assertSame('somefile.php', $iterator->current()->getFilename());
  26. }
  27. public function testThatCustomFinderWorks()
  28. {
  29. $finder = Finder::create();
  30. $finder->in(__DIR__.'/Fixtures/FinderDirectory');
  31. $config = Config::create()->finder($finder);
  32. $iterator = $config->getFinder()->getIterator();
  33. $this->assertSame(1, count($iterator));
  34. $iterator->rewind();
  35. $this->assertSame('somefile.php', $iterator->current()->getFilename());
  36. }
  37. public function testThatCustomSymfonyFinderWorks()
  38. {
  39. $finder = SymfonyFinder::create();
  40. $finder->in(__DIR__.'/Fixtures/FinderDirectory');
  41. $config = Config::create()->finder($finder);
  42. $iterator = $config->getFinder()->getIterator();
  43. $this->assertSame(1, count($iterator));
  44. $iterator->rewind();
  45. $this->assertSame('somefile.php', $iterator->current()->getFilename());
  46. }
  47. public function testThatCacheFileHasDefaultValue()
  48. {
  49. $config = new Config();
  50. $this->assertSame('.php_cs.cache', $config->getCacheFile());
  51. }
  52. public function testThatCacheFileCanBeMutated()
  53. {
  54. $cacheFile = 'some-directory/some.file';
  55. $config = new Config();
  56. $config->setCacheFile($cacheFile);
  57. $this->assertSame($cacheFile, $config->getCacheFile());
  58. }
  59. public function testThatMutatorHasFluentInterface()
  60. {
  61. $config = new Config();
  62. $this->assertSame($config, $config->setCacheFile('some-directory/some.file'));
  63. }
  64. /**
  65. * @expectedException \InvalidArgumentException
  66. * @expectedExceptionMessageRegExp /^Argument must be an array or a Traversable, got "\w+"\.$/
  67. */
  68. public function testAddCustomFixersWithInvalidArgument()
  69. {
  70. $config = Config::create();
  71. $config->addCustomFixers('foo');
  72. }
  73. /**
  74. * @dataProvider provideAddCustomFixersCases
  75. */
  76. public function testAddCustomFixers($expected, $suite)
  77. {
  78. $config = Config::create();
  79. $config->addCustomFixers($suite);
  80. $this->assertSame($expected, $config->getCustomFixers());
  81. }
  82. /**
  83. * @return array
  84. */
  85. public function provideAddCustomFixersCases()
  86. {
  87. $fixers = array(
  88. new \Symfony\CS\Fixer\Symfony\NoWhitespaceBeforeCommaInArrayFixer(),
  89. new \Symfony\CS\Fixer\Symfony\IncludeFixer(),
  90. );
  91. $cases = array(
  92. array($fixers, $fixers),
  93. array($fixers, new \ArrayIterator($fixers)),
  94. );
  95. return $cases;
  96. }
  97. }