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