isEqualTo() public méthode

public isEqualTo ( $value, $failMessage = null )
Exemple #1
0
 public function testIsEqualTo()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) {
         $asserter->isEqualTo(rand(-PHP_INT_MAX, PHP_INT_MAX));
     })->isInstanceOf('logicException')->hasMessage('Value is undefined')->if($asserter->setWith($value = uniqid()))->then->object($asserter->isEqualTo($value))->isIdenticalTo($asserter)->if($diff = new diffs\variable())->then->exception(function () use(&$line, $asserter, &$notEqualValue) {
         $line = __LINE__;
         $asserter->isEqualTo($notEqualValue = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not equal to %s'), $asserter, $asserter->getTypeOf($notEqualValue)) . PHP_EOL . $diff->setExpected($notEqualValue)->setActual($asserter->getValue()))->if($asserter->setWith(1))->and($otherDiff = new diffs\variable())->then->object($asserter->isEqualTo('1'))->isIdenticalTo($asserter)->exception(function () use(&$otherLine, $asserter, &$otherNotEqualValue, &$otherFailMessage) {
         $otherLine = __LINE__;
         $asserter->isEqualTo($otherNotEqualValue = uniqid(), $otherFailMessage = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($otherFailMessage . PHP_EOL . $otherDiff->setExpected($otherNotEqualValue)->setActual($asserter->getValue()));
 }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
 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));
     }
 }
Exemple #4
0
 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));
     }
 }
Exemple #5
0
 /**
  * {@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;
 }
Exemple #6
0
 public function isEqualTo($value, $failMessage = null)
 {
     static::check($value, __FUNCTION__);
     return parent::isEqualTo($value, $failMessage);
 }