Skip to content

Commit

Permalink
Update Reader:
Browse files Browse the repository at this point in the history
- add statXML()
  • Loading branch information
webeweb committed Sep 25, 2019
1 parent 3ad3ccf commit 9244a21
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/IO/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use WBW\Library\XMLTV\Model\Tv;
use WBW\Library\XMLTV\Parser\Parser;
use WBW\Library\XMLTV\Parser\ParserHelper;
use WBW\Library\XMLTV\Statistic\Statistic;
use WBW\Library\XMLTV\Statistic\Statistics;

/**
* Reader.
Expand Down Expand Up @@ -70,4 +72,21 @@ public static function readXML($filename, LoggerInterface $logger = null) {

return Parser::parseTv($document->documentElement);
}

/**
* Stat an XML file.
*
* @param string $filename The filename.
* @return Statistic[] Returns the statistics.
*/
public static function statXML($filename) {

$document = new DOMDocument();
$document->load($filename);

$statistics = new Statistics();
$statistics->parse($document->documentElement);

return $statistics->getStatistics();
}
}
13 changes: 12 additions & 1 deletion tests/IO/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testLoadXML() {
}

/**
* Tests tha readXML() method.
* Tests the readXML() method.
*
* @return void
*/
Expand All @@ -66,4 +66,15 @@ public function testReadXML() {
$this->assertEquals("source-info-name", $res->getSourceInfoName());
$this->assertEquals("source-info-url", $res->getSourceInfoURL());
}

/**
* Tests the statXML() method.
*
* @return void
*/
public function testStatXML() {

$res = Reader::statXML($this->filename);
$this->assertCount(85, $res);
}
}

0 comments on commit 9244a21

Please sign in to comment.