Compare commits

..

No commits in common. "master" and "1.4.2" have entirely different histories.

34 changed files with 142 additions and 453 deletions

View file

@ -1,91 +0,0 @@
name: PHPUnit
on:
pull_request:
jobs:
phpunit:
name: "PHPUnit - PHP ${{ matrix.php-version }}"
runs-on: ubuntu-20.04
continue-on-error: false
env:
SYMFONY_REQUIRE: ${{matrix.symfony-require}}
SYMFONY_DEPRECATIONS_HELPER: ${{matrix.symfony-deprecations-helper}}
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
deps:
- "stable"
symfony-require:
- "5.4.*"
symfony-deprecations-helper:
- "5"
include:
- symfony-require: "4.4.*"
php-version: "7.4"
deps: "low"
symfony-deprecations-helper: ""
- symfony-require: "4.4.*"
php-version: "7.4"
deps: "stable"
symfony-deprecations-helper: "5"
- symfony-require: "6.0.*"
php-version: "8.0"
deps: "stable"
symfony-deprecations-helper: "5"
- symfony-require: "6.0.*"
php-version: "8.1"
deps: "stable"
symfony-deprecations-helper: "5"
fail-fast: true
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo, pdo_sqlite, sqlite3
ini-values: date.timezone=UTC
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Install dependencies with Composer
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable
- name: Cache dependencies installed with Composer
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
- name: Install stable dependencies with Composer
run: composer update --no-interaction --prefer-dist --prefer-stable
if: "${{ matrix.deps == 'stable' }}"
- name: Install dev dependencies with Composer
run: composer update --no-interaction --prefer-dist
if: "${{ matrix.deps == 'dev' }}"
- name: Install lowest possible dependencies with Composer
run: composer update --no-interaction --prefer-dist --prefer-stable --prefer-lowest
if: "${{ matrix.deps == 'low' }}"
- name: Install PHPUnit
run: composer run-script test install
- name: Run tests
run: composer run-script test -v

4
.gitignore vendored
View file

@ -1,6 +1,4 @@
.phpunit.result.cache
phpunit.xml
var/
vendor/*
!vendor/parser
composer.lock
Tests/fixtures/app/cache

View file

@ -1,39 +1,36 @@
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache/files
- $HOME/symfony-bridge/.phpunit
env:
global:
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.2
- php: 7.3
env: deps=low
- php: 7.4
- php: 8.0
# Test against lowest bounds of dependencies to ensure they are right
- php: 5.6
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
# Test against dev versions of dependencies
- php: 5.6
env: deps=dev
before_install:
- phpenv config-rm xdebug.ini || true
- composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main
- if [ "$deps" = 'dev' ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
install:
- |
if [[ $deps = low ]]; then
export SYMFONY_DEPRECATIONS_HELPER=weak
composer update --prefer-dist --prefer-lowest --prefer-stable
else
composer update --prefer-dist
fi
- ./vendor/bin/simple-phpunit install
- composer update $COMPOSER_FLAGS
script:
- composer validate --strict --no-check-lock
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
script: phpunit --coverage-text
notifications:
email:
- travis@knplabs.com

View file

@ -1,6 +0,0 @@
1.7
===
* The MarkdownHelper Templating component integration (and corresponding
`templating.helper.markdown` services) are no longer added unless you
have the `symfony/templating` component installed.

View file

@ -10,7 +10,7 @@ class ParsersCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('markdown.parser.parser_manager')) {
if (!$container->hasDefinition('templating.helper.markdown')) {
return;
}
@ -24,7 +24,7 @@ class ParsersCompilerPass implements CompilerPassInterface
$defaultAlias = isset($defaultAlias['alias']) ? $defaultAlias['alias'] : null;
}
$definition = $container->getDefinition('markdown.parser.parser_manager');
$definition = $container->getDefinition('templating.helper.markdown');
if (empty($defaultAlias)) {
$definition->addMethodCall('addParser', array(new Reference('markdown.parser'), 'default'));
}

View file

@ -12,12 +12,11 @@ class Configuration implements ConfigurationInterface
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder(): TreeBuilder
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('knp_markdown');
$rootNode = $treeBuilder->getRootNode();
$treeBuilder = new TreeBuilder();
$rootNode
$treeBuilder->root('knp_markdown', 'array')
->addDefaultsIfNotSet()
->children()
->arrayNode('parser')

View file

@ -2,15 +2,11 @@
namespace Knp\Bundle\MarkdownBundle\DependencyInjection;
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
use Michelf\MarkdownInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Templating\EngineInterface;
class KnpMarkdownExtension extends Extension
{
@ -30,10 +26,7 @@ class KnpMarkdownExtension extends Extension
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('parser.xml');
// BC to support the PHP templates in the Templating component
if (interface_exists(EngineInterface::class)) {
$loader->load('helper.xml');
}
$loader->load('helper.xml');
$loader->load('twig.xml');
if ('markdown.parser.sundown' == $config['parser']['service']) {
@ -50,8 +43,6 @@ class KnpMarkdownExtension extends Extension
$container->setParameter('markdown.sundown.render_flags', $config['sundown']['render_flags']);
}
$container->setAlias('markdown.parser', new Alias($config['parser']['service'], true));
$container->setAlias(MarkdownParserInterface::class, 'markdown.parser');
$container->setAlias(MarkdownInterface::class, 'markdown.parser');
$container->setAlias('markdown.parser', $config['parser']['service']);
}
}

View file

@ -2,20 +2,24 @@
namespace Knp\Bundle\MarkdownBundle\Helper;
use Knp\Bundle\MarkdownBundle\Parser\ParserManager;
use Symfony\Component\Templating\Helper\HelperInterface;
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
/**
* @deprecated The MarkdownHelper was deprecated in 1.7 and will be removed in 2.0.
*/
class MarkdownHelper implements HelperInterface
{
private $parserManager;
/**
* @var MarkdownParserInterface[]
*/
private $parsers = array();
private $charset = 'UTF-8';
public function __construct(ParserManager $parserManager)
/**
* @param MarkdownParserInterface $parser
* @param string $alias
*/
public function addParser(MarkdownParserInterface $parser, $alias)
{
$this->parserManager = $parserManager;
$this->parsers[$alias] = $parser;
}
/**
@ -30,9 +34,17 @@ class MarkdownHelper implements HelperInterface
*/
public function transform($markdownText, $parserName = null)
{
trigger_error('The MarkdownHelper was deprecated in 1.7 and will be removed in KnpMarkdownBundle 2.0.', E_USER_DEPRECATED);
if (null === $parserName) {
$parserName = 'default';
}
return $this->parserManager->transform($markdownText, $parserName);
if (!isset($this->parsers[$parserName])) {
throw new \RuntimeException(sprintf('Unknown parser selected ("%s"), available are: %s', $parserName, implode(', ', array_keys($this->parsers))));
}
$parser = $this->parsers[$parserName];
return $parser->transformMarkdown($markdownText);
}
/**
@ -50,7 +62,7 @@ class MarkdownHelper implements HelperInterface
*
* @return string The default charset
*/
public function getCharset(): string
public function getCharset()
{
return $this->charset;
}

View file

@ -124,7 +124,7 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface
/**
* Simplify detab
*/
public function detab($text): string
public function detab($text)
{
return str_replace("\t", str_repeat(' ', $this->tab_width), $text);
}
@ -216,7 +216,6 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface
[ \n]* # ignore any spaces/tabs between closing quote and )
)? # title is optional
\)
(?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes
)
}xs',
array(&$this, '_doAnchors_inline_callback'), $text);

View file

@ -1,47 +0,0 @@
<?php
namespace Knp\Bundle\MarkdownBundle\Parser;
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
class ParserManager
{
/**
* @var MarkdownParserInterface[]
*/
private $parsers = array();
/**
* @param MarkdownParserInterface $parser
* @param string $alias
*/
public function addParser(MarkdownParserInterface $parser, $alias)
{
$this->parsers[$alias] = $parser;
}
/**
* Transforms markdown syntax to HTML
*
* @param string $markdownText The markdown syntax text
* @param null|string $parserName
*
* @return string The HTML code
*
* @throws \RuntimeException
*/
public function transform($markdownText, $parserName = null)
{
if (null === $parserName) {
$parserName = 'default';
}
if (!isset($this->parsers[$parserName])) {
throw new \RuntimeException(sprintf('Unknown parser selected ("%s"), available are: %s', $parserName, implode(', ', array_keys($this->parsers))));
}
$parser = $this->parsers[$parserName];
return $parser->transformMarkdown($markdownText);
}
}

View file

@ -15,7 +15,7 @@ class Min extends MarkdownParser
$this->features[$name] = false;
}
parent::__construct($features);
return parent::__construct($features);
}
}

View file

@ -1,69 +1,48 @@
> **WARNING:** This bundle is **abandoned** in favor of [markdown_to_html](https://twig.symfony.com/doc/3.x/filters/markdown_to_html.html)
> Twig filter. Please, consider using it instead. Migration should be easy because it also supports
> `michelf/php-markdown` Markdown parser that is used in this project under the hood.
Provide markdown conversion (based on [Michel Fortin work](https://github.com/michelf/php-markdown)) to your Symfony2 projects.
Provide markdown conversion (based on [Michel Fortin work](https://github.com/michelf/php-markdown)) to your Symfony projects.
[![Build Status](https://secure.travis-ci.org/KnpLabs/KnpMarkdownBundle.svg)](http://travis-ci.org/KnpLabs/KnpMarkdownBundle)
![ci.yml](https://github.com/tacman/KnpMarkdownBundle/actions/workflows/ci.yml/badge.svg)
![php.yml](https://github.com/tacman/KnpMarkdownBundle/actions/workflows/php.yml/badge.svg)
[![Build Status](https://secure.travis-ci.org/KnpLabs/KnpMarkdownBundle.png)](http://travis-ci.org/KnpLabs/KnpMarkdownBundle)
## INSTALLATION
Add KnpMarkdownBundle to your project via [Composer](https://getcomposer.org/):
Add KnpMarkdownBundle to your `composer.json`
```yaml
{
"require": {
"knplabs/knp-markdown-bundle": "~1.3"
}
}
```
composer require knplabs/knp-markdown-bundle
or simply run ```composer require knplabs/knp-markdown-bundle:~1.3```
Register the bundle in ``app/AppKernel.php``
```php
$bundles = array(
// ...
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
);
```
If you're *not* using Symfony Flex, you will also need to enable
the bundle in your `app/AppKernel.php` file
(`new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle()`).
That's it! Start using it!
## USAGE
Once the bundle is installed, you can autowire a `MarkdownParserInterface`
into any service or controller:
```php
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
// Use the service
$html = $this->container->get('markdown.parser')->transformMarkdown($text);
// from inside a controller
public function index(MarkdownParserInterface $parser)
{
$html = $parser->transformMarkdown($text);
}
// Use the helper with default parser
echo $view['markdown']->transform($text);
// or from inside a service
private $parser;
public function __construct(MarkdownParserInterface $parser)
{
$this->parser = $parser;
}
public function someMethod()
{
$html = $this->parser->transformMarkdown($text);
}
// Use the helper and a select specific parser
echo $view['markdown']->transform($text, $parserName);
```
There is also a public `markdown.parser` service you can use.
In Twig, you can use the `markdown` filter:
If you have enabled the Twig markdown filter, you can use the following in your Twig templates:
```twig
{# Use default parser #}
{{ my_data|markdown }}
{# If my_data is entered by a user, escape HTML tags before printing it #}
{{ my_data|escape|markdown }}
{# or strip HTML tags #}
{{ my_data|striptags|markdown }}
{# Or select specific parser #}
{{ my_data|markdown('parserName') }}
```
@ -74,8 +53,6 @@ Create a service implementing `Knp\Bundle\MarkdownBundle\MarkdownParserInterface
then configure the bundle to use it:
```yaml
# Symfony 3: app/config/config.yml
# Symfony 4: config/packages/knp_markdown.yaml (you'll need to create this)
knp_markdown:
parser:
service: my.markdown.parser
@ -85,7 +62,7 @@ Alternatively if you are using the ``markdown.parser.sundown`` there are
options for enabling sundown extensions and render flags, see the
default Configuration with:
php bin/console config:dump-reference knp_markdown
php app/console config:dump-reference knp_markdown
This bundle comes with 5 parser services, 4 based on the same algorithm
but providing different levels of compliance to the markdown specification,
@ -100,3 +77,7 @@ and one which is uses the php sundown extension:
``markdown.parser.sundown`` requires the [php sundown extension](https://github.com/chobie/php-sundown).
For more details, see the implementations in Parser/Preset.
## TEST
phpunit -c myapp vendor/bundles/Knp/Bundle/MarkdownBundle

View file

@ -9,7 +9,7 @@
<services>
<service id="templating.helper.markdown" class="%templating.helper.markdown.class%">
<argument type="service" id="markdown.parser.parser_manager" />
<argument type="service" id="markdown.parser" />
<tag name="templating.helper" alias="markdown" />
</service>
</services>

View file

@ -19,8 +19,5 @@
<service id="markdown.parser.flavored" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Flavored" public="false">
<tag name="markdown.parser" alias="flavored" />
</service>
<!-- parsers will be injected with a compiler pass -->
<service id="markdown.parser.parser_manager" class="Knp\Bundle\MarkdownBundle\Parser\ParserManager" public="false" />
</services>
</container>

View file

@ -5,7 +5,7 @@
<services>
<service id="twig.extension.exercise.twig" class="Knp\Bundle\MarkdownBundle\Twig\Extension\MarkdownTwigExtension" public="false">
<argument type="service" id="markdown.parser.parser_manager" />
<argument type="service" id="templating.helper.markdown" />
<tag name="twig.extension" />
</service>
</services>

View file

@ -2,14 +2,13 @@
namespace Knp\Bundle\MarkdownBundle\Tests;
use PHPUnit\Framework\TestCase;
use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser as Parser;
class EscapingTest extends TestCase
class EscapingTest extends \PHPUnit_Framework_TestCase
{
protected $parser;
protected function setUp(): void
public function setUp()
{
$this->parser = new Parser();
}

View file

@ -3,9 +3,8 @@
namespace Knp\Bundle\MarkdownBundle\Tests;
use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser as Parser;
use PHPUnit\Framework\TestCase;
class FeatureTest extends TestCase
class FeatureTest extends \PHPUnit_Framework_TestCase
{
public function testParser()
{
@ -750,15 +749,23 @@ That's some text with a footnote.[^1]
[^1]: And that's the footnote.
EOF;
$actualHtml = $parser->transform($text);
$html = <<<EOF
<p>That's some text with a footnote.<sup id="fnref:1"><a href="#fn:1" class="footnote-ref">1</a></sup></p>
// asserting a few things instead of comparing full final HTML
// because a few minor things have changed over versions of Michelf
// With assertContains(), tests will pass across all versions
$this->assertStringContainsString('<p>That\'s some text with a footnote.<sup id="fnref:1"><a href="#fn:1"', $actualHtml);
$this->assertStringContainsString('<div class="footnotes"', $actualHtml);
$this->assertStringContainsString('<li id="fn:1"', $actualHtml);
$this->assertStringContainsString('<p>And that\'s the footnote.&#160;<a href="#fnref:1" class="footnote-backref"', $actualHtml);
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
<p>And that's the footnote.&#160;<a href="#fnref:1" class="footnote-backref">&#8617;</a></p>
</li>
</ol>
</div>
EOF;
$this->assertEquals($html, $parser->transform($text));
}
/**

View file

@ -3,9 +3,8 @@
namespace Knp\Bundle\MarkdownBundle\Tests;
use Knp\Bundle\MarkdownBundle\Parser\Preset as Preset;
use PHPUnit\Framework\TestCase;
class PresetTest extends TestCase
class PresetTest extends \PHPUnit_Framework_TestCase
{
public function testMax()
{

View file

@ -2,32 +2,30 @@
namespace Knp\Bundle\MarkdownBundle\Twig\Extension;
use Knp\Bundle\MarkdownBundle\Parser\ParserManager;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Knp\Bundle\MarkdownBundle\Helper\MarkdownHelper;
class MarkdownTwigExtension extends AbstractExtension
class MarkdownTwigExtension extends \Twig_Extension
{
private $parserManager;
protected $helper;
public function __construct(ParserManager $parserManager)
public function __construct(MarkdownHelper $helper)
{
$this->parserManager = $parserManager;
$this->helper = $helper;
}
public function getFilters(): array
public function getFilters()
{
return array(
new TwigFilter('markdown', array($this, 'markdown'), array('is_safe' => array('html'))),
new \Twig_SimpleFilter('markdown', array($this, 'markdown'), array('is_safe' => array('html'))),
);
}
public function markdown($text, $parser = null): string
public function markdown($text, $parser = null)
{
return $this->parserManager->transform($text, $parser);
return $this->helper->transform($text, $parser);
}
public function getName(): string
public function getName()
{
return 'markdown';
}

View file

@ -18,18 +18,13 @@
],
"require": {
"php": "^7.4|^8.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
"michelf/php-markdown": "^1.9"
"php": ">=5.3.9",
"symfony/framework-bundle": "~2.3|~3.0",
"michelf/php-markdown": "~1.4"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.4.11|^5.0|^6.0",
"symfony/templating": "^4.4|^5.0|^6.0",
"phpstan/phpstan": "^1.2",
"phpstan/phpstan-symfony": "^1.0"
"phpunit/phpunit": "~4.5"
},
"abandoned": "twig/markdown-extra",
"suggest": {
"symfony/twig-bundle": "to use the Twig markdown filter",
"ext-sundown": "to use optional support for php-sundown extension instead of php implementation"
@ -37,19 +32,7 @@
"extra": {
"branch-alias": {
"dev-master": "1.5.x-dev"
}
},
"scripts": {
"test": [
"php ./vendor/bin/simple-phpunit"
]
},
"autoload-dev": {
"psr-4": {
"Knp\\Bundle\\MarkdownBundle\\Tests\\": "tests/"
"dev-master": "1.4.x-dev"
}
},

View file

@ -1,31 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
failOnIncomplete="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php"
>
<php>
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
</php>
<coverage processUncoveredFiles="true">
<include>
<directory>.</directory>
</include>
<exclude>
<directory>tests</directory>
<directory>vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Markdown Test Suite">
<directory>tests</directory>
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View file

@ -1,63 +0,0 @@
<?php
namespace Knp\Bundle\MarkdownBundle\Tests;
use Knp\Bundle\MarkdownBundle\KnpMarkdownBundle;
use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;
class IntegrationTest extends TestCase
{
public function testServicesAvailable()
{
$kernel = new IntegrationKernel('dev', true);
$kernel->boot();
$container = $kernel->getContainer();
$this->assertInstanceOf(MarkdownParser::class, $container->get('markdown.parser'));
}
}
class IntegrationKernel extends Kernel
{
use MicroKernelTrait;
private $cacheDir;
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
new KnpMarkdownBundle(),
];
}
protected function configureRoutes(RoutingConfigurator $routes)
{
}
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$c->loadFromExtension('framework', [
'secret' => 'F00',
'router' => ['utf8' => true]
]);
}
public function getCacheDir(): string
{
if (null === $this->cacheDir) {
$this->cacheDir = sys_get_temp_dir().'/'.rand(100, 999);
}
return $this->cacheDir;
}
}

View file

@ -1,29 +0,0 @@
<?php
namespace Knp\Bundle\MarkdownBundle\Tests\Parser;
use Knp\Bundle\MarkdownBundle\Helper\MarkdownHelper;
use Knp\Bundle\MarkdownBundle\Tests\fixtures\app\TestKernel;
use Knp\Bundle\MarkdownBundle\Parser\ParserManager;
use PHPUnit\Framework\TestCase;
class ParserManagerTest extends TestCase
{
public function testIntegration()
{
require_once __DIR__.'/../fixtures/app/TestKernel.php';
$kernel = new TestKernel('dev', true);
$kernel->boot();
$container = $kernel->getContainer();
/** @var ParserManager $parserManager */
$parserManager = $container->get('markdown.parser.parser_manager.public');
$actual = $parserManager->transform('*hi*');
$this->assertEquals("<p><em>hi</em></p>\n", $actual, 'There is a default parser');
$actual = $parserManager->transform('*hi*', 'light');
$this->assertEquals("<p><em>hi</em></p>\n", $actual, 'Specific parsers are registered');
}
}

View file

@ -1,34 +0,0 @@
<?php
namespace Knp\Bundle\MarkdownBundle\Tests\fixtures\app;
use Knp\Bundle\MarkdownBundle\KnpMarkdownBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel;
class TestKernel extends Kernel
{
public function registerBundles(): iterable
{
return array(
new FrameworkBundle(),
new KnpMarkdownBundle(),
);
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function(ContainerBuilder $c) {
$c->loadFromExtension('framework', array(
'secret' => 'MarkdownTesting'
));
// add a public alias so we can fetch for testing
$c->setAlias('markdown.parser.parser_manager.public', new Alias('markdown.parser.parser_manager', true));
});
}
}