diff --git a/src/Client/Cache/MySQL/Manager.php b/src/Client/Cache/MySQL/Manager.php index c6e7bd7..5edba77 100644 --- a/src/Client/Cache/MySQL/Manager.php +++ b/src/Client/Cache/MySQL/Manager.php @@ -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) : []; } /** diff --git a/src/Client/Delay/MySQL/Manager.php b/src/Client/Delay/MySQL/Manager.php index 8e982b5..4705cf8 100644 --- a/src/Client/Delay/MySQL/Manager.php +++ b/src/Client/Delay/MySQL/Manager.php @@ -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) : []; } } diff --git a/src/Parser/Directives/RequestRateParser.php b/src/Parser/Directives/RequestRateParser.php index 214d3cf..87d2d6b 100644 --- a/src/Parser/Directives/RequestRateParser.php +++ b/src/Parser/Directives/RequestRateParser.php @@ -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']; }); diff --git a/src/Parser/Directives/VisitTimeParser.php b/src/Parser/Directives/VisitTimeParser.php index b594df4..98d346f 100644 --- a/src/Parser/Directives/VisitTimeParser.php +++ b/src/Parser/Directives/VisitTimeParser.php @@ -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']; }); diff --git a/tests/CacheSQLTest.php b/tests/CacheSQLTest.php index 3bd369d..c0eaf6c 100644 --- a/tests/CacheSQLTest.php +++ b/tests/CacheSQLTest.php @@ -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(); diff --git a/tests/DelaySQLTest.php b/tests/DelaySQLTest.php index 2b13672..93d5a7e 100644 --- a/tests/DelaySQLTest.php +++ b/tests/DelaySQLTest.php @@ -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(); diff --git a/tests/ExportTest.php b/tests/ExportTest.php index c8fe983..4bae427 100644 --- a/tests/ExportTest.php +++ b/tests/ExportTest.php @@ -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('
'); + } }