ErrorTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Error;
  13. use PhpCsFixer\Error\Error;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Error\Error
  19. */
  20. final class ErrorTest extends TestCase
  21. {
  22. public function testThatErrorTypeConstantValuesAreDifferent(): void
  23. {
  24. self::assertNotSame(Error::TYPE_INVALID, Error::TYPE_EXCEPTION);
  25. self::assertNotSame(Error::TYPE_EXCEPTION, Error::TYPE_LINT);
  26. }
  27. public function testConstructorSetsValues(): void
  28. {
  29. $type = 123;
  30. $filePath = 'foo.php';
  31. $error = new Error(
  32. $type,
  33. $filePath
  34. );
  35. self::assertSame($type, $error->getType());
  36. self::assertSame($filePath, $error->getFilePath());
  37. self::assertNull($error->getSource());
  38. self::assertSame([], $error->getAppliedFixers());
  39. self::assertNull($error->getDiff());
  40. }
  41. public function testConstructorSetsValues2(): void
  42. {
  43. $type = 456;
  44. $filePath = __FILE__;
  45. $source = new \Exception();
  46. $appliedFixers = ['some_rule'];
  47. $diff = '__diff__';
  48. $error = new Error(
  49. $type,
  50. $filePath,
  51. $source,
  52. $appliedFixers,
  53. $diff
  54. );
  55. self::assertSame($type, $error->getType());
  56. self::assertSame($filePath, $error->getFilePath());
  57. self::assertSame($source, $error->getSource());
  58. self::assertSame($appliedFixers, $error->getAppliedFixers());
  59. self::assertSame($diff, $error->getDiff());
  60. }
  61. }