Skip to content

Commit

Permalink
Fix unit tests. (#21)
Browse files Browse the repository at this point in the history
* Fix unit tests.

* Enable code coverage report generation

* Local variable is shadowing function argument.

---------

Co-authored-by: Grzegorz Drozd <[email protected]>
  • Loading branch information
GrzegorzDrozd and Grzegorz Drozd authored Nov 7, 2023
1 parent e11f688 commit 4d144ba
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 43 deletions.
6 changes: 6 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>

<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>
</phpunit>
28 changes: 14 additions & 14 deletions tests/DownloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public function testDownload($url)
$parser = new SitemapParser('SitemapParser');
$this->assertInstanceOf('vipnytt\SitemapParser', $parser);
$parser->parse($url);
$this->assertInternalType('array', $parser->getSitemaps());
$this->assertInternalType('array', $parser->getURLs());
$this->assertIsArray($parser->getSitemaps());
$this->assertIsArray($parser->getURLs());
$this->assertTrue(count($parser->getSitemaps()) > 0 || count($parser->getURLs()) > 0);
foreach ($parser->getSitemaps() as $url => $tags) {
$this->assertInternalType('string', $url);
$this->assertInternalType('array', $tags);
$this->assertTrue($url === $tags['loc']);
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL));
foreach ($parser->getSitemaps() as $parsedUrl => $tags) {
$this->assertIsString($parsedUrl);
$this->assertIsArray($tags);
$this->assertTrue($parsedUrl === $tags['loc']);
$this->assertNotFalse(filter_var($parsedUrl, FILTER_VALIDATE_URL));
}
foreach ($parser->getURLs() as $url => $tags) {
$this->assertInternalType('string', $url);
$this->assertInternalType('array', $tags);
$this->assertTrue($url === $tags['loc']);
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL));
foreach ($parser->getURLs() as $parsedUrl => $tags) {
$this->assertIsString($parsedUrl);
$this->assertIsArray($tags);
$this->assertTrue($parsedUrl === $tags['loc']);
$this->assertNotFalse(filter_var($parsedUrl, FILTER_VALIDATE_URL));
}
}

Expand All @@ -40,10 +40,10 @@ public function generateDataForTest()
{
return [
[
'http://www.google.com/sitemap.xml',
'https://www.google.com/sitemap.xml',
],
[
'http://php.net/sitemap.xml',
'https://php.net/sitemap.xml',
],
[
'https://www.yahoo.com/news/sitemaps/news-sitemap_index_US_en-US.xml.gz',
Expand Down
24 changes: 12 additions & 12 deletions tests/RecursiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ public function testRecursive($url)
$parser = new SitemapParser('SitemapParser');
$this->assertInstanceOf('vipnytt\SitemapParser', $parser);
$parser->parseRecursive($url);
$this->assertInternalType('array', $parser->getSitemaps());
$this->assertInternalType('array', $parser->getURLs());
$this->assertIsArray($parser->getSitemaps());
$this->assertIsArray($parser->getURLs());
$this->assertTrue(count($parser->getSitemaps()) > 1 || count($parser->getURLs()) > 100);
foreach ($parser->getSitemaps() as $url => $tags) {
$this->assertInternalType('string', $url);
$this->assertInternalType('array', $tags);
$this->assertTrue($url === $tags['loc']);
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL));
foreach ($parser->getSitemaps() as $parsedUrl => $tags) {
$this->assertIsString($parsedUrl);
$this->assertIsArray($tags);
$this->assertTrue($parsedUrl === $tags['loc']);
$this->assertNotFalse(filter_var($parsedUrl, FILTER_VALIDATE_URL));
}
foreach ($parser->getURLs() as $url => $tags) {
$this->assertInternalType('string', $url);
$this->assertInternalType('array', $tags);
$this->assertTrue($url === $tags['loc']);
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL));
foreach ($parser->getURLs() as $parsedUrl => $tags) {
$this->assertIsString($parsedUrl);
$this->assertIsArray($tags);
$this->assertTrue($parsedUrl === $tags['loc']);
$this->assertNotFalse(filter_var($parsedUrl, FILTER_VALIDATE_URL));
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/SitemapIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ public function generateDataForTest()
'http://www.example.com/sitemap2.xml' => [
'loc' => 'http://www.example.com/sitemap2.xml',
'lastmod' => '2004-10-01T18:23:17+00:00',
'namespaces'=> [],
],
'http://www.example.com/sitemap3.xml' => [
'loc' => 'http://www.example.com/sitemap3.xml',
'lastmod' => '2005-09-01T17:22:16+00:00',
'namespaces'=> [],
],
'http://www.example.com/sitemap4.xml.gz' => [
'loc' => 'http://www.example.com/sitemap4.xml.gz',
'lastmod' => '2006-08-01T16:21:15+00:00',
'namespaces'=> [],
],
]
]
Expand Down
24 changes: 12 additions & 12 deletions tests/StringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ public function testString($url)
$parser = new SitemapParser('SitemapParser', ['strict' => false]);
$this->assertInstanceOf('vipnytt\SitemapParser', $parser);
$parser->parse($url);
$this->assertInternalType('array', $parser->getSitemaps());
$this->assertInternalType('array', $parser->getURLs());
$this->assertIsArray($parser->getSitemaps());
$this->assertIsArray($parser->getURLs());
$this->assertTrue(count($parser->getSitemaps()) > 1);
$this->assertTrue(count($parser->getURLs()) >= 1000);
foreach ($parser->getSitemaps() as $url => $tags) {
$this->assertInternalType('string', $url);
$this->assertInternalType('array', $tags);
$this->assertTrue($url === $tags['loc']);
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL));
foreach ($parser->getSitemaps() as $parsedUrl => $tags) {
$this->assertIsString($parsedUrl);
$this->assertIsArray($tags);
$this->assertTrue($parsedUrl === $tags['loc']);
$this->assertNotFalse(filter_var($parsedUrl, FILTER_VALIDATE_URL));
}
foreach ($parser->getURLs() as $url => $tags) {
$this->assertInternalType('string', $url);
$this->assertInternalType('array', $tags);
$this->assertTrue($url === $tags['loc']);
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL));
foreach ($parser->getURLs() as $parsedUrl => $tags) {
$this->assertIsString($parsedUrl);
$this->assertIsArray($tags);
$this->assertTrue($parsedUrl === $tags['loc']);
$this->assertNotFalse(filter_var($parsedUrl, FILTER_VALIDATE_URL));
}
}

Expand Down
15 changes: 10 additions & 5 deletions tests/StripCommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,28 @@ public function testStrict($url, $body)
$this->assertEquals([
'https://www.bellinghambaymarathon.org/post-sitemap.xml' => [
'loc' => 'https://www.bellinghambaymarathon.org/post-sitemap.xml',
'lastmod' => '2019-07-19T10:18:07-07:00'
'lastmod' => '2019-07-19T10:18:07-07:00',
'namespaces'=> [],
],
'https://www.bellinghambaymarathon.org/page-sitemap.xml' => [
'loc' => 'https://www.bellinghambaymarathon.org/page-sitemap.xml',
'lastmod' => '2019-07-29T06:51:35-07:00'
'lastmod' => '2019-07-29T06:51:35-07:00',
'namespaces'=> [],
],
'https://www.bellinghambaymarathon.org/category-sitemap.xml' => [
'loc' => 'https://www.bellinghambaymarathon.org/category-sitemap.xml',
'lastmod' => '2019-07-19T10:18:07-07:00'
'lastmod' => '2019-07-19T10:18:07-07:00',
'namespaces'=> [],
],
'https://www.bellinghambaymarathon.org/post_tag-sitemap.xml' => [
'loc' => 'https://www.bellinghambaymarathon.org/post_tag-sitemap.xml',
'lastmod' => '2019-05-16T10:06:14-07:00'
'lastmod' => '2019-05-16T10:06:14-07:00',
'namespaces'=> [],
],
'https://www.bellinghambaymarathon.org/author-sitemap.xml' => [
'loc' => 'https://www.bellinghambaymarathon.org/author-sitemap.xml',
'lastmod' => '2018-08-22T17:12:52-07:00'
'lastmod' => '2018-08-22T17:12:52-07:00',
'namespaces'=> [],
],
], $parser->getSitemaps());
$this->assertEquals([], $parser->getURLs());
Expand Down
5 changes: 5 additions & 0 deletions tests/URLSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,35 @@ public function generateDataForTest()
'lastmod' => '2005-01-01',
'changefreq' => 'monthly',
'priority' => '0.8',
'namespaces'=> [],
],
'http://www.example.com/catalog?item=12&desc=vacation_hawaii' => [
'loc' => 'http://www.example.com/catalog?item=12&desc=vacation_hawaii',
'changefreq' => 'weekly',
'lastmod' => null,
'priority' => null,
'namespaces'=> [],
],
'http://www.example.com/catalog?item=73&desc=vacation_new_zealand' => [
'loc' => 'http://www.example.com/catalog?item=73&desc=vacation_new_zealand',
'lastmod' => '2004-12-23',
'changefreq' => 'weekly',
'priority' => null,
'namespaces'=> [],
],
'http://www.example.com/catalog?item=74&desc=vacation_newfoundland' => [
'loc' => 'http://www.example.com/catalog?item=74&desc=vacation_newfoundland',
'lastmod' => '2004-12-23T18:00:15+00:00',
'priority' => '0.3',
'changefreq' => null,
'namespaces'=> [],
],
'http://www.example.com/catalog?item=83&desc=vacation_usa' => [
'loc' => 'http://www.example.com/catalog?item=83&desc=vacation_usa',
'lastmod' => '2004-11-23',
'changefreq' => null,
'priority' => null,
'namespaces'=> [],
],
]
]
Expand Down

0 comments on commit 4d144ba

Please sign in to comment.