UtilsTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog;
  11. class UtilsTest extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @param int $code
  15. * @param string $msg
  16. * @dataProvider providesHandleJsonErrorFailure
  17. */
  18. public function testHandleJsonErrorFailure($code, $msg)
  19. {
  20. $this->setExpectedException('RuntimeException', $msg);
  21. Utils::handleJsonError($code, 'faked');
  22. }
  23. public function providesHandleJsonErrorFailure()
  24. {
  25. return array(
  26. 'depth' => array(JSON_ERROR_DEPTH, 'Maximum stack depth exceeded'),
  27. 'state' => array(JSON_ERROR_STATE_MISMATCH, 'Underflow or the modes mismatch'),
  28. 'ctrl' => array(JSON_ERROR_CTRL_CHAR, 'Unexpected control character found'),
  29. 'default' => array(-1, 'Unknown error'),
  30. );
  31. }
  32. /**
  33. * @param mixed $in Input
  34. * @param mixed $expect Expected output
  35. * @covers Monolog\Formatter\NormalizerFormatter::detectAndCleanUtf8
  36. * @dataProvider providesDetectAndCleanUtf8
  37. */
  38. public function testDetectAndCleanUtf8($in, $expect)
  39. {
  40. Utils::detectAndCleanUtf8($in);
  41. $this->assertSame($expect, $in);
  42. }
  43. public function providesDetectAndCleanUtf8()
  44. {
  45. $obj = new \stdClass;
  46. return array(
  47. 'null' => array(null, null),
  48. 'int' => array(123, 123),
  49. 'float' => array(123.45, 123.45),
  50. 'bool false' => array(false, false),
  51. 'bool true' => array(true, true),
  52. 'ascii string' => array('abcdef', 'abcdef'),
  53. 'latin9 string' => array("\xB1\x31\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE\xFF", '±1€ŠšŽžŒœŸÿ'),
  54. 'unicode string' => array('¤¦¨´¸¼½¾€ŠšŽžŒœŸ', '¤¦¨´¸¼½¾€ŠšŽžŒœŸ'),
  55. 'empty array' => array(array(), array()),
  56. 'array' => array(array('abcdef'), array('abcdef')),
  57. 'object' => array($obj, $obj),
  58. );
  59. }
  60. }