ErrorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 testConstructorSetsValues(): void
  23. {
  24. $type = 123;
  25. $filePath = 'foo.php';
  26. $error = new Error(
  27. $type,
  28. $filePath
  29. );
  30. self::assertSame($type, $error->getType());
  31. self::assertSame($filePath, $error->getFilePath());
  32. self::assertNull($error->getSource());
  33. self::assertSame([], $error->getAppliedFixers());
  34. self::assertNull($error->getDiff());
  35. }
  36. public function testConstructorSetsValues2(): void
  37. {
  38. $type = 456;
  39. $filePath = __FILE__;
  40. $source = new \Exception();
  41. $appliedFixers = ['some_rule'];
  42. $diff = '__diff__';
  43. $error = new Error(
  44. $type,
  45. $filePath,
  46. $source,
  47. $appliedFixers,
  48. $diff
  49. );
  50. self::assertSame($type, $error->getType());
  51. self::assertSame($filePath, $error->getFilePath());
  52. self::assertSame($source, $error->getSource());
  53. self::assertSame($appliedFixers, $error->getAppliedFixers());
  54. self::assertSame($diff, $error->getDiff());
  55. }
  56. }