protected function matches($actual) { if ($this->delta == null && $this->analyzer->isFloat($actual) === false && $this->analyzer->isFloat($this->expected) === false) { $asserter = new asserters\variable(null, $this->analyzer); if ($this->analyzer->isString($actual) && $this->ignoreCase) { $actual = strtolower($actual); } if ($this->analyzer->isArray($actual) && $this->canonicalize) { $actual = sort($actual); } $asserter->setWith($actual); if ($actual === 0 && $this->expected == '' || $actual == '' && $this->expected === 0) { $asserter->isIdenticalTo($this->expected); } else { $expected = $this->expected; if ($this->analyzer->isString($expected) && $this->ignoreCase) { $expected = strtolower($expected); } if ($this->analyzer->isArray($expected) && $this->canonicalize) { $expected = sort($expected); } $asserter->isEqualTo($expected); } } else { $asserter = new asserters\phpFloat(null, $this->analyzer); $asserter->setWith((double) $actual)->isNearlyEqualTo((double) $this->expected, $this->delta); } }
protected function valueIsSet($message = 'Object is undefined') { if (self::isObject(parent::valueIsSet($message)->value) === false) { throw new exceptions\logic($message); } return $this; }
public function isEqualToContentsOfFile($path, $failMessage = null) { $fileContents = @$this->valueIsSet()->adapter->file_get_contents($path); if ($fileContents === false) { $this->fail(sprintf($this->getLocale()->_('Unable to get contents of file %s'), $path)); } else { return parent::isEqualTo($fileContents, $failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('string is not equals to contents of file %s'), $path)); } }
public function setWith($value) { variable::setWith($value); if ($this->analyzer->isFloat($this->value) === true) { $this->pass(); } else { $this->fail($this->_('%s is not a float', $this)); } return $this; }
public function setWith($value) { parent::setWith($value); if ($this->analyzer->isBoolean($this->value) === true) { $this->pass(); } else { $this->fail($this->_('%s is not a boolean', $this)); } return $this; }
public function setWith($value, $label = null) { parent::setWith($value, $label); if (self::isBoolean($this->value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not a boolean'), $this)); } else { $this->pass(); } return $this; }
public function setWith($value, $label = null) { variable::setWith($value, $label); if (self::isFloat($this->value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not a float'), $this)); } else { $this->pass(); } return $this; }
public function isEqualToContentsOfFile($path, $failMessage = null) { $this->valueIsSet(); $fileContents = @file_get_contents($path); if ($fileContents === false) { $this->fail($this->_('Unable to get contents of file %s', $path)); } else { return parent::isEqualTo($fileContents, $failMessage ?: $this->_('string is not equal to contents of file %s', $path)); } }
public function setWith($value, $checkType = true) { parent::setWith($value, $checkType); if ($checkType === true) { if ($this->value instanceof DependencyInjection\Definition) { $this->pass(); } else { $this->fail($this->_('%s is not an instance of Symfony\\Component\\DependencyInjection\\Definition', get_class($this->value))); } } return $this; }
public function setWith($value, $checkType = true) { parent::setWith($value, $checkType); if ($checkType === true) { if ($this->value instanceof DependencyInjection\ContainerBuilder) { $this->pass(); } else { $this->fail($this->_('%s is not an instance of Symfony\\Component\\DependencyInjection\\ContainerBuilder', is_object($this->value) ? get_class($this->value) : gettype($this->value))); } } return $this; }
public function __call($name, $arguments) { if ('is' === substr($name, 0, 2)) { $pattern = preg_replace(array('/^is/', '/_/'), array('', '.?'), $name); $pattern = preg_replace_callback('/([A-Z])([a-z]+)/', function ($matches) { return '.?' . strtolower($matches[1]) . $matches[2]; }, $pattern); $pattern = '/^' . $pattern . '$/i'; if (1 === count($arguments)) { return $this->matches($pattern, $arguments[0]); } return $this->matches($pattern); } return parent::__call($name, $arguments); }
/** * {@inheritdoc} */ public function isEqualTo($value, $failMessage = null) { $target = $this->valueIsSet()->value; if ($target instanceof EquatableInterface) { if ($target->equals($value)) { $this->pass(); } else { if (!$failMessage) { $failMessage = $this->_('%s is not equal to %s', $this, $this->getTypeOf($value)); } $this->fail($failMessage); } } else { parent::isEqualTo($value, $failMessage); } return $this; }
protected function matches($actual) { $asserter = new asserters\variable(); $asserter->setWith($actual)->isNotNull(); }
public function isEqualTo($value, $failMessage = null) { static::check($value, __FUNCTION__); return parent::isEqualTo($value, $failMessage); }
public function testIsReferenceTo() { $this->if($asserter = new asserters\variable($generator = new asserter\generator()))->and($value = uniqid())->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter, $value) { $asserter->isReferenceTo($value); })->isInstanceOf('logicException')->hasMessage('Value is undefined')->if($asserter->setWith($value))->then->boolean($asserter->isSetByReference())->isFalse()->exception(function () use($asserter, $value) { $asserter->isReferenceTo($value); })->isInstanceOf('logicException')->hasMessage('Value is not set by reference')->if($asserter->setByReferenceWith($value))->and($reference =& $value)->then->boolean($asserter->wasSet())->isTrue()->boolean($asserter->isSetByReference())->isTrue()->object($asserter->isReferenceTo($reference))->isIdenticalTo($asserter)->if($notReference = uniqid())->then->exception(function () use($asserter, $notReference) { $asserter->isReferenceTo($notReference); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not a reference to %s'), $asserter, $asserter->getTypeOf($notReference)))->if($value = new \exception())->and($reference = $value)->and($asserter->setByReferenceWith($value))->then->boolean($asserter->wasSet())->isTrue()->boolean($asserter->isSetByReference())->isTrue()->object($asserter->isReferenceTo($reference))->isIdenticalTo($asserter)->if($notReference = new \exception())->then->exception(function () use($asserter, $notReference) { $asserter->isReferenceTo($notReference); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not a reference to %s'), $asserter, $asserter->getTypeOf($notReference))); }
protected function valueIsSet($message = 'Array is undefined') { return parent::valueIsSet($message); }
public function testIsNotTrue() { $this->if($asserter = new sut($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) { $asserter->isNotNull(rand(-PHP_INT_MAX, PHP_INT_MAX)); })->isInstanceOf('logicException')->hasMessage('Value is undefined')->if($asserter->setWith(uniqid()))->then->object($asserter->isNotTrue())->isIdenticalTo($asserter)->if($asserter->setWith(true))->then->exception(function () use($asserter) { $asserter->isNotTrue(); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is true'), $asserter)); }
protected function matches($actual) { $asserter = new asserters\variable(); $asserter->setWith($actual)->isNotIdenticalTo($this->expected); }