public function testCallableComparator()
 {
     $callableComparatorMock = $this->getMockBuilder('\\NoRegression\\PHPUnit\\Comparator\\Callables\\CallableInterface')->getMock();
     $comparatorFactory = Factory::getInstance();
     $comparator = $comparatorFactory->getComparatorFor($callableComparatorMock, null);
     $this->assertInstanceOf('\\NoRegression\\PHPUnit\\Comparator\\CallableComparator', $comparator);
 }
 /**
  * @param \SwaggerAssert\PickInterface $pick
  */
 public function __construct(PickInterface $pick)
 {
     $this->pick = $pick;
     $this->pick->execute();
     $this->comparatorFactory = ComparatorFactory::getInstance();
     $this->differ = new Differ("--- Response\n+++ Swagger\n");
 }
Ejemplo n.º 3
0
 /**
  * Initializes object prophecy.
  *
  * @param LazyDouble        $lazyDouble
  * @param CallCenter        $callCenter
  * @param RevealerInterface $revealer
  * @param ComparatorFactory $comparatorFactory
  */
 public function __construct(LazyDouble $lazyDouble, CallCenter $callCenter = null, RevealerInterface $revealer = null, ComparatorFactory $comparatorFactory = null)
 {
     $this->lazyDouble = $lazyDouble;
     $this->callCenter = $callCenter ?: new CallCenter();
     $this->revealer = $revealer ?: new Revealer();
     $this->comparatorFactory = $comparatorFactory ?: ComparatorFactory::getInstance();
 }
 /**
  * @param array $other
  * @param string $description
  * @param bool $returnResult
  *
  * @throws \PHPUnit_Framework_ExpectationFailedException
  *
  * @return bool
  */
 public function evaluate($other, $description = '', $returnResult = false)
 {
     if (!is_array($other)) {
         if ($returnResult) {
             return false;
         }
         throw new PHPUnit_Framework_ExpectationFailedException(trim($description . "\n" . 'Value is not an array'));
     }
     if (!isset($other[$this->key])) {
         if ($returnResult) {
             return false;
         }
         throw new PHPUnit_Framework_ExpectationFailedException(trim($description . "\n" . 'Array does not contain the expected key ' . $this->key));
     }
     $comparatorFactory = Factory::getInstance();
     try {
         $comparator = $comparatorFactory->getComparatorFor($other[$this->key], $this->value);
         $comparator->assertEquals($this->value, $other[$this->key]);
     } catch (ComparisonFailure $f) {
         if ($returnResult) {
             return false;
         }
         throw new PHPUnit_Framework_ExpectationFailedException(trim($description . "\n" . $f->getMessage()), $f);
     }
     return true;
 }
 public static function tearDownAfterClass()
 {
     if (is_array(self::$comparators)) {
         array_map(array(Factory::getInstance(), 'unregister'), self::$comparators);
         self::$comparators = null;
     }
     parent::tearDownAfterClass();
 }
 public function setupCallableComparator()
 {
     $this->comparatorFactory = Factory::getInstance();
     $this->comparators[] = new ArrayComparator();
     $this->comparators[] = new CallableComparator();
     foreach ($this->comparators as $comparator) {
         $this->comparatorFactory->register($comparator);
     }
 }
Ejemplo n.º 7
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);
 }
 public function evaluate($other, $description = '', $returnResult = false)
 {
     $constraints = $other;
     /** @var string[] $expectedConstraintTypes */
     $expectedConstraintTypes = $this->constraintTypes;
     $hasExpectedConstraintTypes = !empty($this->constraintTypes);
     /** @var Constraint[] $expectedConstraints */
     $expectedConstraints = $this->constraints;
     $hasExpectedConstraints = !empty($this->constraints);
     $this->configureConstraintGroups($expectedConstraints);
     if ($hasExpectedConstraints) {
         list($constraints, $expectedConstraints) = $this->excludeKnownConstraints($constraints, $expectedConstraints);
     }
     if ($hasExpectedConstraintTypes) {
         list($constraints, $expectedConstraintTypes) = $this->excludeKnownTypes($constraints, $expectedConstraintTypes);
     }
     // Return if valid
     if (empty($constraints) && empty($expectedConstraints) && empty($expectedConstraintTypes)) {
         if ($returnResult) {
             return true;
         }
         return;
     }
     $comparatorFactory = ComparatorFactory::getInstance();
     try {
         if (empty($expectedConstraints)) {
             $constraintTypes = array_map('get_class', $constraints);
             $comparatorFactory->getComparatorFor($expectedConstraintTypes, $constraintTypes)->assertEquals($expectedConstraintTypes, $constraintTypes, 0.0, true);
         } elseif (empty($expectedConstraintTypes)) {
             $comparatorFactory->getComparatorFor($expectedConstraints, $constraints)->assertEquals($expectedConstraints, $constraints);
         } else {
             $expected = array_merge($expectedConstraints, $expectedConstraintTypes);
             $comparatorFactory->getComparatorFor($expected, $constraints)->assertEquals($expected, $constraints);
         }
     } catch (ComparisonFailure $f) {
         if ($returnResult) {
             return false;
         }
         throw new \PHPUnit_Framework_ExpectationFailedException(trim($description . "\n" . $f->getMessage()), $f);
     }
     throw new \LogicException('This stage should never be reached!');
 }
Ejemplo n.º 9
0
<?php

/*
 * This file is part of the puli/cli package.
 *
 * (c) Bernhard Schussek <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use SebastianBergmann\Comparator\Factory;
use Webmozart\Expression\PhpUnit\ExpressionComparator;
require_once __DIR__ . '/../vendor/autoload.php';
Factory::getInstance()->register(new ExpressionComparator());
Ejemplo n.º 10
0
 /**
  * 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();
 }