diff --git a/.github/workflows/phpunit.yaml b/.github/workflows/phpunit.yaml new file mode 100644 index 0000000..22dfdef --- /dev/null +++ b/.github/workflows/phpunit.yaml @@ -0,0 +1,91 @@ +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 diff --git a/.gitignore b/.gitignore index d2cb556..717b31c 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +.phpunit.result.cache phpunit.xml +var/ vendor/* composer.lock Tests/fixtures/app/cache diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 90bbdfa..c9b6e90 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -12,11 +12,10 @@ class Configuration implements ConfigurationInterface * * @return TreeBuilder */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('knp_markdown'); - // BC layer for symfony/config < 4.2 - $rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('knp_markdown'); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->addDefaultsIfNotSet() diff --git a/Helper/MarkdownHelper.php b/Helper/MarkdownHelper.php index 0b3974f..fc7de2d 100644 --- a/Helper/MarkdownHelper.php +++ b/Helper/MarkdownHelper.php @@ -50,7 +50,7 @@ class MarkdownHelper implements HelperInterface * * @return string The default charset */ - public function getCharset() + public function getCharset(): string { return $this->charset; } diff --git a/Parser/MarkdownParser.php b/Parser/MarkdownParser.php index df369b3..378786a 100644 --- a/Parser/MarkdownParser.php +++ b/Parser/MarkdownParser.php @@ -124,7 +124,7 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface /** * Simplify detab */ - public function detab($text) + public function detab($text): string { return str_replace("\t", str_repeat(' ', $this->tab_width), $text); } diff --git a/Parser/Preset/Min.php b/Parser/Preset/Min.php index 2a4646b..50f774f 100644 --- a/Parser/Preset/Min.php +++ b/Parser/Preset/Min.php @@ -15,7 +15,7 @@ class Min extends MarkdownParser $this->features[$name] = false; } - return parent::__construct($features); + parent::__construct($features); } } diff --git a/README.markdown b/README.markdown index 715d6ad..398d3a7 100644 --- a/README.markdown +++ b/README.markdown @@ -2,6 +2,9 @@ Provide markdown conversion (based on [Michel Fortin work](https://github.com/mi [![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) + ## INSTALLATION Add KnpMarkdownBundle to your project via [Composer](https://getcomposer.org/): diff --git a/Twig/Extension/MarkdownTwigExtension.php b/Twig/Extension/MarkdownTwigExtension.php index e9ab8c0..9d20683 100644 --- a/Twig/Extension/MarkdownTwigExtension.php +++ b/Twig/Extension/MarkdownTwigExtension.php @@ -15,19 +15,19 @@ class MarkdownTwigExtension extends AbstractExtension $this->parserManager = $parserManager; } - public function getFilters() + public function getFilters(): array { return array( new TwigFilter('markdown', array($this, 'markdown'), array('is_safe' => array('html'))), ); } - public function markdown($text, $parser = null) + public function markdown($text, $parser = null): string { return $this->parserManager->transform($text, $parser); } - public function getName() + public function getName(): string { return 'markdown'; } diff --git a/composer.json b/composer.json index 961801c..c064cb9 100644 --- a/composer.json +++ b/composer.json @@ -18,14 +18,16 @@ ], "require": { - "php": "^7.1.3|^8.0", - "symfony/framework-bundle": "~3.4|^4.0|^5.0", - "symfony/dependency-injection": "~3.4|^4.0|^5.0", - "michelf/php-markdown": "~1.4" + "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" }, "require-dev": { - "symfony/phpunit-bridge": "^4.4.0 || ^5.0", - "symfony/templating": "~3.4|^4.0|^5.0" + "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" }, "suggest": { "symfony/twig-bundle": "to use the Twig markdown filter", @@ -38,6 +40,18 @@ } }, + "scripts": { + "test": [ + "php ./vendor/bin/simple-phpunit" + ] + }, + + "autoload-dev": { + "psr-4": { + "Knp\\Bundle\\MarkdownBundle\\Tests\\": "tests/" + } + }, + "autoload": { "psr-4": { "Knp\\Bundle\\MarkdownBundle\\": "" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0bdd033..e8fcfce 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,30 +2,30 @@ - + + + + . + + + tests + vendor + + tests - - - - . - - tests - vendor - - - - \ No newline at end of file + diff --git a/Tests/EscapingTest.php b/tests/EscapingTest.php similarity index 89% rename from Tests/EscapingTest.php rename to tests/EscapingTest.php index a2d396f..443eec1 100644 --- a/Tests/EscapingTest.php +++ b/tests/EscapingTest.php @@ -2,13 +2,14 @@ namespace Knp\Bundle\MarkdownBundle\Tests; +use PHPUnit\Framework\TestCase; use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser as Parser; -class EscapingTest extends \PHPUnit_Framework_TestCase +class EscapingTest extends TestCase { protected $parser; - public function setUp() + protected function setUp(): void { $this->parser = new Parser(); } diff --git a/Tests/FeatureTest.php b/tests/FeatureTest.php similarity index 97% rename from Tests/FeatureTest.php rename to tests/FeatureTest.php index 7c0d099..a2291d7 100644 --- a/Tests/FeatureTest.php +++ b/tests/FeatureTest.php @@ -3,8 +3,9 @@ namespace Knp\Bundle\MarkdownBundle\Tests; use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser as Parser; +use PHPUnit\Framework\TestCase; -class FeatureTest extends \PHPUnit_Framework_TestCase +class FeatureTest extends TestCase { public function testParser() { @@ -754,10 +755,10 @@ EOF; // 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->assertContains('

That\'s some text with a footnote.assertContains('

assertContains('
  • assertContains('

    And that\'s the footnote. assertStringContainsString('

    That\'s some text with a footnote.assertStringContainsString('

  • assertStringContainsString('

    And that\'s the footnote. setParameter('kernel.secret', '1234'); + + $c->loadFromExtension('framework', [ + 'secret' => 'F00', + 'router' => ['utf8' => true] + ]); } - public function getCacheDir() + public function getCacheDir(): string { if (null === $this->cacheDir) { $this->cacheDir = sys_get_temp_dir().'/'.rand(100, 999); diff --git a/Tests/Parser/ParserManagerTest.php b/tests/Parser/ParserManagerTest.php similarity index 92% rename from Tests/Parser/ParserManagerTest.php rename to tests/Parser/ParserManagerTest.php index 9285ea8..7357c1e 100644 --- a/Tests/Parser/ParserManagerTest.php +++ b/tests/Parser/ParserManagerTest.php @@ -5,8 +5,9 @@ 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 \PHPUnit_Framework_TestCase +class ParserManagerTest extends TestCase { public function testIntegration() { diff --git a/Tests/Performance/.htaccess b/tests/Performance/.htaccess similarity index 100% rename from Tests/Performance/.htaccess rename to tests/Performance/.htaccess diff --git a/Tests/Performance/Base.php b/tests/Performance/Base.php similarity index 100% rename from Tests/Performance/Base.php rename to tests/Performance/Base.php diff --git a/Tests/Performance/Light.php b/tests/Performance/Light.php similarity index 100% rename from Tests/Performance/Light.php rename to tests/Performance/Light.php diff --git a/Tests/Performance/Max.php b/tests/Performance/Max.php similarity index 100% rename from Tests/Performance/Max.php rename to tests/Performance/Max.php diff --git a/Tests/Performance/Medium.php b/tests/Performance/Medium.php similarity index 100% rename from Tests/Performance/Medium.php rename to tests/Performance/Medium.php diff --git a/Tests/Performance/Min.php b/tests/Performance/Min.php similarity index 100% rename from Tests/Performance/Min.php rename to tests/Performance/Min.php diff --git a/Tests/Performance/index.php b/tests/Performance/index.php similarity index 100% rename from Tests/Performance/index.php rename to tests/Performance/index.php diff --git a/Tests/Performance/run b/tests/Performance/run similarity index 100% rename from Tests/Performance/run rename to tests/Performance/run diff --git a/Tests/PresetTest.php b/tests/PresetTest.php similarity index 94% rename from Tests/PresetTest.php rename to tests/PresetTest.php index cc7aaf0..224cb31 100644 --- a/Tests/PresetTest.php +++ b/tests/PresetTest.php @@ -3,8 +3,9 @@ namespace Knp\Bundle\MarkdownBundle\Tests; use Knp\Bundle\MarkdownBundle\Parser\Preset as Preset; +use PHPUnit\Framework\TestCase; -class PresetTest extends \PHPUnit_Framework_TestCase +class PresetTest extends TestCase { public function testMax() { diff --git a/Tests/fixtures/app/TestKernel.php b/tests/fixtures/app/TestKernel.php similarity index 95% rename from Tests/fixtures/app/TestKernel.php rename to tests/fixtures/app/TestKernel.php index b5cb93d..26cf034 100644 --- a/Tests/fixtures/app/TestKernel.php +++ b/tests/fixtures/app/TestKernel.php @@ -12,7 +12,7 @@ use Symfony\Component\HttpKernel\Kernel; class TestKernel extends Kernel { - public function registerBundles() + public function registerBundles(): iterable { return array( new FrameworkBundle(), @@ -31,4 +31,4 @@ class TestKernel extends Kernel $c->setAlias('markdown.parser.parser_manager.public', new Alias('markdown.parser.parser_manager', true)); }); } -} \ No newline at end of file +} diff --git a/Tests/fixtures/big_text.html b/tests/fixtures/big_text.html similarity index 100% rename from Tests/fixtures/big_text.html rename to tests/fixtures/big_text.html diff --git a/Tests/fixtures/big_text.markdown b/tests/fixtures/big_text.markdown similarity index 100% rename from Tests/fixtures/big_text.markdown rename to tests/fixtures/big_text.markdown