Skip to content

Commit

Permalink
Merge pull request #19 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Jul 18, 2019
2 parents dfa4784 + d7357d9 commit e80aaa9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions src/Utility/LinkScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand All @@ -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) {
Expand Down
70 changes: 32 additions & 38 deletions tests/TestCase/Utility/LinkScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5
1.0.6

0 comments on commit e80aaa9

Please sign in to comment.