/** * @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; } }
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; }
/** * 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; }
/** * 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; }