Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaishiyoku committed Aug 17, 2023
1 parent c3df951 commit c83c378
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function testGetImageUrlsForFeedItem(): void

$imageUrls = Helper::getImageUrlsForFeedItem($feedItemUrl, $content, new Client());

$this->assertEquals(['https://www.golem.de/2107/158391-284735-284731_rc.jpg'], $imageUrls->toArray());
static::assertEquals(['https://www.golem.de/2107/158391-284735-284731_rc.jpg'], $imageUrls->toArray());
}

/**
* @dataProvider faviconProvider
*/
public function testGetHttpContentTypeForUrl(string $faviconUrl, ?string $expectedContentType): void
{
$this->assertSame($expectedContentType, Helper::getHttpContentTypeForUrl($faviconUrl, new Client()));
static::assertSame($expectedContentType, Helper::getHttpContentTypeForUrl($faviconUrl, new Client()));
}

/**
Expand Down Expand Up @@ -85,6 +85,6 @@ protected function tearDown(): void
{
parent::tearDown();

$this->addToAssertionCount($this->failingTestClassMock->mockery_getExpectationCount());
static::addToAssertionCount($this->failingTestClassMock->mockery_getExpectationCount());
}
}
66 changes: 33 additions & 33 deletions tests/HeraRssCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ public function testCompareTo(): void
public function testDiscoverFeedUrls(string $url, array $expectedUrls, ?string $expectedFaviconUrl = null, bool $throwsConnectException = false): void
{
if ($throwsConnectException) {
$this->expectException(ConnectException::class);
static::expectException(ConnectException::class);
}

$actual = $this->heraRssCrawler->discoverFeedUrls($url);

if (!$throwsConnectException) {
$this->assertEquals($expectedUrls, $actual->toArray());
static::assertEquals($expectedUrls, $actual->toArray());
}
}

Expand All @@ -129,7 +129,7 @@ public function testParseFeed(array $feedUrls, array $expectedValues, bool $thro
{
foreach ($feedUrls as $key => $feedUrl) {
if ($throwsConnectException) {
$this->expectException(ConnectException::class);
static::expectException(ConnectException::class);
}

$feed = $this->heraRssCrawler->parseFeed($feedUrl);
Expand All @@ -145,16 +145,16 @@ public function testParseFeed(array $feedUrls, array $expectedValues, bool $thro
'url' => $feed->getUrl(),
]);

$this->assertMatchesSnapshot($feedArr->toArray());
static::assertMatchesSnapshot($feedArr->toArray());

$this->assertNotEmpty($feed->getChecksum());
$this->assertGreaterThanOrEqual(0, $feed->getFeedItems()->count());
static::assertNotEmpty($feed->getChecksum());
static::assertGreaterThanOrEqual(0, $feed->getFeedItems()->count());

if ($feed->getFeedItems()->isNotEmpty()) {
$this->assertNotEmpty($feed->getFeedItems()->first()->getChecksum());
static::assertNotEmpty($feed->getFeedItems()->first()->getChecksum());
}
} else {
$this->assertNull($feed);
static::assertNull($feed);
}
}
}
Expand All @@ -170,7 +170,7 @@ public function testDiscoverAndParseFeeds(): void
$feeds = $this->heraRssCrawler->discoverAndParseFeeds('https://byorgey.wordpress.com/');
$actual = $feeds->map(fn(Feed $feed) => $feed->getTitle())->toArray();

$this->assertMatchesSnapshot($actual);
static::assertMatchesSnapshot($actual);
}

public function testDiscoverAndParseFeedsCheckFeedUrls(): void
Expand All @@ -185,7 +185,7 @@ public function testDiscoverAndParseFeedsCheckFeedUrls(): void
'url' => $feed->getUrl(),
])->toArray();

$this->assertMatchesSnapshot($actual);
static::assertMatchesSnapshot($actual);
}

/**
Expand All @@ -199,17 +199,17 @@ public function testGenerateChecksumForFeedItem(): void

$feedItem = self::getSampleFeedItem();

$this->assertEquals($expected, HeraRssCrawler::generateChecksumForFeedItem($feedItem));
static::assertEquals($expected, HeraRssCrawler::generateChecksumForFeedItem($feedItem));

$feedItem2 = clone $feedItem;
$feedItem2->setTitle('Title has changed');

$this->assertNotEquals($expected, HeraRssCrawler::generateChecksumForFeedItem($feedItem2));
static::assertNotEquals($expected, HeraRssCrawler::generateChecksumForFeedItem($feedItem2));

$expectedSha512 = 'a64b86da753fcc3d85fdcd5c9d2ef65530b20cf9c0eb9acfa972a53dbda2fbea94b733c1958a341535ef3a9785916f6297f41ab5ed0e497cfe6540451158fc04';

$this->assertEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeedItem($feedItem, '__', Hash::SHA_512));
$this->assertNotEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeedItem($feedItem, '--', Hash::SHA_512));
static::assertEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeedItem($feedItem, '__', Hash::SHA_512));
assertNotEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeedItem($feedItem, '--', Hash::SHA_512));

Check failure on line 212 in tests/HeraRssCrawlerTest.php

View workflow job for this annotation

GitHub Actions / phpstan

Function assertNotEquals not found.
}

/**
Expand All @@ -223,22 +223,22 @@ public function testGenerateChecksumForFeed(): void

$feed = self::getSampleFeed();

$this->assertEquals($expected, HeraRssCrawler::generateChecksumForFeed($feed));
static::assertEquals($expected, HeraRssCrawler::generateChecksumForFeed($feed));

$feed2 = clone $feed;
$feed2->setTitle('Title has changed');

$this->assertNotEquals($expected, HeraRssCrawler::generateChecksumForFeed($feed2));
static::assertNotEquals($expected, HeraRssCrawler::generateChecksumForFeed($feed2));

$expectedSha512 = '1d025eb44d8035465b5a573646e5f95379bcff8c49b6cfc704e12bee3ffef930a4c9129897bef1b9746d625e2a9894eb662160e4ecc6f088a9c96df2590d0205';

$feed3 = clone $feed;
$feed3->setFeedItems(new Collection([self::getSampleFeedItem(), self::getSampleFeedItem()]));

$this->assertNotEquals($expected, HeraRssCrawler::generateChecksumForFeed($feed3));
static::assertNotEquals($expected, HeraRssCrawler::generateChecksumForFeed($feed3));

$this->assertEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeed($feed, '__', Hash::SHA_512));
$this->assertNotEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeed($feed, '--', Hash::SHA_512));
static::assertEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeed($feed, '__', Hash::SHA_512));
static::assertNotEquals($expectedSha512, HeraRssCrawler::generateChecksumForFeed($feed, '--', Hash::SHA_512));
}

/**
Expand All @@ -254,13 +254,13 @@ public function testGenerateChecksumForFeed(): void
public function testDiscoverFavicon(string $url, array $expectedUrls, ?string $expectedFaviconUrl = null, bool $throwsConnectException = false): void
{
if ($throwsConnectException) {
$this->expectException(ConnectException::class);
static::expectException(ConnectException::class);
}

$faviconUrl = $this->heraRssCrawler->discoverFavicon($url);

if (!$throwsConnectException) {
$this->assertEquals($expectedFaviconUrl, $faviconUrl);
static::assertEquals($expectedFaviconUrl, $faviconUrl);
}
}

Expand All @@ -275,7 +275,7 @@ public function testCheckIfConsumableFeed(array $feedUrls, array $expectedValues
foreach ($feedUrls as $key => $feedUrl) {
$isConsumableFeed = $this->heraRssCrawler->checkIfConsumableFeed($feedUrl);

$this->assertEquals($expectedValues[$key], $isConsumableFeed);
static::assertEquals($expectedValues[$key], $isConsumableFeed);
}
}

Expand All @@ -285,13 +285,13 @@ public function testCheckIfConsumableFeed(array $feedUrls, array $expectedValues
public function testReplaceBaseUrl(): void
{
$newUrl = Helper::replaceBaseUrl('https://www.reddit.com/r/ns2/new/', 'https://www.reddit.com/', 'https://old.reddit.com/');
$this->assertEquals('https://old.reddit.com/r/ns2/new/', $newUrl);
static::assertEquals('https://old.reddit.com/r/ns2/new/', $newUrl);

$newUrl2 = Helper::replaceBaseUrl('https://site.dev/test?query=hello_world', 'https://site.dev', 'https://new.site.dev');
$this->assertEquals('https://new.site.dev/test?query=hello_world', $newUrl2);
static::assertEquals('https://new.site.dev/test?query=hello_world', $newUrl2);

$newUrl3 = Helper::replaceBaseUrl('https://www.google.com/?query=hello_world', 'https://site.dev', 'https://new.site.dev');
$this->assertEquals('https://www.google.com/?query=hello_world', $newUrl3);
static::assertEquals('https://www.google.com/?query=hello_world', $newUrl3);
}

/**
Expand All @@ -305,13 +305,13 @@ public function testReplaceBaseUrls(): void
];

$url = Helper::replaceBaseUrls('https://www.reddit.com/r/ns2/new/', $urlReplacementMap);
$this->assertEquals('https://old.reddit.com/r/ns2/new/', $url);
static::assertEquals('https://old.reddit.com/r/ns2/new/', $url);

$url2 = Helper::replaceBaseUrls('https://site.dev/test?query=hello_world', $urlReplacementMap);
$this->assertEquals('https://new.site.dev/test?query=hello_world', $url2);
static::assertEquals('https://new.site.dev/test?query=hello_world', $url2);

$url3 = Helper::replaceBaseUrls('https://www.google.com/?query=hello_world', $urlReplacementMap);
$this->assertEquals('https://www.google.com/?query=hello_world', $url3);
static::assertEquals('https://www.google.com/?query=hello_world', $url3);
}

/**
Expand All @@ -322,25 +322,25 @@ public function testDiscoverRedditFeedUrls(): void
$heraRssCrawler = new HeraRssCrawler();

$feed = $heraRssCrawler->parseFeed('https://www.reddit.com/r/ns2/new/.rss');
$this->assertInstanceOf(Feed::class, $feed);
static::assertInstanceOf(Feed::class, $feed);

$feedUrls = $heraRssCrawler->discoverFeedUrls('https://www.reddit.com/r/ns2/new/');
$this->assertEquals(['https://old.reddit.com/r/ns2/new/.rss'], $feedUrls->toArray());
static::assertEquals(['https://old.reddit.com/r/ns2/new/.rss'], $feedUrls->toArray());

$heraRssCrawler->setUrlReplacementMap([
'https://site.dev' => 'https://new.site.dev',
'https://www.reddit.com/' => 'https://old.reddit.com/',
]);

$feedUrls = $heraRssCrawler->discoverFeedUrls('https://www.reddit.com/r/ns2/new/');
$this->assertEquals(['https://old.reddit.com/r/ns2/new/.rss'], $feedUrls->toArray());
static::assertEquals(['https://old.reddit.com/r/ns2/new/.rss'], $feedUrls->toArray());

$heraRssCrawler->setUrlReplacementMap([
'https://site.dev' => 'https://new.site.dev',
]);

$feedUrls = $heraRssCrawler->discoverFeedUrls('https://www.reddit.com/r/ns2/new/');
$this->assertEmpty($feedUrls->toArray());
static::assertEmpty($feedUrls->toArray());
}

/**
Expand Down Expand Up @@ -397,7 +397,7 @@ public function discover(Client $httpClient, ResponseContainer $responseContaine

$heraRssCrawler = new HeraRssCrawler();

$this->expectException(InvalidArgumentException::class);
static::expectException(InvalidArgumentException::class);

$heraRssCrawler->setFeedDiscoverers($feedDiscoverers);
}
Expand Down

0 comments on commit c83c378

Please sign in to comment.