Skip to content

Commit

Permalink
Debug bugfix + tests
Browse files Browse the repository at this point in the history
- Added some type casting
  • Loading branch information
JanPetterMG committed Aug 2, 2016
1 parent 793ac33 commit f45e908
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Client/Cache/MySQL/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function debug($base)
);
$query->bindParam(':base', $base, PDO::PARAM_STR);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
return $query->rowCount() > 0 ? $query->fetch(PDO::FETCH_ASSOC) : [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Delay/MySQL/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public function debug($base)
);
$query->bindParam(':base', $base, PDO::PARAM_STR);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
return $query->rowCount() > 0 ? $query->fetch(PDO::FETCH_ASSOC) : [];
}
}
2 changes: 1 addition & 1 deletion src/Parser/Directives/RequestRateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function client($userAgent = self::USER_AGENT, $fallbackValue = 0)
*/
private function sort()
{
usort($this->requestRates, function ($requestRateA, $requestRateB) {
usort($this->requestRates, function (array $requestRateA, array $requestRateB) {
// PHP 7: Switch to the <=> "Spaceship" operator
return $requestRateB['rate'] > $requestRateA['rate'];
});
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Directives/VisitTimeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function render(RenderHandler $handler)
*/
private function sort()
{
usort($this->visitTimes, function ($visitTimeA, $visitTimeB) {
usort($this->visitTimes, function (array $visitTimeA, array $visitTimeB) {
// PHP 7: Switch to the <=> "Spaceship" operator
return $visitTimeA['from'] > $visitTimeB['from'];
});
Expand Down
2 changes: 2 additions & 0 deletions tests/CacheSQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function testCacheSQL($uri, $base)
$parser->client($uri);
}

$this->assertTrue(count($parser->debug($uri), COUNT_NORMAL) >= 5);

$parser->cron();
$parser->clean();

Expand Down
1 change: 1 addition & 0 deletions tests/DelaySQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testDelaySQL($uri, $userAgent)
$queue = $client->getQueue();
$this->assertLessThanOrEqual(60, $queue);
$this->assertGreaterThan(59, $queue);
$this->assertTrue(count($delayHandler->debug($uri), COUNT_NORMAL) >= 3);
}

$client->reset();
Expand Down
9 changes: 9 additions & 0 deletions tests/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,13 @@ public function generateDataForTest()
]
];
}

public function testRenderInvalidNewLine()
{
$parser = new RobotsTxtParser\TxtClient('http://example.com', 200, '');
$this->assertInstanceOf('vipnytt\RobotsTxtParser\TxtClient', $parser);

$this->expectException(RobotsTxtParser\Exceptions\ClientException::class);
$parser->render()->normal('<br>');
}
}

0 comments on commit f45e908

Please sign in to comment.