ErrorHandlerTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Util;
  12. use Composer\Util\ErrorHandler;
  13. use Composer\Test\TestCase;
  14. /**
  15. * ErrorHandler test case
  16. */
  17. class ErrorHandlerTest extends TestCase
  18. {
  19. public function setUp()
  20. {
  21. ErrorHandler::register();
  22. }
  23. public function tearDown()
  24. {
  25. restore_error_handler();
  26. }
  27. /**
  28. * Test ErrorHandler handles notices
  29. */
  30. public function testErrorHandlerCaptureNotice()
  31. {
  32. $this->setExpectedException('\ErrorException', 'Undefined index: baz');
  33. $array = array('foo' => 'bar');
  34. $array['baz'];
  35. }
  36. /**
  37. * Test ErrorHandler handles warnings
  38. */
  39. public function testErrorHandlerCaptureWarning()
  40. {
  41. if (PHP_VERSION_ID >= 80000) {
  42. $this->setExpectedException('TypeError', 'array_merge');
  43. } else {
  44. $this->setExpectedException('ErrorException', 'array_merge');
  45. }
  46. array_merge(array(), 'string');
  47. }
  48. /**
  49. * Test ErrorHandler handles warnings
  50. * @doesNotPerformAssertions
  51. */
  52. public function testErrorHandlerRespectsAtOperator()
  53. {
  54. @trigger_error('test', E_USER_NOTICE);
  55. }
  56. }