diff --git a/CHANGELOG.md b/CHANGELOG.md index bcae63b..bd56163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 1.x branch ## 1.0 branch +### 1.0.6 +* `LinkScanner::import()` can no longer be called statically; +* little fixes; +* updated for `php-tools` `1.2.6`. + ### 1.0.5 * now it correctly handles the url with the trailing slash or the `www` prefix. diff --git a/appveyor.yml b/appveyor.yml index 1f0f853..ef9127d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,7 +11,7 @@ init: install: - cd c:\ - - curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-7.2.19-nts-Win32-VC15-x86.zip + - curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-7.2.20-nts-Win32-VC15-x86.zip - 7z x php.zip -oc:\php > nul - cd c:\php - copy php.ini-production php.ini diff --git a/composer.json b/composer.json index a3da5da..738354d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "php": ">=5.5.9", "cakephp/cakephp": "^3.7.1", "mirko-pagliai/me-tools": "^2.18", - "mirko-pagliai/php-tools": "^1.2.3" + "mirko-pagliai/php-tools": "^1.2.6" }, "require-dev": { "cakephp/cakephp-codesniffer": "^3.0", diff --git a/src/Utility/LinkScanner.php b/src/Utility/LinkScanner.php index 4caf1d6..62fc2c1 100644 --- a/src/Utility/LinkScanner.php +++ b/src/Utility/LinkScanner.php @@ -24,7 +24,6 @@ use Cake\Http\Client\Response; use Exception; use InvalidArgumentException; -use LinkScanner\Http\Client\ScanResponse; use LinkScanner\ResultScan; use LinkScanner\ScanEntity; use RuntimeException; @@ -386,7 +385,7 @@ public function export($filename = null) $filename = $filename ?: sprintf('results_%s_%s', $this->hostname, $this->startTime); if (!Folder::isAbsolute($filename)) { - $filename = Folder::slashTerm($this->getConfig('target')) . $filename; + $filename = add_slash_term($this->getConfig('target')) . $filename; } (new File($filename, true))->write(serialize($this)); $this->dispatchEvent('LinkScanner.resultsExported', [$filename]); @@ -404,14 +403,13 @@ public function export($filename = null) * been exported. * @param string $filename Filename from which to import * @return \LinkScanner\Utility\LinkScanner - * @see unserialize() * @throws \RuntimeException */ - public static function import($filename) + public function import($filename) { try { if (!Folder::isAbsolute($filename)) { - $filename = Folder::slashTerm(self::getConfig('target')) . $filename; + $filename = add_slash_term($this->getConfig('target')) . $filename; } $instance = unserialize(file_get_contents($filename)); } catch (Exception $e) { diff --git a/tests/TestCase/Utility/LinkScannerTest.php b/tests/TestCase/Utility/LinkScannerTest.php index 16c3cfa..439e468 100644 --- a/tests/TestCase/Utility/LinkScannerTest.php +++ b/tests/TestCase/Utility/LinkScannerTest.php @@ -197,49 +197,43 @@ public function testImport() { $this->LinkScanner->Client->setConfig('timeout', 100); $this->LinkScanner->setConfig('externalLinks', false)->setConfig('maxDepth', 1)->scan(); - $filename = $this->LinkScanner->export(); - - $resultAsObject = (new LinkScanner())->import($filename); - $resultAsStatic = LinkScanner::import($filename); - - foreach ([$resultAsObject, $resultAsStatic] as $result) { - $this->assertInstanceof(LinkScanner::class, $result); - - $this->assertEquals([ - 'cache' => true, - 'excludeLinks' => '/[\{\}+]/', - 'externalLinks' => false, - 'followRedirects' => false, - 'fullBaseUrl' => $this->fullBaseUrl, - 'maxDepth' => 1, - 'lockFile' => true, - 'target' => TMP . 'cakephp-link-scanner', - ], $result->getConfig()); - $this->assertEquals(100, $result->Client->getConfig('timeout')); - - //Checks the event is fired only on the new object. Then, it flushes - // both event lists, so that the objects comparison will run - $this->assertEventNotFired('LinkScanner.resultsImported', $this->EventManager); - $this->assertEventFired('LinkScanner.resultsImported', $this->getEventManager($result)); - $this->EventManager->getEventList()->flush(); - $this->getEventManager($result)->getEventList()->flush(); - - //Gets properties from both client, fixes properties of the `Client` - // instances and performs the comparison - $expectedClientProperties = $this->getProperties($this->LinkScanner->Client); - $resultClientProperties = $this->getProperties($result->Client); - foreach (['_adapter', '__phpunit_invocationMocker', '__phpunit_originalObject', '__phpunit_configurable'] as $key) { - unset($expectedClientProperties[$key], $resultClientProperties[$key]); - } - $expectedProperties = ['Client' => $expectedClientProperties] + $this->getProperties($this->LinkScanner); - $resultProperties = ['Client' => $resultClientProperties] + $this->getProperties($result); - $this->assertEquals($expectedProperties, $resultProperties); + $filename = basename($this->LinkScanner->export()); + $result = (new LinkScanner())->import($filename); + $this->assertInstanceof(LinkScanner::class, $result); + $this->assertEquals([ + 'cache' => true, + 'excludeLinks' => '/[\{\}+]/', + 'externalLinks' => false, + 'followRedirects' => false, + 'fullBaseUrl' => $this->fullBaseUrl, + 'maxDepth' => 1, + 'lockFile' => true, + 'target' => TMP . 'cakephp-link-scanner', + ], $result->getConfig()); + $this->assertEquals(100, $result->Client->getConfig('timeout')); + + //Checks the event is fired only on the new object. Then, it flushes + // both event lists, so that the objects comparison will run + $this->assertEventNotFired('LinkScanner.resultsImported', $this->EventManager); + $this->assertEventFired('LinkScanner.resultsImported', $this->getEventManager($result)); + $this->EventManager->getEventList()->flush(); + $this->getEventManager($result)->getEventList()->flush(); + + //Gets properties from both client, fixes properties of the `Client` + // instances and performs the comparison + $expectedClientProperties = $this->getProperties($this->LinkScanner->Client); + $resultClientProperties = $this->getProperties($result->Client); + foreach (['_adapter', '__phpunit_invocationMocker', '__phpunit_originalObject', '__phpunit_configurable'] as $key) { + unset($expectedClientProperties[$key], $resultClientProperties[$key]); } + $expectedProperties = ['Client' => $expectedClientProperties] + $this->getProperties($this->LinkScanner); + $resultProperties = ['Client' => $resultClientProperties] + $this->getProperties($result); + $this->assertEquals($expectedProperties, $resultProperties); //With a no existing file $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Failed to import results from file `' . TMP . 'noExistingDir' . DS . 'result` with message `failed to open stream: No such file or directory`'); - LinkScanner::import(TMP . 'noExistingDir' . DS . 'result'); + $this->LinkScanner->import(TMP . 'noExistingDir' . DS . 'result'); } /** diff --git a/version b/version index 90a27f9..af0b7dd 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.0.5 +1.0.6