diff --git a/.gitignore b/.gitignore index d1502b0..3d7e132 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ composer.lock +.phpunit.result.cache diff --git a/README.md b/README.md index 0d78b60..6040c59 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,4 @@ Reference: [erusev/parsedown](https://github.com/erusev/parsedown/wiki/Tutorial: ## License -MIT \ No newline at end of file +MIT diff --git a/composer.json b/composer.json index dea0f19..6d26360 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,12 @@ } ], "require": { - "illuminate/support": "^5.1", + "illuminate/support": "5.1 - 6.0", "erusev/parsedown": "~1.7" }, + "require-dev": { + "orchestra/testbench": "3.9.x-dev@dev" + }, "autoload": { "psr-4": { "Yansongda\\LaravelParsedown\\": "src" @@ -24,6 +27,11 @@ "src/helpers.php" ] }, + "autoload-dev": { + "psr-4": { + "Yansongda\\LaravelParsedown\\Tests\\": "tests" + } + }, "extra": { "laravel": { "providers": [ @@ -34,5 +42,7 @@ } } }, - "license": "MIT" -} \ No newline at end of file + "license": "MIT", + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..7741f18 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,31 @@ + + + + + ./tests + + + + + ./app + + + + + + + + + + + + diff --git a/src/ParsedownServiceProvider.php b/src/ParsedownServiceProvider.php index 64975fe..6b859f6 100644 --- a/src/ParsedownServiceProvider.php +++ b/src/ParsedownServiceProvider.php @@ -26,10 +26,15 @@ class ParsedownServiceProvider extends ServiceProvider */ public function boot() { - if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { - $this->publishes([ - dirname(__DIR__).'/config/markdown.php' => config_path('markdown.php'), - ], 'laravel-parsedown-config'); + if ($this->app instanceof LaravelApplication + && $this->app->runningInConsole() + ) { + $this->publishes( + [ + __DIR__.'/config/markdown.php' => config_path('markdown.php'), + ], + 'laravel-parsedown-config' + ); } elseif ($this->app instanceof LumenApplication) { $this->app->configure('markdown'); } @@ -48,11 +53,11 @@ public function register() { $this->mergeConfigFrom(dirname(__DIR__).'/config/markdown.php', 'markdown'); - $this->app->singleton(Parsedown::class, function ($app) { + $this->app->singleton(Parsedown::class, function () { return Parsedown::instance()->setSafeMode(config('markdown.parsedown.safeMode')) - ->setBreaksEnabled(config('markdown.parsedown.breaksEnabled')) - ->setMarkupEscaped(config('markdown.parsedown.markupEscaped')) - ->setUrlsLinked(config('markdown.parsedown.urlsLinked')); + ->setBreaksEnabled(config('markdown.parsedown.breaksEnabled')) + ->setMarkupEscaped(config('markdown.parsedown.markupEscaped')) + ->setUrlsLinked(config('markdown.parsedown.urlsLinked')); }); $this->app->alias(Parsedown::class, 'parsedown'); diff --git a/tests/Facades/ParsedownTest.php b/tests/Facades/ParsedownTest.php new file mode 100644 index 0000000..48d866c --- /dev/null +++ b/tests/Facades/ParsedownTest.php @@ -0,0 +1,30 @@ +assertEquals('

Heading 1

', $result); + } + + public function testFacadeWorks() + { + $result = Parsedown::text('# Heading 1'); + + $this->assertEquals('

Heading 1

', $result); + } + + public function testSingletonWorks() + { + $result = app('parsedown')->text('# Heading 1'); + + $this->assertEquals('

Heading 1

', $result); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..4b0d4c3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,16 @@ +