StringUtilSpec.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace spec\Prophecy\Util;
  3. use PhpSpec\ObjectBehavior;
  4. class StringUtilSpec extends ObjectBehavior
  5. {
  6. function it_generates_proper_string_representation_for_integer()
  7. {
  8. $this->stringify(42)->shouldReturn('42');
  9. }
  10. function it_generates_proper_string_representation_for_string()
  11. {
  12. $this->stringify('some string')->shouldReturn('"some string"');
  13. }
  14. function it_generates_single_line_representation_for_multiline_string()
  15. {
  16. $this->stringify("some\nstring")->shouldReturn('"some\\nstring"');
  17. }
  18. function it_generates_proper_string_representation_for_double()
  19. {
  20. $this->stringify(42.3)->shouldReturn('42.3');
  21. }
  22. function it_generates_proper_string_representation_for_boolean_true()
  23. {
  24. $this->stringify(true)->shouldReturn('true');
  25. }
  26. function it_generates_proper_string_representation_for_boolean_false()
  27. {
  28. $this->stringify(false)->shouldReturn('false');
  29. }
  30. function it_generates_proper_string_representation_for_null()
  31. {
  32. $this->stringify(null)->shouldReturn('null');
  33. }
  34. function it_generates_proper_string_representation_for_empty_array()
  35. {
  36. $this->stringify(array())->shouldReturn('[]');
  37. }
  38. function it_generates_proper_string_representation_for_array()
  39. {
  40. $this->stringify(array('zet', 42))->shouldReturn('["zet", 42]');
  41. }
  42. function it_generates_proper_string_representation_for_hash_containing_one_value()
  43. {
  44. $this->stringify(array('ever' => 'zet'))->shouldReturn('["ever" => "zet"]');
  45. }
  46. function it_generates_proper_string_representation_for_hash()
  47. {
  48. $this->stringify(array('ever' => 'zet', 52 => 'hey', 'num' => 42))->shouldReturn(
  49. '["ever" => "zet", 52 => "hey", "num" => 42]'
  50. );
  51. }
  52. function it_generates_proper_string_representation_for_resource()
  53. {
  54. $resource = fopen(__FILE__, 'r');
  55. $this->stringify($resource)->shouldReturn('stream:'.$resource);
  56. }
  57. /**
  58. * @param \stdClass $object
  59. */
  60. function it_generates_proper_string_representation_for_object($object)
  61. {
  62. $objHash = sprintf('%s:%s',
  63. get_class($object->getWrappedObject()),
  64. spl_object_hash($object->getWrappedObject())
  65. ) . " Object (\n 'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)\n)";
  66. $this->stringify($object)->shouldReturn("$objHash");
  67. }
  68. /**
  69. * @param stdClass $object
  70. */
  71. function it_generates_proper_string_representation_for_object_without_exporting($object)
  72. {
  73. $objHash = sprintf('%s:%s',
  74. get_class($object->getWrappedObject()),
  75. spl_object_hash($object->getWrappedObject())
  76. );
  77. $this->stringify($object, false)->shouldReturn("$objHash");
  78. }
  79. }