2
0

UtilsTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 string $expected
  15. * @param string $input
  16. * @dataProvider providePathsToCanonicalize
  17. */
  18. public function testCanonicalizePath($expected, $input)
  19. {
  20. $this->assertSame($expected, Utils::canonicalizePath($input));
  21. }
  22. public function providePathsToCanonicalize()
  23. {
  24. return array(
  25. array('/foo/bar', '/foo/bar'),
  26. array('file://'.getcwd().'/bla', 'file://bla'),
  27. array(getcwd().'/bla', 'bla'),
  28. array(getcwd().'/./bla', './bla'),
  29. array('file:///foo/bar', 'file:///foo/bar'),
  30. array('any://foo', 'any://foo'),
  31. array('\\\\network\path', '\\\\network\path'),
  32. );
  33. }
  34. /**
  35. * @param int $code
  36. * @param string $msg
  37. * @dataProvider providesHandleJsonErrorFailure
  38. */
  39. public function testHandleJsonErrorFailure($code, $msg)
  40. {
  41. $this->setExpectedException('RuntimeException', $msg);
  42. Utils::handleJsonError($code, 'faked');
  43. }
  44. public function providesHandleJsonErrorFailure()
  45. {
  46. return array(
  47. 'depth' => array(JSON_ERROR_DEPTH, 'Maximum stack depth exceeded'),
  48. 'state' => array(JSON_ERROR_STATE_MISMATCH, 'Underflow or the modes mismatch'),
  49. 'ctrl' => array(JSON_ERROR_CTRL_CHAR, 'Unexpected control character found'),
  50. 'default' => array(-1, 'Unknown error'),
  51. );
  52. }
  53. /**
  54. * @param mixed $in Input
  55. * @param mixed $expect Expected output
  56. * @covers Monolog\Formatter\NormalizerFormatter::detectAndCleanUtf8
  57. * @dataProvider providesDetectAndCleanUtf8
  58. */
  59. public function testDetectAndCleanUtf8($in, $expect)
  60. {
  61. Utils::detectAndCleanUtf8($in);
  62. $this->assertSame($expect, $in);
  63. }
  64. public function providesDetectAndCleanUtf8()
  65. {
  66. $obj = new \stdClass;
  67. return array(
  68. 'null' => array(null, null),
  69. 'int' => array(123, 123),
  70. 'float' => array(123.45, 123.45),
  71. 'bool false' => array(false, false),
  72. 'bool true' => array(true, true),
  73. 'ascii string' => array('abcdef', 'abcdef'),
  74. 'latin9 string' => array("\xB1\x31\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE\xFF", '±1€ŠšŽžŒœŸÿ'),
  75. 'unicode string' => array('¤¦¨´¸¼½¾€ŠšŽžŒœŸ', '¤¦¨´¸¼½¾€ŠšŽžŒœŸ'),
  76. 'empty array' => array(array(), array()),
  77. 'array' => array(array('abcdef'), array('abcdef')),
  78. 'object' => array($obj, $obj),
  79. );
  80. }
  81. }