Skip to content

Commit 28d2feb

Browse files
committed
fixed var name, added missing test and example
1 parent 308765d commit 28d2feb

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

examples/analyze_string.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* HTML string analyze example
4+
*
5+
* Executes file seo analyze on local html file.
6+
*/
7+
8+
require_once(__DIR__ . '/../vendor/autoload.php');
9+
10+
use SeoAnalyzer\Analyzer;
11+
12+
try {
13+
$htmlString = file_get_contents(__DIR__ . '/data/example.html');
14+
$results = (new Analyzer())->analyzeHtml($htmlString);
15+
} catch (ReflectionException $e) {
16+
echo "Error loading metric file: " . $e->getMessage();
17+
}
18+
19+
print_r($results);

src/Analyzer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public function analyzeFile(string $filename, string $locale = null): array
9494
/**
9595
* Analyzes html document from string.
9696
*
97-
* @param string $htmlstring
97+
* @param string $htmlString
9898
* @param string|null $locale
9999
* @return array
100100
* @throws ReflectionException
101101
*/
102-
public function analyzeHtml(string $htmlstring, string $locale = null): array
102+
public function analyzeHtml(string $htmlString, string $locale = null): array
103103
{
104104
$this->page = new Page(null, $locale, $this->client);
105-
$this->page->content = $htmlstring;
105+
$this->page->content = $htmlString;
106106
return $this->analyze();
107107
}
108108

tests/TestCase/AnalyzerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ public function testAnalyzeFilePass()
9090
$this->assertArrayHasKey('negative_impact', current($results));
9191
}
9292

93+
/**
94+
* @throws ReflectionException
95+
*/
96+
public function testAnalyzeHtmlPass()
97+
{
98+
$clientMock = $this->getClientMock();
99+
$analyzer = new Analyzer(null, $clientMock);
100+
$htmlString = file_get_contents(dirname(__DIR__) . '/data/test.html');
101+
$results = $analyzer->analyzeHtml($htmlString);
102+
$this->assertTrue(is_array($results));
103+
$this->assertEquals(count($analyzer->getMetrics()), count($results));
104+
$this->assertArrayHasKey('analysis', current($results));
105+
$this->assertArrayHasKey('name', current($results));
106+
$this->assertArrayHasKey('description', current($results));
107+
$this->assertArrayHasKey('value', current($results));
108+
$this->assertArrayHasKey('negative_impact', current($results));
109+
}
110+
93111
/**
94112
* @throws HttpException
95113
* @throws ReflectionException

0 commit comments

Comments
 (0)