Skip to content

Commit

Permalink
Merge pull request #28 from heathdutton/master
Browse files Browse the repository at this point in the history
Update unit tests and support modern Laravel
  • Loading branch information
vtalbot authored Mar 1, 2021
2 parents f4e60b8 + e882747 commit efb9668
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
vendor
composer.lock
composer.phar
composer.phar
21 changes: 17 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
dist: trusty

language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1
- 7.2
- 7.3
- 7.4

env:
- COMPOSER_MEMORY_LIMIT=-1

before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
- |
if [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then
echo using PHPUnit 4.8.36
curl -sSfL -o ~/.phpenv/versions/$TRAVIS_PHP_VERSION/bin/phpunit https://phar.phpunit.de/phpunit-4.8.36.phar;
elif [ $(echo "$TRAVIS_PHP_VERSION >= 7.2" | bc -l) -eq 1 ]; then
echo using PHPUnit 8.5.2
curl -sSfL -o ~/.phpenv/versions/$TRAVIS_PHP_VERSION/bin/phpunit https://phar.phpunit.de/phpunit-8.5.2.phar;
fi
script: phpunit

matrix:
allow_failures:
- php: 5.6
- php: hhvm
fast_finish: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#### For Laravel 5+

1. Run `composer require vtalbot/markdown:2.0`
1. Run `composer require vtalbot/markdown:2.0`
2. Run `php artisan vendor:publish --provider=“VTalbot\Markdown\MarkdownServiceProvider”`
3. Then edit `markdown.php` in your `config` directory to your needs.
4. Add `VTalbot\Markdown\MarkdownServiceProvider::class` to `providers` in `config/app.php` and
Expand Down
18 changes: 8 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"name": "vtalbot/markdown",
"description": "Markdown compiler for Laravel 4",
"description": "Markdown compiler for Laravel 5",
"keywords": ["laravel", "md", "markdown", "illuminate"],
"license": "MIT",
"authors": [
{
"name": "Vincent Talbot",
"email": "[email protected]"
}
],
"authors": [{
"name": "Vincent Talbot",
"email": "[email protected]"
}],
"require": {
"laravel/framework": "~5.0",
"michelf/php-markdown": "1.5.x"
"laravel/framework": "^5||^6||^7||^8",
"michelf/php-markdown": "^1.8"
},
"require-dev": {
"mockery/mockery": "0.9.0"
},
"autoload": {
"psr-0": {"VTalbot\\Markdown": "src/"}
"psr-4": { "VTalbot\\Markdown\\": "src/" }
},
"extra": {
"branch-alias": {
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.php → config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return array(
return [

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -64,4 +64,4 @@
'predef_abbr' => array(),
),

);
];
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public function string($str)
return $contents;
}

/**
* Helper to match CommonMark func name
*
* @param string $str
* @return string
*/
public function convertToHtml($str)
{
return $this->string($str);
}

/**
* Create a new parser with the options.
*
Expand Down
11 changes: 11 additions & 0 deletions src/VTalbot/Markdown/Environment.php → src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ public function string($markdown)
return $compiler->string($markdown);
}

/**
* Helper to match CommonMark func name.
*
* @param string $markdown
* @return string
*/
public function convertToHtml($markdown)
{
return $this->string($markdown);
}

/**
* Get the appropriate Markdown engine for the given path.
*
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/VTalbot/Markdown/Markdown.php → src/Markdown.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Vtalbot\Markdown;
namespace VTalbot\Markdown;

use Illuminate\View\Engines\EngineInterface;
use Illuminate\Contracts\Support\Renderable as Renderable;
Expand Down Expand Up @@ -139,4 +139,4 @@ public function __toString()
return $this->render();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Response;
use File;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Container\Container;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\FileViewFinder;
Expand All @@ -16,18 +17,25 @@
class MarkdownServiceProvider extends ServiceProvider {

/**
* Register the service provider.
* Bootstrap the application services.
*
* @return void
*/
public function register()
public function boot()
{
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('markdown.php'),
]);

$this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'markdown');
$path_config = __DIR__.'/../config/config.php';
$publish_path_config = config_path('markdown.php');
$this->publishes([$path_config => $publish_path_config,], 'config');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'markdown');
$this->registerRoutes();
$this->registerEngineResolver();
$this->registerMarkdownFinder();
Expand Down Expand Up @@ -66,13 +74,13 @@ public function registerEngineResolver()
{
list($me, $app) = array($this, $this->app);

$app['markdown.engine.resolver'] = $app->share(function($app) use ($me)
{
$resolver = new EngineResolver;
$me->registerMarkdownEngine($resolver);
$this->app->singleton('markdown.engine.resolver', function () use ($app, $me) {
$resolver = new EngineResolver;
$me->registerMarkdownEngine($resolver);

return $resolver;
});

return $resolver;
});
}

/**
Expand Down Expand Up @@ -109,17 +117,20 @@ public function registerMarkdownEngine($resolver)
*/
public function registerMarkdownFinder()
{
$this->app['markdown.finder'] = $this->app->share(function($app)
{
$paths = Config::get('markdown.paths');
$app = $this->app;

foreach ($paths as $key => $path)
{
$paths[$key] = app_path().$path;
}
$this->app->singleton('markdown.finder', function () use ($app) {

$paths = Config::get('markdown.paths');

foreach ($paths as $key => $path)
{
$paths[$key] = app_path().$path;
}

return new FileViewFinder($app['files'], $paths, array('markdown', 'md'));
});

return new FileViewFinder($app['files'], $paths, array('markdown', 'md'));
});
}

/**
Expand All @@ -129,24 +140,25 @@ public function registerMarkdownFinder()
*/
public function registerEnvironment()
{
$me = $this;
//$me = $this;
$app = $this->app;

$this->app['markdown'] = $this->app->share(function($app) use ($me)
{
$resolver = $app['markdown.engine.resolver'];
$this->app->singleton('markdown', function () use ($app) {
$resolver = $app['markdown.engine.resolver'];

$finder = $app['markdown.finder'];
$finder = $app['markdown.finder'];

$events = $app['events'];
$events = $app['events'];

$environment = new Environment($resolver, $finder, $events);
$environment = new Environment($resolver, $finder, $events);

$environment->setContainer($app);
$environment->setContainer($app);

$environment->share('app', $app);
$environment->share('app', $app);

return $environment;
});

return $environment;
});
}

}
11 changes: 6 additions & 5 deletions tests/MarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
use Mockery as m;
use VTalbot\Markdown\Compilers\MarkdownCompiler;

class MarkdownTest extends PHPUnit_Framework_TestCase {
class MarkdownTest extends PHPUnit\Framework\TestCase {

public function tearDown()
{
m::close();
}
// Removed for BC.
// protected function tearDown()
// {
// m::close();
// }

public function testTransformString()
{
Expand Down

0 comments on commit efb9668

Please sign in to comment.