Example #1
0
 public function test__construct()
 {
     $this->testedClass->isSubClassOf('mageekguy\\atoum\\template')->exception(function () {
         $template = new template\tag('');
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Tag must not be an empty string')->exception(function () {
         $template = new template\tag(uniqid(), null, 0);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Line must be greater than 0')->exception(function () {
         $template = new template\tag(uniqid(), null, -rand(1, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Line must be greater than 0')->exception(function () {
         $template = new template\tag(uniqid(), null, rand(1, PHP_INT_MAX), 0);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Offset must be greater than 0')->exception(function () {
         $template = new template\tag(uniqid(), null, rand(1, PHP_INT_MAX), -rand(1, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Offset must be greater than 0')->if($template = new template\tag($tag = uniqid()))->then->string($template->getTag())->isEqualTo($tag)->string($template->getData())->isEmpty()->variable($template->getLine())->isNull()->variable($template->getOffset())->isNull()->if($template = new template\tag($tag = uniqid(), $data = uniqid(), $line = rand(1, PHP_INT_MAX), $offset = rand(1, PHP_INT_MAX)))->then->string($template->getTag())->isEqualTo($tag)->string($template->getData())->isEqualTo($data)->integer($template->getLine())->isEqualTo($line)->integer($template->getOffset())->isEqualTo($offset);
 }
Example #2
0
 public function test__unset()
 {
     $template = new atoum\template();
     $template->addChild($childTag = new atoum\template\tag(uniqid()));
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty();
     unset($template->{$childTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty();
     $template->{$childTag->getTag()} = uniqid();
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isNotEmpty();
     unset($template->{$childTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty();
     $template->addChild($otherChildTag = new atoum\template\tag(uniqid()));
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isEmpty();
     unset($template->{$childTag->getTag()});
     unset($template->{$otherChildTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isEmpty();
     $template->{$childTag->getTag()} = uniqid();
     $template->{$otherChildTag->getTag()} = uniqid();
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isNotEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isNotEmpty();
     unset($template->{$childTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isNotEmpty();
     unset($template->{$otherChildTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isEmpty();
     $childTag->addChild($littleChildTag = new atoum\template\tag(uniqid()));
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isEmpty()->boolean(isset($template->{$littleChildTag->getTag()}))->isTrue()->string($littleChildTag->getData())->isEmpty();
     $template->{$childTag->getTag()} = uniqid();
     $template->{$otherChildTag->getTag()} = uniqid();
     $template->{$littleChildTag->getTag()} = uniqid();
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isNotEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isNotEmpty()->boolean(isset($template->{$littleChildTag->getTag()}))->isTrue()->string($littleChildTag->getData())->isNotEmpty();
     unset($template->{$childTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isNotEmpty()->boolean(isset($template->{$littleChildTag->getTag()}))->isTrue()->string($littleChildTag->getData())->isNotEmpty();
     unset($template->{$otherChildTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isEmpty()->boolean(isset($template->{$littleChildTag->getTag()}))->isTrue()->string($littleChildTag->getData())->isNotEmpty();
     unset($template->{$littleChildTag->getTag()});
     $this->assert->boolean(isset($template->{$childTag->getTag()}))->isTrue()->string($childTag->getData())->isEmpty()->boolean(isset($template->{$otherChildTag->getTag()}))->isTrue()->string($otherChildTag->getData())->isEmpty()->boolean(isset($template->{$littleChildTag->getTag()}))->isTrue()->string($littleChildTag->getData())->isEmpty();
 }
Example #3
0
 public function testCurrent()
 {
     $iterator = new template\iterator();
     $this->assert->boolean($iterator->valid())->isFalse()->variable($iterator->current())->isNull();
     $template = new atoum\template();
     $template->addChild($tag = new template\tag(uniqid()));
     $iterator->addTag($tag->getTag(), $template);
     $this->assert->boolean($iterator->valid())->isTrue()->object($iterator->current())->isIdenticalTo($tag);
     $iterator->next();
     $this->assert->boolean($iterator->valid())->isFalse()->variable($iterator->current())->isNull();
 }
Example #4
0
 public function testGetByTag()
 {
     $this->if($this->newTestedInstance)->then->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isZero()->if($this->testedInstance->addChild($tag = new atoum\template\tag(uniqid())))->then->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isZero()->object($iterator = $this->testedInstance->getByTag($tag->getTag()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isEqualTo(1)->object($iterator->current())->isIdenticalTo($tag)->if($this->testedInstance->addChild($otherTag = new atoum\template\tag($tag->getTag())))->then->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isZero()->object($iterator = $this->testedInstance->getByTag($tag->getTag()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isEqualTo(2)->object($iterator->current())->isIdenticalTo($tag)->object($iterator->next()->current())->isIdenticalTo($otherTag)->if($tag->addChild($childTag = new atoum\template\tag($tag->getTag())))->then->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isZero()->object($iterator = $this->testedInstance->getByTag($tag->getTag()))->isInstanceOf('mageekguy\\atoum\\template\\iterator')->sizeOf($iterator)->isEqualTo(3)->object($iterator->current())->isIdenticalTo($tag)->object($iterator->next()->current())->isIdenticalTo($childTag)->object($iterator->next()->current())->isIdenticalTo($otherTag);
 }