/**
  * @param Property $property
  * @param $firstObject
  * @param $secondObject
  * @return bool
  * @throws InvalidArgumentException
  */
 public function hasDifferentValue(Property $property, $firstObject, $secondObject)
 {
     $this->validaObjects($firstObject, $secondObject);
     $firstValue = $this->propertyAccessor->getValue($firstObject, $property->getName());
     $secondValue = $this->propertyAccessor->getValue($secondObject, $property->getName());
     $comparator = $this->comparatorFactory->getComparatorFor($firstValue, $secondValue);
     try {
         $comparator->assertEquals($firstValue, $secondValue);
         return false;
     } catch (ComparisonFailure $exception) {
         return true;
     }
 }
 /**
  * @todo Make correct validation
  * @return bool
  */
 public function validateMapping()
 {
     $mapperMapping = $this->getMapping();
     $documentMapping = $this->document->getMapping();
     $factory = new Factory();
     $comparator = $factory->getComparatorFor($mapperMapping, $documentMapping);
     try {
         $comparator->assertEquals($mapperMapping, $documentMapping);
         return true;
     } catch (ComparisonFailure $e) {
         return false;
     }
 }
 /**
  * @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 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);
 }
 private function getBaseURL($file)
 {
     switch ($this->storage->getDefaultDriver()) {
         case 'local':
             return $this->storage->getDriver()->getAdapter()->getPathPrefix() . "/" . $file->id . "." . $file->extension;
     }
 }
Example #6
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 \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");
 }
 public static function tearDownAfterClass()
 {
     if (is_array(self::$comparators)) {
         array_map(array(Factory::getInstance(), 'unregister'), self::$comparators);
         self::$comparators = null;
     }
     parent::tearDownAfterClass();
 }
Example #9
0
 public function evaluate($other, $description = '', $returnResult = false)
 {
     $isValid = true;
     $comparatorFactory = new Factory();
     $comparatorFactory->register(new DateTimeSimilarComparator());
     $comparatorFactory->register(new DateTimeStringSimilarComparator());
     try {
         $comparator = $comparatorFactory->getComparatorFor($other, $this->value);
         $comparator->assertEquals($this->value, $other, $this->delta, $this->canonicalize, $this->ignoreCase);
     } catch (ComparisonFailure $f) {
         if (!$returnResult) {
             throw new PHPUnit_Framework_ExpectationFailedException(trim($description . "\n" . $f->getMessage()), $f);
         }
         $isValid = false;
     }
     return $isValid;
 }
 public function setupCallableComparator()
 {
     $this->comparatorFactory = Factory::getInstance();
     $this->comparators[] = new ArrayComparator();
     $this->comparators[] = new CallableComparator();
     foreach ($this->comparators as $comparator) {
         $this->comparatorFactory->register($comparator);
     }
 }
Example #11
0
 /**
  * Evaluates the constraint for parameter $other
  *
  * @param mixed  $other        Value or object to evaluate.
  * @param string $description  Additional information about the test
  * @param bool   $returnResult Whether to return a result or throw an exception
  *
  * @return bool
  *
  * @throws \NumPHP\Core\Exception\CacheKeyException
  *
  * @see \PHPUnit_Framework_Constraint::evaluate
  * @since 1.0.0
  */
 public function evaluate($other, $description = '', $returnResult = false)
 {
     $otherClone = clone $other;
     if ($otherClone instanceof NumArray) {
         // flush the cache
         $otherClone->flushCache();
     }
     $comparatorFactory = new Factory();
     try {
         $comparator = $comparatorFactory->getComparatorFor($this->value, $otherClone);
         $comparator->assertEquals($this->value, $otherClone);
     } catch (ComparisonFailure $f) {
         if ($returnResult) {
             return false;
         }
         throw new \PHPUnit_Framework_ExpectationFailedException(trim($description . "\n" . $f->getMessage()), $f);
     }
     return true;
 }
Example #12
0
 /**
  * Check if a property has changed
  * 
  * @param string $property
  * @return boolean
  */
 public function hasModified($property)
 {
     if ($property === $this) {
         $original = $this->persistedData__;
         $current = $this->toData();
     } else {
         $persisted = static::fromData($this->persistedData__);
         $original = isset($persisted->{$property}) ? $persisted->{$property} : null;
         $current = isset($this->{$property}) ? $this->{$property} : null;
     }
     if ($original === $current) {
         return false;
     }
     $factory = new ComparatorFactory();
     $comparator = $factory->getComparatorFor($original, $current);
     try {
         $comparator->assertEquals($original, $current);
     } catch (ComparisonFailure $failure) {
         return true;
     }
     return false;
 }
Example #13
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!');
 }
Example #15
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());
Example #16
0
 public function __construct()
 {
     parent::__construct();
     $this->register(new ClosureComparator());
 }
Example #17
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();
 }