Refactor into namespaces for PSR-4

This commit is contained in:
Aidan Woods 2018-04-17 14:44:38 +01:00
parent bfaa76d370
commit 88ab68fd0b
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
138 changed files with 59 additions and 35 deletions

View File

@ -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;")" ]'

View File

@ -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/"
}
} }
} }

View File

@ -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>

View File

@ -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';
# ~ # ~

View File

@ -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

View File

@ -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

View File

@ -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">&lt;p&gt;foobar&lt;/p&gt;</code></pre>'; $expectedSafeMarkup = '<pre><code class="language-php">&lt;p&gt;foobar&lt;/p&gt;</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);

View File

@ -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)
{ {

View 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;
}
}

View File

@ -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