Ejemplo n.º 1
0
 /**
  * @param string $element
  *
  * @return $this
  */
 public function hasElement($element)
 {
     $asserter = new Element($this->generator, $this);
     return $asserter->setWith($this->valueIsSet()->value->filter($element), $element);
 }
Ejemplo n.º 2
0
 public function testEnd()
 {
     $this->given($document = new \DOMDocument())->if($generator = new asserter\generator())->and($parent = new CrawlerAssert($generator))->and($object = new TestedClass($generator, $parent))->and($crawler = new \mock\Symfony\Component\DomCrawler\Crawler())->and($this->calling($crawler)->count = 0)->and($object->setWith($crawler))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at least %d element(s) matching %s, found %d.'), 1, '*', 0))->if($this->calling($crawler)->count = 1)->then->object($object->end())->isIdenticalTo($parent)->if($object->atLeast(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at least %d element(s) matching %s, found %d.'), 2, '*', 1))->if($this->calling($crawler)->count = 3)->then->object($object->end())->isIdenticalTo($parent)->if($object->atMost(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at most %d element(s) matching %s, found %d.'), 2, '*', 3))->if($object->exactly(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected %d element(s) matching %s, found %d.'), 2, '*', 3))->if($this->calling($crawler)->count = 2)->then->object($object->end())->isIdenticalTo($parent)->if($generator = new asserter\generator())->and($parent = new CrawlerAssert($generator))->and($object = new TestedClass($generator, $parent))->and($elem = $document->createElement(uniqid('_')))->and($otherElem = $document->createElement(uniqid('_')))->and($crawler = new \Symfony\Component\DomCrawler\Crawler(array($elem, $otherElem)))->and($object->setWith($crawler))->and($object->withAttribute($attr = uniqid('_'), $value = uniqid()))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at least %d element(s) matching %s, found %d.'), 1, '*[' . $attr . '="' . $value . '"]', 0))->if($elem->setAttribute($attr, $value))->then->object($object->end())->isIdenticalTo($parent)->if($object->exactly(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected %d element(s) matching %s, found %d.'), 2, '*[' . $attr . '="' . $value . '"]', 1))->if($object->withContent($content = uniqid()))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected %d element(s) matching %s, found %d.'), 2, '*[' . $attr . '="' . $value . '"][@content="' . $content . '"]', 0));
 }
Ejemplo n.º 3
0
 /**
  * @param string $element
  *
  * @return $this
  */
 public function hasElement($element)
 {
     $asserter = new Element($this->getGenerator(), $this->getAnalyzer(), $this->getLocale());
     return $asserter->setParent($this)->setWith($this->valueIsSet()->value->filter($element));
 }