WarningsDetectorTest.php 2.2 KB

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