Exemplo n.º 1
0
 public function testContains()
 {
     $this->if($asserter = new asserters\string($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->contains(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Value is undefined')->if($asserter->setWith($string = __METHOD__))->and($diff = new diffs\variable())->then->exception(function () use($asserter, &$fragment) {
         $asserter->contains($fragment = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($this->getLocale()->_('String does not contain %s'), $fragment))->object($asserter->contains($string))->isIdenticalTo($asserter)->if($asserter->setWith(uniqid() . $string . uniqid()))->then->object($asserter->contains($string))->isIdenticalTo($asserter)->exception(function () use($asserter, $string, &$fragment) {
         $asserter->contains($fragment = strtoupper($string));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($this->getLocale()->_('String does not contain %s'), $fragment));
 }
 public function setWith($value, $charlist = null, $checkType = true)
 {
     parent::setWith($value, $charlist, $checkType);
     if ($checkType === true) {
         if ($this->analyzer->isUtf8($this->value) === true) {
             $this->pass();
         } else {
             $this->fail($this->_('%s is not an UTF-8 string', $this));
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 public function __get($asserter)
 {
     switch (strtolower($asserter)) {
         case 'issha1':
         case 'issha256':
         case 'issha512':
         case 'ismd5':
             return $this->{$asserter}();
         default:
             return parent::__get($asserter);
     }
 }
 public function setWith($value, $charlist = null, $checkType = true)
 {
     parent::setWith($value, $charlist, false);
     if ($checkType === true) {
         if (self::isObject($value) === false) {
             $this->fail($this->_('%s is not an object', $this->getTypeOf($value)));
         } else {
             $this->pass();
             $this->value = (string) $this->value;
         }
     }
     return $this;
 }
Exemplo n.º 5
0
 public function setWith($value = null, $label = null, $charlist = null, $checkType = true)
 {
     if ($value instanceof \closure) {
         ob_start();
         $value();
         $value = ob_get_clean();
     } else {
         if ($value === null && ob_get_level() > 0) {
             $value = ob_get_clean();
             ob_start();
         }
     }
     return parent::setWith($value, $label, $charlist, $checkType);
 }
Exemplo n.º 6
0
 public function getTypeOf($mixed)
 {
     return is_string($mixed) === false ? parent::getTypeOf($mixed) : sprintf($this->getLocale()->_('string(%s) \'%s\''), mb_strlen($mixed, 'UTF-8'), $mixed);
 }
Exemplo n.º 7
0
 public function testLength()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->length;
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Value is undefined')->if($asserter->setWith(''))->then->object($integer = $asserter->length)->isInstanceOf('mageekguy\\atoum\\asserters\\integer')->integer($integer->getValue())->isEqualTo(0)->if($asserter->setWith($str = uniqid()))->then->object($integer = $asserter->length)->isInstanceOf('mageekguy\\atoum\\asserters\\integer')->integer($integer->getValue())->isEqualTo(strlen($str));
 }
Exemplo n.º 8
0
 public function __toString()
 {
     return is_string($this->value) === false ? parent::__toString() : sprintf($this->getLocale()->_('string(%s) \'%s\''), mb_strlen($this->value, 'UTF-8'), addcslashes($this->value, $this->charlist));
 }