mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-20 03:51:29 +02:00
Refactor into namespaces for PSR-4
This commit is contained in:
parent
bfaa76d370
commit
88ab68fd0b
@ -25,4 +25,4 @@ install:
|
|||||||
script:
|
script:
|
||||||
- vendor/bin/phpunit
|
- vendor/bin/phpunit
|
||||||
- vendor/bin/phpunit test/CommonMarkTestWeak.php || true
|
- vendor/bin/phpunit test/CommonMarkTestWeak.php || true
|
||||||
- '[ -z "$TRAVIS_TAG" ] || [ "$TRAVIS_TAG" == "$(php -r "require(\"Parsedown.php\"); echo Parsedown::version;")" ]'
|
- '[ -z "$TRAVIS_TAG" ] || [ "$TRAVIS_TAG" == "$(php -r "require(\"vendor/autoload.php\"); echo Erusev\Parsedown\Parsedown::version;")" ]'
|
||||||
|
@ -20,14 +20,9 @@
|
|||||||
"phpunit/phpunit": "^4.8.35"
|
"phpunit/phpunit": "^4.8.35"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {"Parsedown": ""}
|
"psr-4": {"Erusev\\Parsedown\\": "src/"}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-0": {
|
"psr-4": {"Erusev\\Parsedown\\Tests\\": "tests/"}
|
||||||
"TestParsedown": "test/",
|
|
||||||
"ParsedownTest": "test/",
|
|
||||||
"CommonMarkTest": "test/",
|
|
||||||
"CommonMarkTestWeak": "test/"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite>
|
<testsuite>
|
||||||
<file>test/ParsedownTest.php</file>
|
<file>tests/ParsedownTest.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown;
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
@ -17,7 +20,7 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
const version = '1.8.0-beta-7';
|
const version = '2.0.0-dev';
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown\Tests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Parsedown against the CommonMark spec
|
* Test Parsedown against the CommonMark spec
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once(__DIR__ . '/CommonMarkTestStrict.php');
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown\Tests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Parsedown against the CommonMark spec, but less aggressive
|
* Test Parsedown against the CommonMark spec, but less aggressive
|
@ -1,7 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
require 'SampleExtensions.php';
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Erusev\Parsedown\Parsedown;
|
||||||
|
|
||||||
class ParsedownTest extends TestCase
|
class ParsedownTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -64,7 +67,7 @@ class ParsedownTest extends TestCase
|
|||||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||||
$expectedSafeMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
$expectedSafeMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||||
|
|
||||||
$unsafeExtension = new UnsafeExtension;
|
$unsafeExtension = new SampleExtensions\UnsafeExtension;
|
||||||
$actualMarkup = $unsafeExtension->text($markdown);
|
$actualMarkup = $unsafeExtension->text($markdown);
|
||||||
|
|
||||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||||
@ -81,7 +84,7 @@ class ParsedownTest extends TestCase
|
|||||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||||
$expectedSafeMarkup = $expectedMarkup;
|
$expectedSafeMarkup = $expectedMarkup;
|
||||||
|
|
||||||
$unsafeExtension = new TrustDelegatedExtension;
|
$unsafeExtension = new SampleExtensions\TrustDelegatedExtension;
|
||||||
$actualMarkup = $unsafeExtension->text($markdown);
|
$actualMarkup = $unsafeExtension->text($markdown);
|
||||||
|
|
||||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||||
@ -98,7 +101,7 @@ class ParsedownTest extends TestCase
|
|||||||
|
|
||||||
foreach ($this->dirs as $dir)
|
foreach ($this->dirs as $dir)
|
||||||
{
|
{
|
||||||
$Folder = new DirectoryIterator($dir);
|
$Folder = new \DirectoryIterator($dir);
|
||||||
|
|
||||||
foreach ($Folder as $File)
|
foreach ($Folder as $File)
|
||||||
{
|
{
|
||||||
@ -182,16 +185,16 @@ EXPECTED_HTML;
|
|||||||
public function testLateStaticBinding()
|
public function testLateStaticBinding()
|
||||||
{
|
{
|
||||||
$parsedown = Parsedown::instance();
|
$parsedown = Parsedown::instance();
|
||||||
$this->assertInstanceOf('Parsedown', $parsedown);
|
$this->assertInstanceOf(Parsedown::class, $parsedown);
|
||||||
|
|
||||||
// After instance is already called on Parsedown
|
// After instance is already called on Parsedown
|
||||||
// subsequent calls with the same arguments return the same instance
|
// subsequent calls with the same arguments return the same instance
|
||||||
$sameParsedown = TestParsedown::instance();
|
$sameParsedown = TestParsedown::instance();
|
||||||
$this->assertInstanceOf('Parsedown', $sameParsedown);
|
$this->assertInstanceOf(Parsedown::class, $sameParsedown);
|
||||||
$this->assertSame($parsedown, $sameParsedown);
|
$this->assertSame($parsedown, $sameParsedown);
|
||||||
|
|
||||||
$testParsedown = TestParsedown::instance('test late static binding');
|
$testParsedown = TestParsedown::instance('test late static binding');
|
||||||
$this->assertInstanceOf('TestParsedown', $testParsedown);
|
$this->assertInstanceOf(TestParsedown::class, $testParsedown);
|
||||||
|
|
||||||
$sameInstanceAgain = TestParsedown::instance('test late static binding');
|
$sameInstanceAgain = TestParsedown::instance('test late static binding');
|
||||||
$this->assertSame($testParsedown, $sameInstanceAgain);
|
$this->assertSame($testParsedown, $sameInstanceAgain);
|
@ -1,25 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UnsafeExtension extends Parsedown
|
declare(strict_types=1);
|
||||||
{
|
|
||||||
protected function blockFencedCodeComplete($Block)
|
|
||||||
{
|
|
||||||
$text = $Block['element']['element']['text'];
|
|
||||||
unset($Block['element']['element']['text']);
|
|
||||||
|
|
||||||
// WARNING: There is almost always a better way of doing things!
|
namespace Erusev\Parsedown\Tests\SampleExtensions;
|
||||||
//
|
|
||||||
// This example is one of them, unsafe behaviour is NOT needed here.
|
|
||||||
// Only use this if you trust the input and have no idea what
|
|
||||||
// the output HTML will look like (e.g. using an external parser).
|
|
||||||
$Block['element']['element']['rawHtml'] = "<p>$text</p>";
|
|
||||||
|
|
||||||
return $Block;
|
use Erusev\Parsedown\Tests\TestParsedown;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
class TrustDelegatedExtension extends TestParsedown
|
||||||
class TrustDelegatedExtension extends Parsedown
|
|
||||||
{
|
{
|
||||||
protected function blockFencedCodeComplete($Block)
|
protected function blockFencedCodeComplete($Block)
|
||||||
{
|
{
|
25
tests/SampleExtensions/UnsafeExtension.php
Normal file
25
tests/SampleExtensions/UnsafeExtension.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown\Tests\SampleExtensions;
|
||||||
|
|
||||||
|
use Erusev\Parsedown\Tests\TestParsedown;
|
||||||
|
|
||||||
|
class UnsafeExtension extends TestParsedown
|
||||||
|
{
|
||||||
|
protected function blockFencedCodeComplete($Block)
|
||||||
|
{
|
||||||
|
$text = $Block['element']['element']['text'];
|
||||||
|
unset($Block['element']['element']['text']);
|
||||||
|
|
||||||
|
// WARNING: There is almost always a better way of doing things!
|
||||||
|
//
|
||||||
|
// This example is one of them, unsafe behaviour is NOT needed here.
|
||||||
|
// Only use this if you trust the input and have no idea what
|
||||||
|
// the output HTML will look like (e.g. using an external parser).
|
||||||
|
$Block['element']['element']['rawHtml'] = "<p>$text</p>";
|
||||||
|
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown\Tests;
|
||||||
|
|
||||||
|
use Erusev\Parsedown\Parsedown;
|
||||||
|
|
||||||
class TestParsedown extends Parsedown
|
class TestParsedown extends Parsedown
|
||||||
{
|
{
|
||||||
public function getTextLevelElements()
|
public function getTextLevelElements()
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user