PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpunit/phpunit/PHPUnit/Framework/Constraint/JsonMatches/ErrorMessageProvider.php

https://bitbucket.org/sklyarov_ivan/trap
PHP | 106 lines | 38 code | 2 blank | 66 comment | 2 complexity | ba1096b73a2c000b4a6551b97803d695 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.de>.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * Neither the name of Sebastian Bergmann nor the names of his
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @package PHPUnit
  38. * @subpackage Framework_Constraint
  39. * @author Bastian Feder <php@bastian-feder.de>
  40. * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
  41. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause
  42. * @link http://www.phpunit.de/
  43. * @since File available since Release 3.7.0
  44. */
  45. /**
  46. * Provides human readable messages for each JSON error.
  47. *
  48. * @package PHPUnit
  49. * @subpackage Framework_Constraint
  50. * @author Bastian Feder <php@bastian-feder.de>
  51. * @copyright 2011 Bastian Feder <php@bastian-feder.de>
  52. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause
  53. * @link http://www.phpunit.de/
  54. * @since Class available since Release 3.7.0
  55. */
  56. class PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider
  57. {
  58. /**
  59. * Translatets accourd JSON error to a human readable string.
  60. *
  61. * @param string $error
  62. * @return string
  63. */
  64. public static function determineJsonError($error, $prefix = '')
  65. {
  66. switch (strtoupper($error)) {
  67. case 'JSON_ERROR_NONE':
  68. return;
  69. case 'JSON_ERROR_DEPTH':
  70. return $prefix . 'Maximum stack depth exceeded';
  71. case 'JSON_ERROR_STATE_MISMATCH':
  72. return $prefix . 'Underflow or the modes mismatch';
  73. case 'JSON_ERROR_CTRL_CHAR':
  74. return $prefix . 'Unexpected control character found';
  75. case 'JSON_ERROR_SYNTAX':
  76. return $prefix . 'Syntax error, malformed JSON';
  77. case 'JSON_ERROR_UTF8':
  78. return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded';
  79. default:
  80. return $prefix . 'Unknown error';
  81. }
  82. }
  83. /**
  84. * Translates a given type to a human readable message prefix.
  85. *
  86. * @param string $type
  87. * @return string
  88. */
  89. public static function translateTypeToPrefix($type)
  90. {
  91. switch (strtolower($type)) {
  92. case 'expected':
  93. $prefix = 'Expected value JSON decode error - ';
  94. break;
  95. case 'actual':
  96. $prefix = 'Actual value JSON decode error - ';
  97. break;
  98. default:
  99. $prefix = '';
  100. break;
  101. }
  102. return $prefix;
  103. }
  104. }