mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-19 19:41:29 +02:00
Refactor into namespaces for PSR-4
This commit is contained in:
parent
bfaa76d370
commit
88ab68fd0b
@ -25,4 +25,4 @@ install:
|
||||
script:
|
||||
- vendor/bin/phpunit
|
||||
- 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"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {"Parsedown": ""}
|
||||
"psr-4": {"Erusev\\Parsedown\\": "src/"}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-0": {
|
||||
"TestParsedown": "test/",
|
||||
"ParsedownTest": "test/",
|
||||
"CommonMarkTest": "test/",
|
||||
"CommonMarkTestWeak": "test/"
|
||||
}
|
||||
"psr-4": {"Erusev\\Parsedown\\Tests\\": "tests/"}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite>
|
||||
<file>test/ParsedownTest.php</file>
|
||||
<file>tests/ParsedownTest.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?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
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
/**
|
||||
* Test Parsedown against the CommonMark spec
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
require_once(__DIR__ . '/CommonMarkTestStrict.php');
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
/**
|
||||
* Test Parsedown against the CommonMark spec, but less aggressive
|
@ -1,7 +1,10 @@
|
||||
<?php
|
||||
require 'SampleExtensions.php';
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
|
||||
class ParsedownTest extends TestCase
|
||||
{
|
||||
@ -64,7 +67,7 @@ class ParsedownTest extends TestCase
|
||||
$expectedMarkup = '<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);
|
||||
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
@ -81,7 +84,7 @@ class ParsedownTest extends TestCase
|
||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||
$expectedSafeMarkup = $expectedMarkup;
|
||||
|
||||
$unsafeExtension = new TrustDelegatedExtension;
|
||||
$unsafeExtension = new SampleExtensions\TrustDelegatedExtension;
|
||||
$actualMarkup = $unsafeExtension->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
@ -98,7 +101,7 @@ class ParsedownTest extends TestCase
|
||||
|
||||
foreach ($this->dirs as $dir)
|
||||
{
|
||||
$Folder = new DirectoryIterator($dir);
|
||||
$Folder = new \DirectoryIterator($dir);
|
||||
|
||||
foreach ($Folder as $File)
|
||||
{
|
||||
@ -182,16 +185,16 @@ EXPECTED_HTML;
|
||||
public function testLateStaticBinding()
|
||||
{
|
||||
$parsedown = Parsedown::instance();
|
||||
$this->assertInstanceOf('Parsedown', $parsedown);
|
||||
$this->assertInstanceOf(Parsedown::class, $parsedown);
|
||||
|
||||
// After instance is already called on Parsedown
|
||||
// subsequent calls with the same arguments return the same instance
|
||||
$sameParsedown = TestParsedown::instance();
|
||||
$this->assertInstanceOf('Parsedown', $sameParsedown);
|
||||
$this->assertInstanceOf(Parsedown::class, $sameParsedown);
|
||||
$this->assertSame($parsedown, $sameParsedown);
|
||||
|
||||
$testParsedown = TestParsedown::instance('test late static binding');
|
||||
$this->assertInstanceOf('TestParsedown', $testParsedown);
|
||||
$this->assertInstanceOf(TestParsedown::class, $testParsedown);
|
||||
|
||||
$sameInstanceAgain = TestParsedown::instance('test late static binding');
|
||||
$this->assertSame($testParsedown, $sameInstanceAgain);
|
@ -1,25 +1,12 @@
|
||||
<?php
|
||||
|
||||
class UnsafeExtension extends Parsedown
|
||||
{
|
||||
protected function blockFencedCodeComplete($Block)
|
||||
{
|
||||
$text = $Block['element']['element']['text'];
|
||||
unset($Block['element']['element']['text']);
|
||||
declare(strict_types=1);
|
||||
|
||||
// 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>";
|
||||
namespace Erusev\Parsedown\Tests\SampleExtensions;
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
use Erusev\Parsedown\Tests\TestParsedown;
|
||||
|
||||
|
||||
class TrustDelegatedExtension extends Parsedown
|
||||
class TrustDelegatedExtension extends TestParsedown
|
||||
{
|
||||
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
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
|
||||
class TestParsedown extends Parsedown
|
||||
{
|
||||
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