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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
<?php
namespace spec\Prophecy\Argument\Token;
use PhpSpec\ObjectBehavior;
class ExactValueTokenSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(42);
}
function it_implements_TokenInterface()
{
$this->shouldBeAnInstanceOf('Prophecy\Argument\Token\TokenInterface');
}
function it_is_not_last()
{
$this->shouldNotBeLast();
}
function it_holds_value()
{
$this->getValue()->shouldReturn(42);
}
function it_scores_10_if_value_is_equal_to_argument()
{
$this->scoreArgument(42)->shouldReturn(10);
$this->scoreArgument('42')->shouldReturn(10);
}
function it_scores_10_if_value_is_an_object_and_equal_to_argument()
{
$value = new \DateTime();
$value2 = clone $value;
$this->beConstructedWith($value);
$this->scoreArgument($value2)->shouldReturn(10);
}
function it_scores_10_if_value_is_a_double_object_and_equal_to_argument(\stdClass $value)
{
$value2 = clone $value->getWrappedObject();
$this->beConstructedWith($value);
$this->scoreArgument($value2)->shouldReturn(10);
}
function it_does_not_scores_if_value_is_not_equal_to_argument()
{
$this->scoreArgument(50)->shouldReturn(false);
$this->scoreArgument(new \stdClass())->shouldReturn(false);
}
function it_does_not_scores_if_value_an_object_and_is_not_equal_to_argument()
{
$value = new ExactValueTokenFixtureB('ABC');
$value2 = new ExactValueTokenFixtureB('CBA');
$this->beConstructedWith($value);
$this->scoreArgument($value2)->shouldReturn(false);
}
function it_does_not_scores_if_value_type_and_is_not_equal_to_argument()
{
$this->beConstructedWith(false);
$this->scoreArgument(0)->shouldReturn(false);
}
function it_generates_proper_string_representation_for_integer()
{
$this->beConstructedWith(42);
$this->__toString()->shouldReturn('exact(42)');
}
function it_generates_proper_string_representation_for_string()
{
$this->beConstructedWith('some string');
$this->__toString()->shouldReturn('exact("some string")');
}
function it_generates_single_line_representation_for_multiline_string()
{
$this->beConstructedWith("some\nstring");
$this->__toString()->shouldReturn('exact("some\\nstring")');
}
function it_generates_proper_string_representation_for_double()
{
$this->beConstructedWith(42.3);
$this->__toString()->shouldReturn('exact(42.3)');
}
function it_generates_proper_string_representation_for_boolean_true()
{
$this->beConstructedWith(true);
$this->__toString()->shouldReturn('exact(true)');
}
function it_generates_proper_string_representation_for_boolean_false()
{
$this->beConstructedWith(false);
$this->__toString()->shouldReturn('exact(false)');
}
function it_generates_proper_string_representation_for_null()
{
$this->beConstructedWith(null);
$this->__toString()->shouldReturn('exact(null)');
}
function it_generates_proper_string_representation_for_empty_array()
{
$this->beConstructedWith(array());
$this->__toString()->shouldReturn('exact([])');
}
function it_generates_proper_string_representation_for_array()
{
$this->beConstructedWith(array('zet', 42));
$this->__toString()->shouldReturn('exact(["zet", 42])');
}
function it_generates_proper_string_representation_for_resource()
{
$resource = fopen(__FILE__, 'r');
$this->beConstructedWith($resource);
$this->__toString()->shouldReturn('exact(stream:'.$resource.')');
}
function it_generates_proper_string_representation_for_object(\stdClass $object)
{
$objHash = sprintf('exact(%s#%s',
get_class($object->getWrappedObject()),
spl_object_id($object->getWrappedObject())
)." Object (\n 'objectProphecyClosure' => Closure#%s Object (\n 0 => Closure#%s Object\n )\n))";
$this->beConstructedWith($object);
$idRegexExpr = '[0-9]+';
$this->__toString()->shouldMatch(sprintf('/^%s$/', sprintf(preg_quote("$objHash"), $idRegexExpr, $idRegexExpr)));
}
function it_scores_10_if_value_an_numeric_and_equal_to_argument_as_stringable()
{
$value = 10;
$argument = new ExactValueTokenC("10");
$this->beConstructedWith($value);
$this->scoreArgument($argument)->shouldReturn(10);
}
function it_does_not_scores_if_value_an_numeric_and_equal_to_argument_as_stringable()
{
$value = 10;
$argument = new ExactValueTokenC("example");
$this->beConstructedWith($value);
$this->scoreArgument($argument)->shouldReturn(false);
}
function it_does_not_scores_if_value_an_object_and_not_equal_to_argument_object()
{
$value = new ExactValueTokenFixtureA();
$argument = new ExactValueTokenC("example");
$this->beConstructedWith($value);
$this->scoreArgument($argument)->shouldReturn(false);
}
}
class ExactValueTokenFixtureA
{
public $errors;
}
class ExactValueTokenFixtureB extends ExactValueTokenFixtureA
{
public $errors;
public $value = null;
public function __construct($value)
{
$this->value = $value;
}
}
class ExactValueTokenC
{
public $value;
public function __construct($value)
{
$this->value = $value;
}
public function __toString()
{
return $this->value;
}
}
|