Skip to content

Commit

Permalink
Merge 32ec32c into eb7d515
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanlaak committed Oct 24, 2019
2 parents eb7d515 + 32ec32c commit d7daa62
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
13 changes: 5 additions & 8 deletions src/Micrometa/Tests/AbstractTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,18 @@ abstract class AbstractTestBase extends TestCase
*
* @var string
*/
protected static $fixture;
protected static $fixture = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR;

/**
* Logger
*
* @var LoggerInterface
*/
protected static $logger;
private static $logger;

/**
* Setup
*/
public static function setUpBeforeClass()
protected static function getLogger() : LoggerInterface
{
self::$fixture = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR;
self::$logger = new ExceptionLogger();
return self::$logger ?? self::$logger = new ExceptionLogger();
}

/**
Expand Down
24 changes: 5 additions & 19 deletions src/Micrometa/Tests/Application/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,6 @@
*/
class ExtractorTest extends AbstractTestBase
{
/**
* Microformats tests root path
*
* @var string
*/
protected static $microformatsTests;

/**
* Setup before all tests
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$microformatsTests = \ComposerLocator::getPath('mf2/tests').DIRECTORY_SEPARATOR.'tests'.
DIRECTORY_SEPARATOR.'microformats-v2'.DIRECTORY_SEPARATOR;
}

/**
* Test the RDFa Lite 1.1 extraction
*/
Expand All @@ -82,7 +65,7 @@ public function testRdfaLiteExtraction()
$this->assertInstanceOf(\DOMDocument::class, $rdfaLiteDom);

// Create an RDFa Lite 1.1 parser
$rdfaLiteParser = new RdfaLite($rdfaLiteUri, self::$logger);
$rdfaLiteParser = new RdfaLite($rdfaLiteUri, self::getLogger());
$this->assertEquals($rdfaLiteUri, $rdfaLiteParser->getUri());

// Create an extractor service
Expand Down Expand Up @@ -121,8 +104,11 @@ public function testMicrodataExtraction()
*/
public function testMicroformatsExtraction()
{
$microformatsTests = \ComposerLocator::getPath('mf2/tests').DIRECTORY_SEPARATOR.'tests'.
DIRECTORY_SEPARATOR.'microformats-v2'.DIRECTORY_SEPARATOR;

$this->getAndTestMicroformatsExtractionBase(
self::$microformatsTests.'h-product'.DIRECTORY_SEPARATOR.'aggregate.html'
$microformatsTests.'h-product'.DIRECTORY_SEPARATOR.'aggregate.html'
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Micrometa/Tests/Infrastructure/ParserFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testParserFactory()
{
$formats = Microformats::FORMAT | Microdata::FORMAT | JsonLD::FORMAT | RdfaLite::FORMAT | LinkType::FORMAT;
$uri = 'http://localhost/example.html';
$parsers = ParserFactory::createParsersFromFormats($formats, Http::createFromString($uri), self::$logger);
$parsers = ParserFactory::createParsersFromFormats($formats, Http::createFromString($uri), self::getLogger());

/**
* @var int $parserFormat
Expand Down
39 changes: 23 additions & 16 deletions src/Micrometa/Tests/Infrastructure/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ParserTest extends AbstractTestBase
public function testLanguageJsonLDParser()
{
list($uri, $dom) = $this->getUriFixture('json-ld/jsonld-languages.html');
$parser = new JsonLD($uri, self::$logger);
$parser = new JsonLD($uri, self::getLogger());
$items = $parser->parseDom($dom)->getItems();
$this->assertTrue(is_array($items));
$this->assertEquals(1, count($items));
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testInvalidJsonLDParser()
public function testMicroformatsParser()
{
list($uri, $dom) = $this->getUriFixture('microformats/entry.html');
$parser = new Microformats($uri, self::$logger);
$parser = new Microformats($uri, self::getLogger());
$items = $parser->parseDom($dom)->getItems();
$this->assertTrue(is_array($items));
$this->assertEquals(1, count($items));
Expand All @@ -126,7 +126,7 @@ public function testMicroformatsParser()
public function testNestedMicroformatsParser()
{
list($uri, $dom) = $this->getUriFixture('microformats/nested-events.html');
$parser = new Microformats($uri, self::$logger);
$parser = new Microformats($uri, self::getLogger());
$items = $parser->parseDom($dom)->getItems();
$this->assertTrue(is_array($items));
$this->assertEquals(1, count($items));
Expand All @@ -141,13 +141,12 @@ public function testNestedMicroformatsParser()
public function testMicrodataParser()
{
list($uri, $dom) = $this->getUriFixture('html-microdata/article-microdata.html');
$parser = new Microdata($uri, self::$logger);
$parser = new Microdata($uri, self::getLogger());
$items = $parser->parseDom($dom)->getItems();
$this->assertTrue(is_array($items));
$this->assertEquals(1, count($items));
$this->assertInstanceOf(Item::class, $items[0]);
$this->assertEquals(Microdata::FORMAT, $items[0]->getFormat());
$this->assertEquals([new Iri('http://schema.org/', 'NewsArticle')], $items[0]->getType());

$expectedItemFormat = Microdata::FORMAT;
$expectedItemIri = new Iri('http://schema.org/', 'NewsArticle');
$this->assertItemParsedAs($items, $expectedItemFormat, $expectedItemIri);
}

/**
Expand All @@ -156,13 +155,12 @@ public function testMicrodataParser()
public function testRdfaLiteParser()
{
list($uri, $dom) = $this->getUriFixture('rdfa-lite/article-rdfa-lite.html');
$parser = new RdfaLite($uri, self::$logger);
$parser = new RdfaLite($uri, self::getLogger());
$items = $parser->parseDom($dom)->getItems();
$this->assertTrue(is_array($items));
$this->assertEquals(1, count($items));
$this->assertInstanceOf(Item::class, $items[0]);
$this->assertEquals(RdfaLite::FORMAT, $items[0]->getFormat());
$this->assertEquals([new Iri('http://schema.org/', 'NewsArticle')], $items[0]->getType());

$expectedItemFormat = RdfaLite::FORMAT;
$expectedItemIri = new Iri('http://schema.org/', 'NewsArticle');
$this->assertItemParsedAs($items, $expectedItemFormat, $expectedItemIri);
}

/**
Expand All @@ -171,12 +169,21 @@ public function testRdfaLiteParser()
public function testLinkTypeParser()
{
list($uri, $dom) = $this->getUriFixture('link-type/valid-test.html');
$parser = new LinkType($uri, self::$logger);
$parser = new LinkType($uri, self::getLogger());
$items = $parser->parseDom($dom)->getItems();
$this->assertTrue(is_array($items));
$this->assertEquals(4, count($items));
$this->assertInstanceOf(Item::class, $items[0]);
$this->assertEquals(LinkType::FORMAT, $items[0]->getFormat());
$this->assertEquals([new Iri(LinkType::HTML_PROFILE_URI, 'icon')], $items[0]->getType());
}

private function assertItemParsedAs(array $items, int $expectedItemFormat, Iri $expectedItemIri)
{
$this->assertIsArray($items);
$this->assertCount(1, $items);
$this->assertInstanceOf(Item::class, $items[0]);
$this->assertEquals($expectedItemFormat, $items[0]->getFormat());
$this->assertEquals([$expectedItemIri], $items[0]->getType());
}
}

0 comments on commit d7daa62

Please sign in to comment.