ErrorsManagerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\Error;
  12. use PhpCsFixer\Error\Error;
  13. use PhpCsFixer\Error\ErrorsManager;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Error\ErrorsManager
  19. */
  20. final class ErrorsManagerTest extends TestCase
  21. {
  22. public function testDefaults()
  23. {
  24. $errorsManager = new ErrorsManager();
  25. $this->assertTrue($errorsManager->isEmpty());
  26. $this->assertEmpty($errorsManager->getInvalidErrors());
  27. $this->assertEmpty($errorsManager->getExceptionErrors());
  28. $this->assertEmpty($errorsManager->getLintErrors());
  29. }
  30. public function testThatCanReportAndRetrieveInvalidErrors()
  31. {
  32. $error = new Error(
  33. Error::TYPE_INVALID,
  34. 'foo.php'
  35. );
  36. $errorsManager = new ErrorsManager();
  37. $errorsManager->report($error);
  38. $this->assertFalse($errorsManager->isEmpty());
  39. $errors = $errorsManager->getInvalidErrors();
  40. $this->assertInternalType('array', $errors);
  41. $this->assertCount(1, $errors);
  42. $this->assertSame($error, array_shift($errors));
  43. $this->assertCount(0, $errorsManager->getExceptionErrors());
  44. $this->assertCount(0, $errorsManager->getLintErrors());
  45. }
  46. public function testThatCanReportAndRetrieveExceptionErrors()
  47. {
  48. $error = new Error(
  49. Error::TYPE_EXCEPTION,
  50. 'foo.php'
  51. );
  52. $errorsManager = new ErrorsManager();
  53. $errorsManager->report($error);
  54. $this->assertFalse($errorsManager->isEmpty());
  55. $errors = $errorsManager->getExceptionErrors();
  56. $this->assertInternalType('array', $errors);
  57. $this->assertCount(1, $errors);
  58. $this->assertSame($error, array_shift($errors));
  59. $this->assertCount(0, $errorsManager->getInvalidErrors());
  60. $this->assertCount(0, $errorsManager->getLintErrors());
  61. }
  62. public function testThatCanReportAndRetrieveInvalidFileErrors()
  63. {
  64. $error = new Error(
  65. Error::TYPE_LINT,
  66. 'foo.php'
  67. );
  68. $errorsManager = new ErrorsManager();
  69. $errorsManager->report($error);
  70. $this->assertFalse($errorsManager->isEmpty());
  71. $errors = $errorsManager->getLintErrors();
  72. $this->assertInternalType('array', $errors);
  73. $this->assertCount(1, $errors);
  74. $this->assertSame($error, array_shift($errors));
  75. $this->assertCount(0, $errorsManager->getInvalidErrors());
  76. $this->assertCount(0, $errorsManager->getExceptionErrors());
  77. }
  78. }