Drupal investigation

StringUtilSpec.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. function it_generates_proper_string_representation_for_object(\stdClass $object)
  58. {
  59. $objHash = sprintf('%s:%s',
  60. get_class($object->getWrappedObject()),
  61. spl_object_hash($object->getWrappedObject())
  62. ) . " Object (\n 'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)\n)";
  63. $this->stringify($object)->shouldReturn("$objHash");
  64. }
  65. function it_generates_proper_string_representation_for_object_without_exporting(\stdClass $object)
  66. {
  67. $objHash = sprintf('%s:%s',
  68. get_class($object->getWrappedObject()),
  69. spl_object_hash($object->getWrappedObject())
  70. );
  71. $this->stringify($object, false)->shouldReturn("$objHash");
  72. }
  73. }