Skip to content

Commit 0bcc2ad

Browse files
author
Harrison Ifeanyichukwu
committed
test: test the Parser API endpoints, targeting exception handling
1 parent 4808589 commit 0bcc2ad

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/ParserTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Forensic\FeedParser\Test;
5+
6+
use Forensic\FeedParser\Parser;
7+
use PHPUnit\Framework\TestCase;
8+
use Forensic\FeedParser\Exceptions\InvalidURLException;
9+
use Forensic\FeedParser\Exceptions\ResourceNotFoundException;
10+
use Forensic\FeedParser\Exceptions\FileNotFoundException;
11+
12+
class ParserTest extends TestCase
13+
{
14+
private $_parser = null;
15+
16+
public function setup()
17+
{
18+
$this->_parser = new Parser();
19+
}
20+
21+
public function testInvalidUrl()
22+
{
23+
$this->expectException(InvalidURLException::class);
24+
$this->_parser->parseFromUrl('www.google.com');
25+
}
26+
27+
public function testUnExistingUrl()
28+
{
29+
$this->expectException(ResourceNotFoundException::class);
30+
$this->_parser->parseFromUrl('http://feed.fjsfoundations.com');
31+
}
32+
33+
public function testUnExistingFile()
34+
{
35+
$this->expectException(FileNotFoundException::class);
36+
$this->_parser->parseFromFile('./somefile.xml');
37+
}
38+
}

0 commit comments

Comments
 (0)