Initial commit with PSR-4 autoloading and phpunit

This commit is contained in:
Annika Backstrom 2022-05-21 16:47:50 +01:00
commit 1a2a5c01a7
7 changed files with 2811 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
vendor
.phpunit.result.cache

18
composer.json Normal file
View File

@ -0,0 +1,18 @@
{
"autoload":{
"psr-4": {
"LogseqGem\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"LogseqGem\\Tests\\": "tests"
}
},
"require": {
"league/commonmark": "^2.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}

2728
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
phpunit.xml Normal file
View File

@ -0,0 +1,7 @@
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="parser">
<file>tests/ParserTest.php</file>
</testsuite>
</testsuites>
</phpunit>

15
run.php Normal file
View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
$parser = new LogseqGem\Parser;
$page = file_get_contents("/Users/annika/sync/BTSync/logseq/pages/Gemlog.md");
$page = file_get_contents("/Users/annika/sync/BTSync/logseq/pages/Publishing to the Gemlog with logseq.md");
$document = $parser->parse($page);
foreach ($document->iterator() as $node) {
echo 'Current node: ' . get_class($node) . "\n";
}

23
src/Parser.php Normal file
View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace LogseqGem;
use League\CommonMark\Parser\MarkdownParser;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
abstract class Parser {
private MarkdownParser $parser;
public function __construct() {
$environment = new Environment();
$environment->addExtension(new CommonMarkCoreExtension());
$this->parser = new MarkdownParser($environment);
}
public function parse(string $input) {
return $this->parser->parse($input);
}
}

18
tests/ParserTest.php Normal file
View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace LogseqGem\Tests;
use PHPUnit\Framework\TestCase;
use LogseqGem\Parser;
use League\CommonMark\Node\Block\Document;
class ParserTest extends TestCase {
public function testParse() {
$parser = $this->getMockForAbstractClass(Parser::class);
$document = $parser->parse('**foo**');
$this->assertInstanceOf(Document::class, $document);
}
}