No Description

StringUtilSpec.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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()
  43. {
  44. $this->stringify(array('ever' => 'zet', 52 => 'hey', 'num' => 42))->shouldReturn(
  45. '["ever" => "zet", 52 => "hey", "num" => 42]'
  46. );
  47. }
  48. function it_generates_proper_string_representation_for_resource()
  49. {
  50. $resource = fopen(__FILE__, 'r');
  51. $this->stringify($resource)->shouldReturn('stream:'.$resource);
  52. }
  53. /**
  54. * @param \stdClass $object
  55. */
  56. function it_generates_proper_string_representation_for_object($object)
  57. {
  58. $objHash = sprintf('%s:%s',
  59. get_class($object->getWrappedObject()),
  60. spl_object_hash($object->getWrappedObject())
  61. ) . " Object (\n 'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)\n)";
  62. $this->stringify($object)->shouldReturn("$objHash");
  63. }
  64. /**
  65. * @param stdClass $object
  66. */
  67. function it_generates_proper_string_representation_for_object_without_exporting($object)
  68. {
  69. $objHash = sprintf('%s:%s',
  70. get_class($object->getWrappedObject()),
  71. spl_object_hash($object->getWrappedObject())
  72. );
  73. $this->stringify($object, false)->shouldReturn("$objHash");
  74. }
  75. }