Ejemplo n.º 1
0
 public function testIsEmpty()
 {
     $this->if($asserter = new asserters\utf8String($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isEmpty();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Value is undefined')->if($asserter->setWith($string = $this->getRandomUtf8String()))->and($diff = new diffs\variable())->then->exception(function () use($asserter) {
         $asserter->isEmpty();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('strings are not equals') . PHP_EOL . $diff->setReference('')->setData($string))->if($asserter->setWith(''))->then->object($asserter->isEmpty())->isIdenticalTo($asserter);
 }
Ejemplo n.º 2
0
 public function testIsIdenticalTo()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) {
         $asserter->isIdenticalTo(rand(-PHP_INT_MAX, PHP_INT_MAX));
     })->isInstanceOf('logicException')->hasMessage('Value is undefined')->if($asserter->setWith($value = rand(-PHP_INT_MAX, PHP_INT_MAX)))->then->object($asserter->isIdenticalTo($value))->isIdenticalTo($asserter)->if($diff = new diffs\variable())->then->exception(function () use($asserter, &$notIdenticalValue, $value) {
         $asserter->isIdenticalTo($notIdenticalValue = (string) $value);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not identical to %s'), $asserter, $asserter->getTypeOf($notIdenticalValue)) . PHP_EOL . $diff->setExpected($notIdenticalValue)->setActual($asserter->getValue()))->exception(function () use($asserter, $notIdenticalValue, &$failMessage) {
         $asserter->isIdenticalTo($notIdenticalValue, $failMessage = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($failMessage . PHP_EOL . $diff->setExpected($notIdenticalValue)->setActual($asserter->getValue()));
 }
Ejemplo n.º 3
0
 public function testIsFalse()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isFalse();
     })->isInstanceOf('logicException')->hasMessage('Value is undefined')->if($asserter->setWith(false))->then->object($asserter->isFalse())->isIdenticalTo($asserter)->if($asserter->setWith(true))->and($diff = new diffs\variable())->then->exception(function () use($asserter) {
         $asserter->isFalse();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not false'), $asserter) . PHP_EOL . $diff->setExpected(false)->setActual(true))->if($asserter->setWith(false))->then->object($asserter->isFalse)->isIdenticalTo($asserter)->if($asserter->setWith(true))->and($diff = new diffs\variable())->then->exception(function () use($asserter) {
         $asserter->isFalse;
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not false'), $asserter) . PHP_EOL . $diff->setExpected(false)->setActual(true));
 }
Ejemplo n.º 4
0
 public function testIsMd5()
 {
     $this->if($asserter = new asserters\hash($generator = new asserter\generator()))->and($asserter->setWith($value = hash('md5', 'hello')))->then->object($asserter->isMd5())->isIdenticalTo($asserter)->if($asserter->setWith($value = strtoupper($value)))->then->object($asserter->isMd5())->isIdenticalTo($asserter)->if($asserter->setWith($newvalue = substr($value, 1)))->and($diff = new diffs\variable())->and($diff->setReference($newvalue)->setData($value))->then->exception(function () use($asserter, &$line) {
         $line = __LINE__;
         $asserter->isMd5();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($this->getLocale()->_('%s should be a string of %d characters'), $asserter, strlen($value)))->if($asserter->setWith($newvalue = 'z' . substr($value, 1)))->and($diff = new diffs\variable())->and($diff->setReference($newvalue)->setData($value))->then->exception(function () use($asserter, &$line) {
         $line = __LINE__;
         $asserter->isMd5();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s does not match given pattern'), $asserter));
 }
Ejemplo n.º 5
0
 public function isIdenticalTo($value, $failMessage = null)
 {
     self::check($value, __FUNCTION__);
     if ($this->valueIsSet()->value === $value) {
         $this->pass();
     } else {
         $diff = new diffs\variable();
         $this->fail(($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not identical to %s'), $this, $this->getTypeOf($value))) . PHP_EOL . $diff->setExpected($value)->setActual($this->value));
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * @dataProvider dataProviderNearlyEqualTo
  */
 public function testIsNearlyEqualTo($value, $testValue, $epsilon, $pass)
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->and($asserter->setWith($value));
     if ($pass) {
         $this->object($asserter->isNearlyEqualTo($testValue, $epsilon))->isIdenticalTo($asserter);
     } else {
         $this->if($diff = new diffs\variable())->and($diff->setExpected($testValue)->setActual($value))->then->exception(function () use($asserter, $testValue, $epsilon) {
             $asserter->isNearlyEqualTo($testValue, $epsilon);
         })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not nearly equal to %s with epsilon %s'), $asserter, $asserter->getTypeOf($testValue), $epsilon) . PHP_EOL . $diff);
     }
 }
Ejemplo n.º 7
0
 public function isNearlyEqualTo($value, $epsilon = null, $failMessage = null)
 {
     static::check($value, __FUNCTION__);
     if ($this->valueIsSet()->value !== $value) {
         // see http://www.floating-point-gui.de/errors/comparison/ for more informations
         $absValue = abs($value);
         $absCurrentValue = abs($this->value);
         $offset = abs($absCurrentValue - $absValue);
         $offsetIsNaN = is_nan($offset);
         if ($offsetIsNaN === false && $epsilon === null) {
             $epsilon = pow(10, -ini_get('precision'));
         }
         switch (true) {
             case $offsetIsNaN === true:
             case $offset / ($absCurrentValue + $absValue) >= $epsilon:
             case $absCurrentValue * $absValue == 0 && $offset >= pow($epsilon, 2):
                 $diff = new diffs\variable();
                 $this->fail(($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not nearly equal to %s with epsilon %s'), $this, $this->getTypeOf($value), $epsilon)) . PHP_EOL . $diff->setExpected($value)->setActual($this->value));
         }
     }
     return $this;
 }
Ejemplo n.º 8
0
 public function testMake()
 {
     $diff = new tools\diffs\variable();
     $exception = null;
     try {
         $diff->make();
     } catch (\exception $exception) {
     }
     $this->assert->exception($exception)->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Reference is undefined');
     $diff->setReference($reference = uniqid());
     try {
         $diff->make();
     } catch (\exception $exception) {
     }
     $this->assert->exception($exception)->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Data is undefined');
     $diff->setData($reference);
     $this->assert->array($diff->make())->isEqualTo(array(self::dumpAsString($reference)));
 }
Ejemplo n.º 9
0
 public function testIsNotIdenticalTo()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isNotIdenticalTo(new \mock\object());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Array is undefined')->if($asserter->setWith($array = array(1, 2)))->then->object($asserter->isNotIdenticalTo(array('1', 2)))->isIdenticalTo($asserter)->exception(function () use($asserter, $array) {
         $asserter->isNotIdenticalTo($array);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is identical to %s'), $asserter, $asserter->getTypeOf($array)))->if($asserter->integer)->then->object($asserter->isNotIdenticalTo(array('1', 2)))->isIdenticalTo($asserter)->if($asserter->integer[1])->then->object($asserter->isEqualTo(2))->isIdenticalTo($asserter)->object($asserter->isEqualTo(2)->isNotEqualTo(5))->isIdenticalTo($asserter)->if($diff = new diffs\variable())->then->exception(function () use($asserter, &$expectedValue) {
         $asserter->isEqualTo($expectedValue = rand(3, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not equal to %s'), $asserter->getTypeOf($asserter->getInnerValue()), $asserter->getTypeOf($expectedValue)) . PHP_EOL . $diff->setExpected($expectedValue)->setActual(2));
 }
Ejemplo n.º 10
0
 public function testIsLessThanOrEqualTo()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->and($asserter->setWith($value = -rand(1, PHP_INT_MAX - 1)))->then->object($asserter->isLessThanOrEqualTo(0))->isIdenticalTo($asserter)->object($asserter->isLessThanOrEqualTo($value))->isIdenticalTo($asserter)->if($diff = new diffs\variable())->and($diff->setExpected(-PHP_INT_MAX)->setActual($value))->then->exception(function () use($asserter, $value) {
         $asserter->isLessThanOrEqualTo(-PHP_INT_MAX);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not less than or equal to %s'), $asserter, $asserter->getTypeOf(-PHP_INT_MAX)));
 }