WarningsDetectorTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Console;
  12. use PhpCsFixer\Console\WarningsDetector;
  13. use PhpCsFixer\Tests\TestCase;
  14. /**
  15. * @author ntzm
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Console\WarningsDetector
  20. */
  21. final class WarningsDetectorTest extends TestCase
  22. {
  23. public function testDetectOldVendorNotInstalledByComposer()
  24. {
  25. $toolInfo = $this->prophesize(\PhpCsFixer\ToolInfoInterface::class);
  26. $toolInfo->isInstalledByComposer()->willReturn(false);
  27. $warningsDetector = new WarningsDetector($toolInfo->reveal());
  28. $warningsDetector->detectOldVendor();
  29. static::assertSame([], $warningsDetector->getWarnings());
  30. }
  31. public function testDetectOldVendorNotLegacyPackage()
  32. {
  33. $toolInfo = $this->prophesize(\PhpCsFixer\ToolInfoInterface::class);
  34. $toolInfo->isInstalledByComposer()->willReturn(false);
  35. $toolInfo->getComposerInstallationDetails()->willReturn([
  36. 'name' => 'friendsofphp/php-cs-fixer',
  37. ]);
  38. $warningsDetector = new WarningsDetector($toolInfo->reveal());
  39. $warningsDetector->detectOldVendor();
  40. static::assertSame([], $warningsDetector->getWarnings());
  41. }
  42. public function testDetectOldVendorLegacyPackage()
  43. {
  44. $toolInfo = $this->prophesize(\PhpCsFixer\ToolInfoInterface::class);
  45. $toolInfo->isInstalledByComposer()->willReturn(true);
  46. $toolInfo->getComposerInstallationDetails()->willReturn([
  47. 'name' => 'fabpot/php-cs-fixer',
  48. ]);
  49. $warningsDetector = new WarningsDetector($toolInfo->reveal());
  50. $warningsDetector->detectOldVendor();
  51. static::assertSame([
  52. 'You are running PHP CS Fixer installed with old vendor `fabpot/php-cs-fixer`. Please update to `friendsofphp/php-cs-fixer`.',
  53. 'If you need help while solving warnings, ask at https://gitter.im/PHP-CS-Fixer, we will help you!',
  54. ], $warningsDetector->getWarnings());
  55. }
  56. }