function get_total_percentage($coverage_html_path)
{
    $dom = new Zend\Dom\Query(file_get_contents($coverage_html_path), 'UTF-8');
    $total = $dom->queryXpath('//table[@cellpadding="2"]//tr[3]//td[3]');
    return $total->current()->nodeValue;
}
Example #2
0
 /**
  * Evaluate an object to see if it fits the constraints
  *
  * @param  string $other String to examine
  * @param  null|string Assertion type
  * @return bool
  */
 public function evaluate($other, $assertType = null)
 {
     if (strstr($assertType, 'Not')) {
         $this->setNegate(true);
         $assertType = str_replace('Not', '', $assertType);
     }
     if (strstr($assertType, 'Xpath')) {
         $this->setUseXpath(true);
         $assertType = str_replace('Xpath', 'Query', $assertType);
     }
     if (!in_array($assertType, $this->_assertTypes)) {
         throw new Exception\ConstraintException(sprintf('Invalid assertion type "%s" provided to %s constraint', $assertType, __CLASS__));
     }
     $this->_assertType = $assertType;
     $method = $this->_useXpath ? 'queryXpath' : 'execute';
     $domQuery = new \Zend\Dom\Query($other);
     $domQuery->registerXpathNamespaces($this->_xpathNamespaces);
     $result = $domQuery->{$method}($this->_path);
     $argv = func_get_args();
     $argc = func_num_args();
     switch ($assertType) {
         case self::ASSERT_CONTENT_CONTAINS:
             if (3 > $argc) {
                 throw new Exception\ConstraintException('No content provided against which to match');
             }
             $this->_content = $content = $argv[2];
             return $this->_negate ? $this->_notMatchContent($result, $content) : $this->_matchContent($result, $content);
         case self::ASSERT_CONTENT_REGEX:
             if (3 > $argc) {
                 throw new Exception\ConstraintException('No pattern provided against which to match');
             }
             $this->_content = $content = $argv[2];
             return $this->_negate ? $this->_notRegexContent($result, $content) : $this->_regexContent($result, $content);
         case self::ASSERT_CONTENT_COUNT:
         case self::ASSERT_CONTENT_COUNT_MIN:
         case self::ASSERT_CONTENT_COUNT_MAX:
             if (3 > $argc) {
                 throw new Exception\ConstraintException('No count provided against which to compare');
             }
             $this->_content = $content = $argv[2];
             return $this->_countContent($result, $content, $assertType);
         case self::ASSERT_QUERY:
         default:
             if ($this->_negate) {
                 return 0 == count($result);
             } else {
                 return 0 != count($result);
             }
     }
 }
Example #3
0
 public function index03Action()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>";
     $dom = new \Zend\Dom\Query($this->_html);
     $nameNodes = $dom->execute("div[class='caption'] h3");
     $imgNodes = $dom->execute("div[class='thumbnail'] img");
     $yearNodes = $dom->execute("div[class='caption'] p");
     echo $totalItems = $nameNodes->count();
     $result = array();
     for ($i = 0; $i < $totalItems; $i++) {
         $result[$i]['name'] = $nameNodes[$i]->nodeValue;
         $result[$i]['year'] = $yearNodes[$i]->nodeValue;
         $result[$i]['image'] = $imgNodes[$i]->getAttribute("src");
     }
     echo "<pre style='font-weight:bold'>";
     print_r($result);
     echo "</pre>";
     return false;
 }