summaryrefslogtreecommitdiff
path: root/vendor/phpspec/prophecy/src/Prophecy/Argument/Token
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/phpspec/prophecy/src/Prophecy/Argument/Token')
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValueToken.php52
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValuesToken.php52
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ApproximateValueToken.php55
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayCountToken.php86
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEntryToken.php143
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEveryEntryToken.php82
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/CallbackToken.php75
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ExactValueToken.php118
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/IdenticalValueToken.php74
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/InArrayToken.php74
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalAndToken.php80
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalNotToken.php73
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/NotInArrayToken.php75
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ObjectStateToken.php104
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/StringContainsToken.php67
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TokenInterface.php43
-rw-r--r--vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.php76
17 files changed, 1329 insertions, 0 deletions
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValueToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValueToken.php
new file mode 100644
index 000000000..50988112c
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValueToken.php
@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Any single value token.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+class AnyValueToken implements TokenInterface
+{
+ /**
+ * Always scores 3 for any argument.
+ *
+ * @param $argument
+ *
+ * @return int
+ */
+ public function scoreArgument($argument)
+ {
+ return 3;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return '*';
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValuesToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValuesToken.php
new file mode 100644
index 000000000..f76b17bc0
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/AnyValuesToken.php
@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Any values token.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+class AnyValuesToken implements TokenInterface
+{
+ /**
+ * Always scores 2 for any argument.
+ *
+ * @param $argument
+ *
+ * @return int
+ */
+ public function scoreArgument($argument)
+ {
+ return 2;
+ }
+
+ /**
+ * Returns true to stop wildcard from processing other tokens.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return true;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return '* [, ...]';
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ApproximateValueToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ApproximateValueToken.php
new file mode 100644
index 000000000..901744ab0
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ApproximateValueToken.php
@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Approximate value token
+ *
+ * @author Daniel Leech <[email protected]>
+ */
+class ApproximateValueToken implements TokenInterface
+{
+ private $value;
+ private $precision;
+
+ public function __construct($value, $precision = 0)
+ {
+ $this->value = $value;
+ $this->precision = $precision;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function scoreArgument($argument)
+ {
+ return round((float)$argument, $this->precision) === round($this->value, $this->precision) ? 10 : false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('≅%s', round($this->value, $this->precision));
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayCountToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayCountToken.php
new file mode 100644
index 000000000..96b4befd7
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayCountToken.php
@@ -0,0 +1,86 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Array elements count token.
+ *
+ * @author Boris Mikhaylov <[email protected]>
+ */
+
+class ArrayCountToken implements TokenInterface
+{
+ private $count;
+
+ /**
+ * @param integer $value
+ */
+ public function __construct($value)
+ {
+ $this->count = $value;
+ }
+
+ /**
+ * Scores 6 when argument has preset number of elements.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ return $this->isCountable($argument) && $this->hasProperCount($argument) ? 6 : false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return boolean
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('count(%s)', $this->count);
+ }
+
+ /**
+ * Returns true if object is either array or instance of \Countable
+ *
+ * @param $argument
+ * @return bool
+ */
+ private function isCountable($argument)
+ {
+ return (is_array($argument) || $argument instanceof \Countable);
+ }
+
+ /**
+ * Returns true if $argument has expected number of elements
+ *
+ * @param array|\Countable $argument
+ *
+ * @return bool
+ */
+ private function hasProperCount($argument)
+ {
+ return $this->count === count($argument);
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEntryToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEntryToken.php
new file mode 100644
index 000000000..0305fc720
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEntryToken.php
@@ -0,0 +1,143 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+use Prophecy\Exception\InvalidArgumentException;
+
+/**
+ * Array entry token.
+ *
+ * @author Boris Mikhaylov <[email protected]>
+ */
+class ArrayEntryToken implements TokenInterface
+{
+ /** @var \Prophecy\Argument\Token\TokenInterface */
+ private $key;
+ /** @var \Prophecy\Argument\Token\TokenInterface */
+ private $value;
+
+ /**
+ * @param mixed $key exact value or token
+ * @param mixed $value exact value or token
+ */
+ public function __construct($key, $value)
+ {
+ $this->key = $this->wrapIntoExactValueToken($key);
+ $this->value = $this->wrapIntoExactValueToken($value);
+ }
+
+ /**
+ * Scores half of combined scores from key and value tokens for same entry. Capped at 8.
+ * If argument implements \ArrayAccess without \Traversable, then key token is restricted to ExactValueToken.
+ *
+ * @param array|\ArrayAccess|\Traversable $argument
+ *
+ * @throws \Prophecy\Exception\InvalidArgumentException
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ if ($argument instanceof \Traversable) {
+ $argument = iterator_to_array($argument);
+ }
+
+ if ($argument instanceof \ArrayAccess) {
+ $argument = $this->convertArrayAccessToEntry($argument);
+ }
+
+ if (!is_array($argument) || empty($argument)) {
+ return false;
+ }
+
+ $keyScores = array_map(array($this->key,'scoreArgument'), array_keys($argument));
+ $valueScores = array_map(array($this->value,'scoreArgument'), $argument);
+ $scoreEntry = function ($value, $key) {
+ return $value && $key ? min(8, ($key + $value) / 2) : false;
+ };
+
+ return max(array_map($scoreEntry, $valueScores, $keyScores));
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return boolean
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('[..., %s => %s, ...]', $this->key, $this->value);
+ }
+
+ /**
+ * Returns key
+ *
+ * @return TokenInterface
+ */
+ public function getKey()
+ {
+ return $this->key;
+ }
+
+ /**
+ * Returns value
+ *
+ * @return TokenInterface
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Wraps non token $value into ExactValueToken
+ *
+ * @param $value
+ * @return TokenInterface
+ */
+ private function wrapIntoExactValueToken($value)
+ {
+ return $value instanceof TokenInterface ? $value : new ExactValueToken($value);
+ }
+
+ /**
+ * Converts instance of \ArrayAccess to key => value array entry
+ *
+ * @param \ArrayAccess $object
+ *
+ * @return array|null
+ * @throws \Prophecy\Exception\InvalidArgumentException
+ */
+ private function convertArrayAccessToEntry(\ArrayAccess $object)
+ {
+ if (!$this->key instanceof ExactValueToken) {
+ throw new InvalidArgumentException(sprintf(
+ 'You can only use exact value tokens to match key of ArrayAccess object'.PHP_EOL.
+ 'But you used `%s`.',
+ $this->key
+ ));
+ }
+
+ $key = $this->key->getValue();
+
+ return $object->offsetExists($key) ? array($key => $object[$key]) : array();
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEveryEntryToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEveryEntryToken.php
new file mode 100644
index 000000000..5d41fa487
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEveryEntryToken.php
@@ -0,0 +1,82 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Array every entry token.
+ *
+ * @author Adrien Brault <[email protected]>
+ */
+class ArrayEveryEntryToken implements TokenInterface
+{
+ /**
+ * @var TokenInterface
+ */
+ private $value;
+
+ /**
+ * @param mixed $value exact value or token
+ */
+ public function __construct($value)
+ {
+ if (!$value instanceof TokenInterface) {
+ $value = new ExactValueToken($value);
+ }
+
+ $this->value = $value;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function scoreArgument($argument)
+ {
+ if (!$argument instanceof \Traversable && !is_array($argument)) {
+ return false;
+ }
+
+ $scores = array();
+ foreach ($argument as $key => $argumentEntry) {
+ $scores[] = $this->value->scoreArgument($argumentEntry);
+ }
+
+ if (empty($scores) || in_array(false, $scores, true)) {
+ return false;
+ }
+
+ return array_sum($scores) / count($scores);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __toString()
+ {
+ return sprintf('[%s, ..., %s]', $this->value, $this->value);
+ }
+
+ /**
+ * @return TokenInterface
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/CallbackToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/CallbackToken.php
new file mode 100644
index 000000000..f45ba20be
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/CallbackToken.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+use Prophecy\Exception\InvalidArgumentException;
+
+/**
+ * Callback-verified token.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+class CallbackToken implements TokenInterface
+{
+ private $callback;
+
+ /**
+ * Initializes token.
+ *
+ * @param callable $callback
+ *
+ * @throws \Prophecy\Exception\InvalidArgumentException
+ */
+ public function __construct($callback)
+ {
+ if (!is_callable($callback)) {
+ throw new InvalidArgumentException(sprintf(
+ 'Callable expected as an argument to CallbackToken, but got %s.',
+ gettype($callback)
+ ));
+ }
+
+ $this->callback = $callback;
+ }
+
+ /**
+ * Scores 7 if callback returns true, false otherwise.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ return call_user_func($this->callback, $argument) ? 7 : false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return 'callback()';
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ExactValueToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ExactValueToken.php
new file mode 100644
index 000000000..045a1b90f
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ExactValueToken.php
@@ -0,0 +1,118 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+use SebastianBergmann\Comparator\ComparisonFailure;
+use Prophecy\Comparator\Factory as ComparatorFactory;
+use Prophecy\Util\StringUtil;
+
+/**
+ * Exact value token.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+class ExactValueToken implements TokenInterface
+{
+ private $value;
+ private $string;
+ private $util;
+ private $comparatorFactory;
+
+ /**
+ * Initializes token.
+ *
+ * @param mixed $value
+ * @param StringUtil $util
+ * @param ComparatorFactory $comparatorFactory
+ */
+ public function __construct($value, StringUtil $util = null, ComparatorFactory $comparatorFactory = null)
+ {
+ $this->value = $value;
+ $this->util = $util ?: new StringUtil();
+
+ $this->comparatorFactory = $comparatorFactory ?: ComparatorFactory::getInstance();
+ }
+
+ /**
+ * Scores 10 if argument matches preset value.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ if (is_object($argument) && is_object($this->value)) {
+ $comparator = $this->comparatorFactory->getComparatorFor(
+ $argument, $this->value
+ );
+
+ try {
+ $comparator->assertEquals($argument, $this->value);
+ return 10;
+ } catch (ComparisonFailure $failure) {
+ return false;
+ }
+ }
+
+ // If either one is an object it should be castable to a string
+ if (is_object($argument) xor is_object($this->value)) {
+ if (is_object($argument) && !method_exists($argument, '__toString')) {
+ return false;
+ }
+
+ if (is_object($this->value) && !method_exists($this->value, '__toString')) {
+ return false;
+ }
+ } elseif (is_numeric($argument) && is_numeric($this->value)) {
+ // noop
+ } elseif (gettype($argument) !== gettype($this->value)) {
+ return false;
+ }
+
+ return $argument == $this->value ? 10 : false;
+ }
+
+ /**
+ * Returns preset value against which token checks arguments.
+ *
+ * @return mixed
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ if (null === $this->string) {
+ $this->string = sprintf('exact(%s)', $this->util->stringify($this->value));
+ }
+
+ return $this->string;
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/IdenticalValueToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/IdenticalValueToken.php
new file mode 100644
index 000000000..0b6d23ab6
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/IdenticalValueToken.php
@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+use Prophecy\Util\StringUtil;
+
+/**
+ * Identical value token.
+ *
+ * @author Florian Voutzinos <[email protected]>
+ */
+class IdenticalValueToken implements TokenInterface
+{
+ private $value;
+ private $string;
+ private $util;
+
+ /**
+ * Initializes token.
+ *
+ * @param mixed $value
+ * @param StringUtil $util
+ */
+ public function __construct($value, StringUtil $util = null)
+ {
+ $this->value = $value;
+ $this->util = $util ?: new StringUtil();
+ }
+
+ /**
+ * Scores 11 if argument matches preset value.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ return $argument === $this->value ? 11 : false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ if (null === $this->string) {
+ $this->string = sprintf('identical(%s)', $this->util->stringify($this->value));
+ }
+
+ return $this->string;
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/InArrayToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/InArrayToken.php
new file mode 100644
index 000000000..f727aea42
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/InArrayToken.php
@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Check if values is in array
+ *
+ * @author Vinícius Alonso <[email protected]>
+ */
+class InArrayToken implements TokenInterface
+{
+ private $token = array();
+ private $strict;
+
+ /**
+ * @param array $arguments tokens
+ * @param bool $strict
+ */
+ public function __construct(array $arguments, $strict = true)
+ {
+ $this->token = $arguments;
+ $this->strict = $strict;
+ }
+
+ /**
+ * Return scores 8 score if argument is in array.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ if (count($this->token) === 0) {
+ return false;
+ }
+
+ if (\in_array($argument, $this->token, $this->strict)) {
+ return 8;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return boolean
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ $arrayAsString = implode(', ', $this->token);
+ return "[{$arrayAsString}]";
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalAndToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalAndToken.php
new file mode 100644
index 000000000..4ee1b25e1
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalAndToken.php
@@ -0,0 +1,80 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Logical AND token.
+ *
+ * @author Boris Mikhaylov <[email protected]>
+ */
+class LogicalAndToken implements TokenInterface
+{
+ private $tokens = array();
+
+ /**
+ * @param array $arguments exact values or tokens
+ */
+ public function __construct(array $arguments)
+ {
+ foreach ($arguments as $argument) {
+ if (!$argument instanceof TokenInterface) {
+ $argument = new ExactValueToken($argument);
+ }
+ $this->tokens[] = $argument;
+ }
+ }
+
+ /**
+ * Scores maximum score from scores returned by tokens for this argument if all of them score.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ if (0 === count($this->tokens)) {
+ return false;
+ }
+
+ $maxScore = 0;
+ foreach ($this->tokens as $token) {
+ $score = $token->scoreArgument($argument);
+ if (false === $score) {
+ return false;
+ }
+ $maxScore = max($score, $maxScore);
+ }
+
+ return $maxScore;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return boolean
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('bool(%s)', implode(' AND ', $this->tokens));
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalNotToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalNotToken.php
new file mode 100644
index 000000000..623efa57a
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/LogicalNotToken.php
@@ -0,0 +1,73 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Logical NOT token.
+ *
+ * @author Boris Mikhaylov <[email protected]>
+ */
+class LogicalNotToken implements TokenInterface
+{
+ /** @var \Prophecy\Argument\Token\TokenInterface */
+ private $token;
+
+ /**
+ * @param mixed $value exact value or token
+ */
+ public function __construct($value)
+ {
+ $this->token = $value instanceof TokenInterface? $value : new ExactValueToken($value);
+ }
+
+ /**
+ * Scores 4 when preset token does not match the argument.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ return false === $this->token->scoreArgument($argument) ? 4 : false;
+ }
+
+ /**
+ * Returns true if preset token is last.
+ *
+ * @return bool|int
+ */
+ public function isLast()
+ {
+ return $this->token->isLast();
+ }
+
+ /**
+ * Returns originating token.
+ *
+ * @return TokenInterface
+ */
+ public function getOriginatingToken()
+ {
+ return $this->token;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('not(%s)', $this->token);
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/NotInArrayToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/NotInArrayToken.php
new file mode 100644
index 000000000..6aed8aa50
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/NotInArrayToken.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Check if values is not in array
+ *
+ * @author Vinícius Alonso <[email protected]>
+ */
+class NotInArrayToken implements TokenInterface
+{
+ private $token = array();
+ private $strict;
+
+ /**
+ * @param array $arguments tokens
+ * @param bool $strict
+ */
+ public function __construct(array $arguments, $strict = true)
+ {
+ $this->token = $arguments;
+ $this->strict = $strict;
+ }
+
+ /**
+ * Return scores 8 score if argument is in array.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ if (count($this->token) === 0) {
+ return false;
+ }
+
+ if (!\in_array($argument, $this->token, $this->strict)) {
+ return 8;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return boolean
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ $arrayAsString = implode(', ', $this->token);
+ return "[{$arrayAsString}]";
+ }
+}
+
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ObjectStateToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ObjectStateToken.php
new file mode 100644
index 000000000..d77107767
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ObjectStateToken.php
@@ -0,0 +1,104 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+use SebastianBergmann\Comparator\ComparisonFailure;
+use Prophecy\Comparator\Factory as ComparatorFactory;
+use Prophecy\Util\StringUtil;
+
+/**
+ * Object state-checker token.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+class ObjectStateToken implements TokenInterface
+{
+ private $name;
+ private $value;
+ private $util;
+ private $comparatorFactory;
+
+ /**
+ * Initializes token.
+ *
+ * @param string $methodName
+ * @param mixed $value Expected return value
+ * @param null|StringUtil $util
+ * @param ComparatorFactory $comparatorFactory
+ */
+ public function __construct(
+ $methodName,
+ $value,
+ StringUtil $util = null,
+ ComparatorFactory $comparatorFactory = null
+ ) {
+ $this->name = $methodName;
+ $this->value = $value;
+ $this->util = $util ?: new StringUtil;
+
+ $this->comparatorFactory = $comparatorFactory ?: ComparatorFactory::getInstance();
+ }
+
+ /**
+ * Scores 8 if argument is an object, which method returns expected value.
+ *
+ * @param mixed $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ if (is_object($argument) && method_exists($argument, $this->name)) {
+ $actual = call_user_func(array($argument, $this->name));
+
+ $comparator = $this->comparatorFactory->getComparatorFor(
+ $this->value, $actual
+ );
+
+ try {
+ $comparator->assertEquals($this->value, $actual);
+ return 8;
+ } catch (ComparisonFailure $failure) {
+ return false;
+ }
+ }
+
+ if (is_object($argument) && property_exists($argument, $this->name)) {
+ return $argument->{$this->name} === $this->value ? 8 : false;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('state(%s(), %s)',
+ $this->name,
+ $this->util->stringify($this->value)
+ );
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/StringContainsToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/StringContainsToken.php
new file mode 100644
index 000000000..bd8d423f9
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/StringContainsToken.php
@@ -0,0 +1,67 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * String contains token.
+ *
+ * @author Peter Mitchell <[email protected]>
+ */
+class StringContainsToken implements TokenInterface
+{
+ private $value;
+
+ /**
+ * Initializes token.
+ *
+ * @param string $value
+ */
+ public function __construct($value)
+ {
+ $this->value = $value;
+ }
+
+ public function scoreArgument($argument)
+ {
+ return is_string($argument) && strpos($argument, $this->value) !== false ? 6 : false;
+ }
+
+ /**
+ * Returns preset value against which token checks arguments.
+ *
+ * @return mixed
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('contains("%s")', $this->value);
+ }
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TokenInterface.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TokenInterface.php
new file mode 100644
index 000000000..625d3bad2
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TokenInterface.php
@@ -0,0 +1,43 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+/**
+ * Argument token interface.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+interface TokenInterface
+{
+ /**
+ * Calculates token match score for provided argument.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument);
+
+ /**
+ * Returns true if this token prevents check of other tokens (is last one).
+ *
+ * @return bool|int
+ */
+ public function isLast();
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString();
+}
diff --git a/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.php b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.php
new file mode 100644
index 000000000..cb65132ca
--- /dev/null
+++ b/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.php
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ * This file is part of the Prophecy.
+ * (c) Konstantin Kudryashov <[email protected]>
+ * Marcello Duarte <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Prophecy\Argument\Token;
+
+use Prophecy\Exception\InvalidArgumentException;
+
+/**
+ * Value type token.
+ *
+ * @author Konstantin Kudryashov <[email protected]>
+ */
+class TypeToken implements TokenInterface
+{
+ private $type;
+
+ /**
+ * @param string $type
+ */
+ public function __construct($type)
+ {
+ $checker = "is_{$type}";
+ if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) {
+ throw new InvalidArgumentException(sprintf(
+ 'Type or class name expected as an argument to TypeToken, but got %s.', $type
+ ));
+ }
+
+ $this->type = $type;
+ }
+
+ /**
+ * Scores 5 if argument has the same type this token was constructed with.
+ *
+ * @param $argument
+ *
+ * @return bool|int
+ */
+ public function scoreArgument($argument)
+ {
+ $checker = "is_{$this->type}";
+ if (function_exists($checker)) {
+ return call_user_func($checker, $argument) ? 5 : false;
+ }
+
+ return $argument instanceof $this->type ? 5 : false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @return bool
+ */
+ public function isLast()
+ {
+ return false;
+ }
+
+ /**
+ * Returns string representation for token.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return sprintf('type(%s)', $this->type);
+ }
+}