4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
14 use Prophecy\Argument\Token;
17 * Argument tokens shortcuts.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
24 * Checks that argument is exact value or object.
28 * @return Token\ExactValueToken
30 public static function exact($value)
32 return new Token\ExactValueToken($value);
36 * Checks that argument is of specific type or instance of specific class.
38 * @param string $type Type name (`integer`, `string`) or full class name
40 * @return Token\TypeToken
42 public static function type($type)
44 return new Token\TypeToken($type);
48 * Checks that argument object has specific state.
50 * @param string $methodName
53 * @return Token\ObjectStateToken
55 public static function which($methodName, $value)
57 return new Token\ObjectStateToken($methodName, $value);
61 * Checks that argument matches provided callback.
63 * @param callable $callback
65 * @return Token\CallbackToken
67 public static function that($callback)
69 return new Token\CallbackToken($callback);
73 * Matches any single value.
75 * @return Token\AnyValueToken
77 public static function any()
79 return new Token\AnyValueToken;
83 * Matches all values to the rest of the signature.
85 * @return Token\AnyValuesToken
87 public static function cetera()
89 return new Token\AnyValuesToken;
93 * Checks that argument matches all tokens
95 * @param mixed ... a list of tokens
97 * @return Token\LogicalAndToken
99 public static function allOf()
101 return new Token\LogicalAndToken(func_get_args());
105 * Checks that argument array or countable object has exact number of elements.
107 * @param integer $value array elements count
109 * @return Token\ArrayCountToken
111 public static function size($value)
113 return new Token\ArrayCountToken($value);
117 * Checks that argument array contains (key, value) pair
119 * @param mixed $key exact value or token
120 * @param mixed $value exact value or token
122 * @return Token\ArrayEntryToken
124 public static function withEntry($key, $value)
126 return new Token\ArrayEntryToken($key, $value);
130 * Checks that arguments array entries all match value
132 * @param mixed $value
134 * @return Token\ArrayEveryEntryToken
136 public static function withEveryEntry($value)
138 return new Token\ArrayEveryEntryToken($value);
142 * Checks that argument array contains value
144 * @param mixed $value
146 * @return Token\ArrayEntryToken
148 public static function containing($value)
150 return new Token\ArrayEntryToken(self::any(), $value);
154 * Checks that argument array has key
156 * @param mixed $key exact value or token
158 * @return Token\ArrayEntryToken
160 public static function withKey($key)
162 return new Token\ArrayEntryToken($key, self::any());
166 * Checks that argument does not match the value|token.
168 * @param mixed $value either exact value or argument token
170 * @return Token\LogicalNotToken
172 public static function not($value)
174 return new Token\LogicalNotToken($value);
178 * @param string $value
180 * @return Token\StringContainsToken
182 public static function containingString($value)
184 return new Token\StringContainsToken($value);
188 * Checks that argument is identical value.
190 * @param mixed $value
192 * @return Token\IdenticalValueToken
194 public static function is($value)
196 return new Token\IdenticalValueToken($value);
200 * Check that argument is same value when rounding to the
203 * @param float $value
204 * @param float $precision
206 * @return Token\ApproximateValueToken
208 public static function approximate($value, $precision = 0)
210 return new Token\ApproximateValueToken($value, $precision);