evaluate() public méthode

Evaluates the constraint for parameter $other. Returns TRUE if the constraint is met, FALSE otherwise.
public evaluate ( mixed $other ) : boolean
$other mixed Value or object to evaluate.
Résultat boolean
 function getMatchers()
 {
     $readProperty = function ($object, $propertyName) {
         return EditorBuilderSpec::readProperty($object, $propertyName);
     };
     return array('haveSearchStrategies' => function ($subject, $expected) use($readProperty) {
         $engine = $readProperty($subject, 'searchEngine');
         $strategies = array_map('get_class', array_filter(call_user_func_array('array_merge', $readProperty($engine, 'searchStrategies'))));
         $constraint = new \PHPUnit_Framework_Constraint_IsEqual($expected);
         return $constraint->evaluate($strategies, '', true);
     }, 'haveCommands' => function ($subject, $expected) use($readProperty) {
         $commandInvoker = $readProperty($subject, 'commandInvoker');
         $commands = array_map('get_class', $readProperty($commandInvoker, 'commands'));
         $constraint = new \PHPUnit_Framework_Constraint_IsEqual($expected);
         return $constraint->evaluate($commands, '', true);
     }, 'haveSearchStrategiesCount' => function ($subject, $expected) use($readProperty) {
         $engine = $readProperty($subject, 'searchEngine');
         $count = array_reduce($readProperty($engine, 'searchStrategies'), function ($carry, $item) {
             return $carry + count($item);
         });
         return $expected == $count;
     }, 'haveCommandCount' => function ($subject, $expected) use($readProperty) {
         $commandInvoker = $readProperty($subject, 'commandInvoker');
         $commands = $readProperty($commandInvoker, 'commands');
         return $expected == count($commands);
     });
 }
 public function matches($other, $description = '')
 {
     $description = $description ?: '$array';
     if (!is_array($other)) {
         return false;
     }
     foreach ($this->pattern as $key => $expectedValue) {
         if (!array_key_exists($key, $other)) {
             return false;
         }
         $otherValue = $other[$key];
         $description .= "['{$key}']";
         if (is_array($expectedValue)) {
             $constraint = new static($expectedValue, $otherValue, $description);
         } elseif ($expectedValue instanceof \PHPUnit_Framework_Constraint) {
             $constraint = $expectedValue;
         } else {
             $constraint = new \PHPUnit_Framework_Constraint_IsEqual($expectedValue);
         }
         if (!$constraint->evaluate($otherValue, $description, true)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Evaluate
  *
  * @param \Closure $other
  * @param  string $description Additional information about the test
  * @param  bool $returnResult Whether to return a result or throw an exception
  * @return boolean
  */
 public function evaluate($other, $description = '', $returnResult = FALSE)
 {
     if (!$other instanceof \Closure) {
         $this->_cause = 'Variable must be a Closure';
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     $reflection = new \ReflectionFunction($other);
     $requiredParameters = new \PHPUnit_Framework_Constraint_IsEqual(1);
     if (false === $requiredParameters->evaluate($reflection->getNumberOfRequiredParameters(), $description, true)) {
         $this->_cause = 'Closure does not have 1 required parameter';
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     $params = $reflection->getParameters();
     $tokenParameter = $params[0];
     /* @var $tokenParameter \ReflectionParameter */
     $parameterType = new \PHPUnit_Framework_Constraint_IsEqual('PHP\\Manipulator\\Token');
     if (false === $parameterType->evaluate($tokenParameter->getClass()->name, $description, true)) {
         $this->_cause = 'Closures Token-Parameter has wrong Typehint';
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     return true;
 }
 public function compare($expected, $actual)
 {
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($expected);
     try {
         $constraint->evaluate($actual);
         throw new \Exception('Can not diff equal values');
     } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
         return $e->getComparisonFailure()->getDiff();
     }
 }
 private function evaluateArgumentValue(Definition $definition, $returnResult)
 {
     $actualValue = $definition->getArgument($this->argumentIndex);
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($this->expectedValue);
     if (!$constraint->evaluate($actualValue, '', true)) {
         if ($returnResult) {
             return false;
         }
         $this->fail($definition, sprintf('The value of argument with index %d (%s) is not equal to the expected value (%s)', $this->argumentIndex, $this->exporter->export($actualValue), $this->exporter->export($this->expectedValue)));
     }
     return true;
 }
 private function evaluateParameterValue(ContainerInterface $container, $returnResult)
 {
     $actualValue = $container->getParameter($this->parameterName);
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($this->expectedParameterValue);
     if (!$constraint->evaluate($actualValue, '', true)) {
         if ($returnResult) {
             return false;
         }
         $this->fail($container, sprintf('The value of parameter "%s" (%s) does not match the expected value (%s)', $this->parameterName, $this->exporter->export($this->expectedParameterValue), $this->exporter->export($actualValue)));
     }
     return true;
 }
Exemple #7
0
 /**
  * @inheritdoc
  */
 public function evaluate($other, $description = '', $returnResult = false)
 {
     if ($this->value === $other) {
         return true;
     }
     if ($this->value instanceof Equatable) {
         return $this->handleResult($this->value, $other, $this->value->equals($other), $description, $returnResult);
     }
     if ($other instanceof Equatable) {
         return $this->handleResult($this->value, $other, $other->equals($this->value), $description, $returnResult);
     }
     return parent::evaluate($other, $description, $returnResult);
 }
 private function evaluateClass(ContainerBuilder $containerBuilder, $returnResult)
 {
     $definition = $containerBuilder->findDefinition($this->serviceId);
     $actualClass = $containerBuilder->getParameterBag()->resolveValue($definition->getClass());
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($this->expectedClass);
     if (!$constraint->evaluate($actualClass, '', true)) {
         if ($returnResult) {
             return false;
         }
         $this->fail($containerBuilder, sprintf('The class of the service definition of "%s" (%s) does not match the expected value (%s)', $this->serviceId, $this->exporter->export($actualClass), $this->exporter->export($this->expectedClass)));
     }
     return true;
 }
 /**
  * Evaluates the constraint for parameter $other
  *
  * If $shouldreturnesult is set to false (the default), an exception is thrown
  * in case of a failure. null is returned otherwise.
  *
  * If $shouldreturnesult is true, the result of the evaluation is returned as
  * a boolean value instead: true in case of success, false in case of a
  * failure.
  *
  * @param  mixed    $other              Value or object to evaluate.
  * @param  string   $description        Additional information about the test
  * @param  bool     $shouldreturnesult  Whether to return a result or throw an exception
  * @return mixed
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 public function evaluate($other, $description = '', $shouldreturnesult = false)
 {
     foreach ($this->keys as $key => $comparison) {
         if (isset($other->{$key}) || isset($this->value->{$key})) {
             // One of the keys is present, therefore run the comparison.
             PHPUnit_Framework_Assert::$comparison($this->value->{$key}, $other->{$key});
             // Unset the keys, otherwise the standard evaluation will take place.
             unset($other->{$key});
             unset($this->value->{$key});
         }
     }
     // Run the parent evaluation (isEqual).
     return parent::evaluate($other, $description, $shouldreturnesult);
 }
Exemple #10
0
 public static function assertEqualsButIgnoreParameterIds($expected, $actual)
 {
     $comparator = new self();
     $factory = ComparatorFactory::getInstance();
     $comparator->setFactory($factory);
     $factory->register($comparator);
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($expected);
     try {
         $constraint->evaluate($actual, 'Queries must be equivalent');
     } catch (\Exception $exception) {
         $factory->unregister($comparator);
         throw $exception;
     }
     $factory->unregister($comparator);
 }
 private function evaluateServiceId(ContainerBuilder $containerBuilder, $returnResult)
 {
     $alias = $containerBuilder->getAlias($this->aliasId);
     /*
      * The aliases service id can be retrieved by casting the alias to a string,
      * see Alias::__toString()
      */
     $actualServiceId = (string) $alias;
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual(strtolower($this->expectedServiceId));
     if (!$constraint->evaluate($actualServiceId, '', true)) {
         if ($returnResult) {
             return false;
         }
         $this->fail($containerBuilder, sprintf('"%s" is not an alias for "%s", but for "%s"', $this->aliasId, $this->expectedServiceId, $actualServiceId));
     }
     return true;
 }
 private function equalArguments($expectedArguments, $actualArguments)
 {
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($expectedArguments);
     return $constraint->evaluate($actualArguments, '', true);
 }
 public function evaluate($other, $description = '', $returnResult = false)
 {
     $processedConfiguration = $this->processConfiguration($this->configurationValues);
     $constraint = new \PHPUnit_Framework_Constraint_IsEqual($other);
     return $constraint->evaluate($processedConfiguration, '', $returnResult);
 }
 public function testConstraintIsEqual()
 {
     $constraint = new PHPUnit_Framework_Constraint_IsEqual(1);
     $this->assertFalse($constraint->evaluate(0));
     $this->assertTrue($constraint->evaluate(1));
     $this->assertEquals('is equal to <integer:1>', $constraint->toString());
     try {
         $constraint->fail(0, '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("Failed asserting that <integer:0> is equal to <integer:1>.", $e->getDescription());
         return;
     }
     $this->fail();
 }