Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Nov 11, 2017
1 parent 7b1bc39 commit 356c44d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Extractor/ContentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public function process($html, $url, SiteConfig $siteConfig = null, $smartTidy =
// If there's more than one, it could indicate more than
// one author, but it could also indicate that we're processing
// a page listing different articles with different authors.
$detectAuthor = $this->extractEntityFromQuery(
$this->extractEntityFromQuery(
'authors',
$detectAuthor,
"//a[contains(concat(' ',normalize-space(@rel),' '),' author ')]",
Expand All @@ -449,7 +449,7 @@ function ($element, $currentEntity) {
// Find date in pubdate marked time element
// For the same reason given above, we only use this
// if there's exactly one element.
$detectDate = $this->extractEntityFromQuery(
$this->extractEntityFromQuery(
'date',
$detectDate,
'//time[@pubdate or @pubDate]',
Expand Down
4 changes: 2 additions & 2 deletions src/SiteConfig/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function addToCache($key, SiteConfig $config)
*
* @param string $key Key for the cache
*
* @return bool|SiteConfig
* @return false|SiteConfig
*/
public function getCachedVersion($key)
{
Expand Down Expand Up @@ -113,7 +113,7 @@ public function buildFromUrl($url, $addToCache = true)
// extract host name
$host = parse_url($url, PHP_URL_HOST);

return $this->buildForHost($host, $addToCache);
return $this->buildForHost((string) $host, $addToCache);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Extractor/ContentExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public function testLogMessage()

$config = new SiteConfig();

$res = $contentExtractor->process(
$contentExtractor->process(
'<html>&lt;iframe &gt;&lt;/iframe&gt;</html>',
'https://vimeo.com/35941909',
$config
Expand Down
8 changes: 2 additions & 6 deletions tests/Extractor/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,6 @@ public function testWith404ResponseWithoutResponse()
->disableOriginalConstructor()
->getMock();

$response = $this->getMockBuilder('GuzzleHttp\Message\Response')
->disableOriginalConstructor()
->getMock();

$client = $this->getMockBuilder('GuzzleHttp\Client')
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -787,7 +783,7 @@ public function testUserAgent($url, $httpHeader, $expectedUa)
]);
$http->setLogger($logger);

$res = $http->fetch($url, false, $httpHeader);
$http->fetch($url, false, $httpHeader);

$records = $handler->getRecords();

Expand Down Expand Up @@ -863,7 +859,7 @@ public function testReferer($url, $httpHeader, $expectedReferer)
]);
$http->setLogger($logger);

$res = $http->fetch($url, false, $httpHeader);
$http->fetch($url, false, $httpHeader);

$records = $handler->getRecords();

Expand Down
5 changes: 0 additions & 5 deletions tests/Ring/Client/SafeCurlHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ public function testReusesHandles()
$a($request);
$a($request);
}

protected function getHandler($factory = null, $options = [])
{
return new SafeCurlHandler($options);
}
}
15 changes: 14 additions & 1 deletion tests/SiteConfig/ConfigBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ConfigBuilderTest extends \PHPUnit_Framework_TestCase
{
public function testConstructDefault()
{
$configBuilder = new ConfigBuilder(['site_config' => [__DIR__]]);
new ConfigBuilder(['site_config' => [__DIR__]]);
}

public function testBuildFromArrayNoLines()
Expand Down Expand Up @@ -210,6 +210,8 @@ public function testLogMessage()

$res = $configBuilder->buildFromUrl('https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal');

$this->assertInstanceOf('Graby\SiteConfig\SiteConfig', $res);

$records = $handler->getRecords();

$this->assertGreaterThan(5, $records);
Expand All @@ -219,4 +221,15 @@ public function testLogMessage()
$this->assertSame('.wikipedia.org.txt', $records[1]['context']['host']);
$this->assertSame('Appending site config settings from global.txt', $records[2]['message']);
}

public function testWithBadHost()
{
$configBuilder = new ConfigBuilder([
'site_config' => [__DIR__ . '/../fixtures/site_config'],
]);

$res = $configBuilder->buildFromUrl('http://user@:80/test');

$this->assertInstanceOf('Graby\SiteConfig\SiteConfig', $res);
}
}

0 comments on commit 356c44d

Please sign in to comment.