From 88ab68fd0b08a38da56a3e2c7313f845d413ae6b Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 17 Apr 2018 14:44:38 +0100 Subject: [PATCH] Refactor into namespaces for PSR-4 --- .travis.yml | 2 +- composer.json | 9 ++----- phpunit.xml.dist | 2 +- Parsedown.php => src/Parsedown.php | 5 +++- {test => tests}/CommonMarkTestStrict.php | 3 +++ {test => tests}/CommonMarkTestWeak.php | 4 ++- {test => tests}/ParsedownTest.php | 17 +++++++------ .../TrustDelegatedExtension.php | 21 +++------------- tests/SampleExtensions/UnsafeExtension.php | 25 +++++++++++++++++++ {test => tests}/TestParsedown.php | 6 +++++ {test => tests}/data/aesthetic_table.html | 0 {test => tests}/data/aesthetic_table.md | 0 {test => tests}/data/aligned_table.html | 0 {test => tests}/data/aligned_table.md | 0 {test => tests}/data/atx_heading.html | 0 {test => tests}/data/atx_heading.md | 0 {test => tests}/data/automatic_link.html | 0 {test => tests}/data/automatic_link.md | 0 {test => tests}/data/block-level_html.html | 0 {test => tests}/data/block-level_html.md | 0 {test => tests}/data/code_block.html | 0 {test => tests}/data/code_block.md | 0 {test => tests}/data/code_span.html | 0 {test => tests}/data/code_span.md | 0 {test => tests}/data/compound_blockquote.html | 0 {test => tests}/data/compound_blockquote.md | 0 {test => tests}/data/compound_emphasis.html | 0 {test => tests}/data/compound_emphasis.md | 0 {test => tests}/data/compound_list.html | 0 {test => tests}/data/compound_list.md | 0 {test => tests}/data/deeply_nested_list.html | 0 {test => tests}/data/deeply_nested_list.md | 0 {test => tests}/data/em_strong.html | 0 {test => tests}/data/em_strong.md | 0 {test => tests}/data/email.html | 0 {test => tests}/data/email.md | 0 {test => tests}/data/emphasis.html | 0 {test => tests}/data/emphasis.md | 0 {test => tests}/data/escaping.html | 0 {test => tests}/data/escaping.md | 0 {test => tests}/data/fenced_code_block.html | 0 {test => tests}/data/fenced_code_block.md | 0 {test => tests}/data/horizontal_rule.html | 0 {test => tests}/data/horizontal_rule.md | 0 {test => tests}/data/html_comment.html | 0 {test => tests}/data/html_comment.md | 0 {test => tests}/data/html_entity.html | 0 {test => tests}/data/html_entity.md | 0 {test => tests}/data/image_reference.html | 0 {test => tests}/data/image_reference.md | 0 {test => tests}/data/image_title.html | 0 {test => tests}/data/image_title.md | 0 {test => tests}/data/implicit_reference.html | 0 {test => tests}/data/implicit_reference.md | 0 {test => tests}/data/inline_link.html | 0 {test => tests}/data/inline_link.md | 0 {test => tests}/data/inline_link_title.html | 0 {test => tests}/data/inline_link_title.md | 0 {test => tests}/data/inline_title.html | 0 {test => tests}/data/inline_title.md | 0 {test => tests}/data/lazy_blockquote.html | 0 {test => tests}/data/lazy_blockquote.md | 0 {test => tests}/data/lazy_list.html | 0 {test => tests}/data/lazy_list.md | 0 {test => tests}/data/line_break.html | 0 {test => tests}/data/line_break.md | 0 .../data/markup_consecutive_one.html | 0 .../data/markup_consecutive_one.md | 0 .../data/markup_consecutive_one_line.html | 0 .../data/markup_consecutive_one_line.md | 0 .../data/markup_consecutive_one_stripped.html | 0 .../data/markup_consecutive_one_stripped.md | 0 .../data/markup_consecutive_two.html | 0 .../data/markup_consecutive_two.md | 0 .../data/markup_consecutive_two_lines.html | 0 .../data/markup_consecutive_two_lines.md | 0 .../data/markup_consecutive_two_stripped.html | 0 .../data/markup_consecutive_two_stripped.md | 0 .../data/multiline_list_paragraph.html | 0 .../data/multiline_list_paragraph.md | 0 {test => tests}/data/multiline_lists.html | 0 {test => tests}/data/multiline_lists.md | 0 .../data/nested_block-level_html.html | 0 .../data/nested_block-level_html.md | 0 {test => tests}/data/ordered_list.html | 0 {test => tests}/data/ordered_list.md | 0 {test => tests}/data/paragraph_list.html | 0 {test => tests}/data/paragraph_list.md | 0 {test => tests}/data/reference_title.html | 0 {test => tests}/data/reference_title.md | 0 {test => tests}/data/self-closing_html.html | 0 {test => tests}/data/self-closing_html.md | 0 .../data/separated_nested_list.html | 0 {test => tests}/data/separated_nested_list.md | 0 {test => tests}/data/setext_header.html | 0 {test => tests}/data/setext_header.md | 0 .../data/setext_header_spaces.html | 0 {test => tests}/data/setext_header_spaces.md | 0 {test => tests}/data/simple_blockquote.html | 0 {test => tests}/data/simple_blockquote.md | 0 {test => tests}/data/simple_table.html | 0 {test => tests}/data/simple_table.md | 0 {test => tests}/data/span-level_html.html | 0 {test => tests}/data/span-level_html.md | 0 {test => tests}/data/sparse_dense_list.html | 0 {test => tests}/data/sparse_dense_list.md | 0 {test => tests}/data/sparse_html.html | 0 {test => tests}/data/sparse_html.md | 0 {test => tests}/data/sparse_list.html | 0 {test => tests}/data/sparse_list.md | 0 {test => tests}/data/special_characters.html | 0 {test => tests}/data/special_characters.md | 0 {test => tests}/data/strict_atx_heading.html | 0 {test => tests}/data/strict_atx_heading.md | 0 {test => tests}/data/strikethrough.html | 0 {test => tests}/data/strikethrough.md | 0 {test => tests}/data/strong_em.html | 0 {test => tests}/data/strong_em.md | 0 .../data/tab-indented_code_block.html | 0 .../data/tab-indented_code_block.md | 0 .../data/table_inline_markdown.html | 0 {test => tests}/data/table_inline_markdown.md | 0 {test => tests}/data/text_reference.html | 0 {test => tests}/data/text_reference.md | 0 {test => tests}/data/unordered_list.html | 0 {test => tests}/data/unordered_list.md | 0 {test => tests}/data/untidy_table.html | 0 {test => tests}/data/untidy_table.md | 0 {test => tests}/data/url_autolinking.html | 0 {test => tests}/data/url_autolinking.md | 0 {test => tests}/data/whitespace.html | 0 {test => tests}/data/whitespace.md | 0 .../data/xss_attribute_encoding.html | 0 .../data/xss_attribute_encoding.md | 0 {test => tests}/data/xss_bad_url.html | 0 {test => tests}/data/xss_bad_url.md | 0 {test => tests}/data/xss_text_encoding.html | 0 {test => tests}/data/xss_text_encoding.md | 0 138 files changed, 59 insertions(+), 35 deletions(-) rename Parsedown.php => src/Parsedown.php (99%) rename {test => tests}/CommonMarkTestStrict.php (97%) rename {test => tests}/CommonMarkTestWeak.php (97%) rename {test => tests}/ParsedownTest.php (90%) rename test/SampleExtensions.php => tests/SampleExtensions/TrustDelegatedExtension.php (50%) create mode 100644 tests/SampleExtensions/UnsafeExtension.php rename {test => tests}/TestParsedown.php (60%) rename {test => tests}/data/aesthetic_table.html (100%) rename {test => tests}/data/aesthetic_table.md (100%) rename {test => tests}/data/aligned_table.html (100%) rename {test => tests}/data/aligned_table.md (100%) rename {test => tests}/data/atx_heading.html (100%) rename {test => tests}/data/atx_heading.md (100%) rename {test => tests}/data/automatic_link.html (100%) rename {test => tests}/data/automatic_link.md (100%) rename {test => tests}/data/block-level_html.html (100%) rename {test => tests}/data/block-level_html.md (100%) rename {test => tests}/data/code_block.html (100%) rename {test => tests}/data/code_block.md (100%) rename {test => tests}/data/code_span.html (100%) rename {test => tests}/data/code_span.md (100%) rename {test => tests}/data/compound_blockquote.html (100%) rename {test => tests}/data/compound_blockquote.md (100%) rename {test => tests}/data/compound_emphasis.html (100%) rename {test => tests}/data/compound_emphasis.md (100%) rename {test => tests}/data/compound_list.html (100%) rename {test => tests}/data/compound_list.md (100%) rename {test => tests}/data/deeply_nested_list.html (100%) rename {test => tests}/data/deeply_nested_list.md (100%) rename {test => tests}/data/em_strong.html (100%) rename {test => tests}/data/em_strong.md (100%) rename {test => tests}/data/email.html (100%) rename {test => tests}/data/email.md (100%) rename {test => tests}/data/emphasis.html (100%) rename {test => tests}/data/emphasis.md (100%) rename {test => tests}/data/escaping.html (100%) rename {test => tests}/data/escaping.md (100%) rename {test => tests}/data/fenced_code_block.html (100%) rename {test => tests}/data/fenced_code_block.md (100%) rename {test => tests}/data/horizontal_rule.html (100%) rename {test => tests}/data/horizontal_rule.md (100%) rename {test => tests}/data/html_comment.html (100%) rename {test => tests}/data/html_comment.md (100%) rename {test => tests}/data/html_entity.html (100%) rename {test => tests}/data/html_entity.md (100%) rename {test => tests}/data/image_reference.html (100%) rename {test => tests}/data/image_reference.md (100%) rename {test => tests}/data/image_title.html (100%) rename {test => tests}/data/image_title.md (100%) rename {test => tests}/data/implicit_reference.html (100%) rename {test => tests}/data/implicit_reference.md (100%) rename {test => tests}/data/inline_link.html (100%) rename {test => tests}/data/inline_link.md (100%) rename {test => tests}/data/inline_link_title.html (100%) rename {test => tests}/data/inline_link_title.md (100%) rename {test => tests}/data/inline_title.html (100%) rename {test => tests}/data/inline_title.md (100%) rename {test => tests}/data/lazy_blockquote.html (100%) rename {test => tests}/data/lazy_blockquote.md (100%) rename {test => tests}/data/lazy_list.html (100%) rename {test => tests}/data/lazy_list.md (100%) rename {test => tests}/data/line_break.html (100%) rename {test => tests}/data/line_break.md (100%) rename {test => tests}/data/markup_consecutive_one.html (100%) rename {test => tests}/data/markup_consecutive_one.md (100%) rename {test => tests}/data/markup_consecutive_one_line.html (100%) rename {test => tests}/data/markup_consecutive_one_line.md (100%) rename {test => tests}/data/markup_consecutive_one_stripped.html (100%) rename {test => tests}/data/markup_consecutive_one_stripped.md (100%) rename {test => tests}/data/markup_consecutive_two.html (100%) rename {test => tests}/data/markup_consecutive_two.md (100%) rename {test => tests}/data/markup_consecutive_two_lines.html (100%) rename {test => tests}/data/markup_consecutive_two_lines.md (100%) rename {test => tests}/data/markup_consecutive_two_stripped.html (100%) rename {test => tests}/data/markup_consecutive_two_stripped.md (100%) rename {test => tests}/data/multiline_list_paragraph.html (100%) rename {test => tests}/data/multiline_list_paragraph.md (100%) rename {test => tests}/data/multiline_lists.html (100%) rename {test => tests}/data/multiline_lists.md (100%) rename {test => tests}/data/nested_block-level_html.html (100%) rename {test => tests}/data/nested_block-level_html.md (100%) rename {test => tests}/data/ordered_list.html (100%) rename {test => tests}/data/ordered_list.md (100%) rename {test => tests}/data/paragraph_list.html (100%) rename {test => tests}/data/paragraph_list.md (100%) rename {test => tests}/data/reference_title.html (100%) rename {test => tests}/data/reference_title.md (100%) rename {test => tests}/data/self-closing_html.html (100%) rename {test => tests}/data/self-closing_html.md (100%) rename {test => tests}/data/separated_nested_list.html (100%) rename {test => tests}/data/separated_nested_list.md (100%) rename {test => tests}/data/setext_header.html (100%) rename {test => tests}/data/setext_header.md (100%) rename {test => tests}/data/setext_header_spaces.html (100%) rename {test => tests}/data/setext_header_spaces.md (100%) rename {test => tests}/data/simple_blockquote.html (100%) rename {test => tests}/data/simple_blockquote.md (100%) rename {test => tests}/data/simple_table.html (100%) rename {test => tests}/data/simple_table.md (100%) rename {test => tests}/data/span-level_html.html (100%) rename {test => tests}/data/span-level_html.md (100%) rename {test => tests}/data/sparse_dense_list.html (100%) rename {test => tests}/data/sparse_dense_list.md (100%) rename {test => tests}/data/sparse_html.html (100%) rename {test => tests}/data/sparse_html.md (100%) rename {test => tests}/data/sparse_list.html (100%) rename {test => tests}/data/sparse_list.md (100%) rename {test => tests}/data/special_characters.html (100%) rename {test => tests}/data/special_characters.md (100%) rename {test => tests}/data/strict_atx_heading.html (100%) rename {test => tests}/data/strict_atx_heading.md (100%) rename {test => tests}/data/strikethrough.html (100%) rename {test => tests}/data/strikethrough.md (100%) rename {test => tests}/data/strong_em.html (100%) rename {test => tests}/data/strong_em.md (100%) rename {test => tests}/data/tab-indented_code_block.html (100%) rename {test => tests}/data/tab-indented_code_block.md (100%) rename {test => tests}/data/table_inline_markdown.html (100%) rename {test => tests}/data/table_inline_markdown.md (100%) rename {test => tests}/data/text_reference.html (100%) rename {test => tests}/data/text_reference.md (100%) rename {test => tests}/data/unordered_list.html (100%) rename {test => tests}/data/unordered_list.md (100%) rename {test => tests}/data/untidy_table.html (100%) rename {test => tests}/data/untidy_table.md (100%) rename {test => tests}/data/url_autolinking.html (100%) rename {test => tests}/data/url_autolinking.md (100%) rename {test => tests}/data/whitespace.html (100%) rename {test => tests}/data/whitespace.md (100%) rename {test => tests}/data/xss_attribute_encoding.html (100%) rename {test => tests}/data/xss_attribute_encoding.md (100%) rename {test => tests}/data/xss_bad_url.html (100%) rename {test => tests}/data/xss_bad_url.md (100%) rename {test => tests}/data/xss_text_encoding.html (100%) rename {test => tests}/data/xss_text_encoding.md (100%) diff --git a/.travis.yml b/.travis.yml index 7a8ba35..f2f310e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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;")" ]' diff --git a/composer.json b/composer.json index f8b40f8..301a6f6 100644 --- a/composer.json +++ b/composer.json @@ -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/"} } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4fe3177..6b39037 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ - test/ParsedownTest.php + tests/ParsedownTest.php diff --git a/Parsedown.php b/src/Parsedown.php similarity index 99% rename from Parsedown.php rename to src/Parsedown.php index ae0cbde..1be2e13 100644 --- a/Parsedown.php +++ b/src/Parsedown.php @@ -1,4 +1,7 @@

foobar

'; $expectedSafeMarkup = '
<p>foobar</p>
'; - $unsafeExtension = new UnsafeExtension; + $unsafeExtension = new SampleExtensions\UnsafeExtension; $actualMarkup = $unsafeExtension->text($markdown); $this->assertEquals($expectedMarkup, $actualMarkup); @@ -81,7 +84,7 @@ class ParsedownTest extends TestCase $expectedMarkup = '

foobar

'; $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); diff --git a/test/SampleExtensions.php b/tests/SampleExtensions/TrustDelegatedExtension.php similarity index 50% rename from test/SampleExtensions.php rename to tests/SampleExtensions/TrustDelegatedExtension.php index e855c71..04cfee8 100644 --- a/test/SampleExtensions.php +++ b/tests/SampleExtensions/TrustDelegatedExtension.php @@ -1,25 +1,12 @@ $text

"; +namespace Erusev\Parsedown\Tests\SampleExtensions; - return $Block; - } -} +use Erusev\Parsedown\Tests\TestParsedown; - -class TrustDelegatedExtension extends Parsedown +class TrustDelegatedExtension extends TestParsedown { protected function blockFencedCodeComplete($Block) { diff --git a/tests/SampleExtensions/UnsafeExtension.php b/tests/SampleExtensions/UnsafeExtension.php new file mode 100644 index 0000000..91c03d1 --- /dev/null +++ b/tests/SampleExtensions/UnsafeExtension.php @@ -0,0 +1,25 @@ +$text

"; + + return $Block; + } +} diff --git a/test/TestParsedown.php b/tests/TestParsedown.php similarity index 60% rename from test/TestParsedown.php rename to tests/TestParsedown.php index 2faa0ab..a6267ed 100644 --- a/test/TestParsedown.php +++ b/tests/TestParsedown.php @@ -1,5 +1,11 @@