Skip to content

Commit 73e18c0

Browse files
committed
UPGRADE minimum CommonMark version to v2
1 parent 9d72f27 commit 73e18c0

7 files changed

Lines changed: 25 additions & 19 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CommonMarkBundle
2-
A **Symfony 4 / 5** bundle to easily configure [league/commonmark](https://github.com/thephpleague/commonmark),
2+
A **Symfony 4 / 5** bundle to easily configure [league/commonmark](https://github.com/thephpleague/commonmark) **v2**,
33
allowing you to set multiple **MarkDown** converters.
44

55
![Unit Test Suite](https://github.com/AymDev/CommonMarkBundle/workflows/Unit%20Test%20Suite/badge.svg)
@@ -55,27 +55,27 @@ The `type` key can be used to choose between a *CommonMark* or a *GitHub* conver
5555
### Converter options
5656

5757
The `options` key holds the configuration passed to the converter, as an array.
58-
>For more information, see the [CommonMark documentation about Configuration](https://commonmark.thephpleague.com/1.5/configuration/).
58+
>For more information, see the [CommonMark documentation about Configuration](https://commonmark.thephpleague.com/2.0/configuration/).
5959

6060
### Converter extensions
6161

6262
The `extensions` key allows to add any extension class to a converter.
63-
>Check the complete list of extensions on the [CommonMark documentation](https://commonmark.thephpleague.com/1.5/extensions/overview/).
63+
>Check the complete list of extensions on the [CommonMark documentation](https://commonmark.thephpleague.com/2.0/extensions/overview/).
6464

6565
## Using the converters
6666

6767
### As services
6868
The bundle registers your converters as **services** with the converter name as the **service ID**.
6969

7070
It also creates an alias, so you can get them by *autowiring* using the *converter name* as the *argument name*,
71-
type with the `League\CommonMark\CommonMarkConverter` class.
71+
type with the `League\CommonMark\MarkdownConverter` class.
7272

7373
**Example YAML configuration**:
7474
```yaml
7575
aymdev_commonmark:
7676
converters:
7777
# You can add an argument for this converter as:
78-
# CommonMarkConverter $myConverter
78+
# MarkdownConverter $myConverter
7979
my_converter:
8080
```
8181

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": ">=7.1",
14+
"php": "^7.1||^8.0",
1515
"symfony/http-kernel": "^4.4|^5.0",
1616
"symfony/dependency-injection": "^4.4|^5.0",
1717
"symfony/config": "^4.4|^5.0",
18-
"league/commonmark": "^1.5",
18+
"league/commonmark": "^2.0",
1919
"symfony/framework-bundle": "^4.4|^5.0"
2020
},
2121
"autoload": {
@@ -25,7 +25,7 @@
2525
},
2626
"autoload-dev": {
2727
"psr-4": {
28-
"Tests\\Aymdev\\CommonmarkBundle\\": "tests/"
28+
"Tests\\AymDev\\CommonmarkBundle\\": "tests/"
2929
}
3030
},
3131
"require-dev": {

src/DependencyInjection/AymdevCommonmarkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Aymdev\CommonmarkBundle\DependencyInjection\Compiler\ConvertersPass;
66
use Aymdev\CommonmarkBundle\Twig\CommonMarkExtension;
7-
use League\CommonMark\Environment;
7+
use League\CommonMark\Environment\Environment;
88
use League\CommonMark\MarkdownConverter;
99
use Symfony\Component\DependencyInjection\ContainerBuilder;
1010
use Symfony\Component\DependencyInjection\Definition;

src/Twig/CommonMarkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public function convertMarkdown(?string $markdown, ?string $converterName = null
5050

5151
/** @var MarkdownConverter $converter */
5252
$converter = $this->serviceLocator->get($converterName);
53-
return $converter->convertToHtml($markdown);
53+
return $converter->convertToHtml($markdown)->getContent();
5454
}
5555
}

tests/DependencyInjection/AymDevCommonmarkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Aymdev\CommonmarkBundle\DependencyInjection\AymdevCommonMarkExtension;
66
use Aymdev\CommonmarkBundle\DependencyInjection\Compiler\ConvertersPass;
7-
use League\CommonMark\Environment;
7+
use League\CommonMark\Environment\Environment;
88
use League\CommonMark\MarkdownConverter;
99
use PHPUnit\Framework\TestCase;
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;

tests/DependencyInjection/Compiler/ConvertersPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\AymDev\CommonMarkBundle\DependencyInjection\Compiler;
3+
namespace Tests\Aymdev\CommonmarkBundle\DependencyInjection\Compiler;
44

55
use Aymdev\CommonmarkBundle\AymdevCommonmarkBundle;
66
use Aymdev\CommonmarkBundle\DependencyInjection\AymdevCommonMarkExtension;

tests/Twig/CommonMarkExtensionTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Aymdev\CommonmarkBundle\Twig\CommonMarkExtension;
66
use League\CommonMark\MarkdownConverter;
7+
use League\CommonMark\Node\Block\Document;
8+
use League\CommonMark\Output\RenderedContent;
79
use PHPUnit\Framework\TestCase;
810
use Symfony\Component\DependencyInjection\ServiceLocator;
911

@@ -16,20 +18,25 @@ public function testFilterBasicUsage()
1618
$converterMockA = $this->getMockBuilder(MarkdownConverter::class)
1719
->disableOriginalConstructor()
1820
->getMock();
19-
$converterMockA->method('convertToHtml')->willReturn('a');
21+
$converterMockA->method('convertToHtml')
22+
->willReturn(new RenderedContent(new Document(), 'a'));
2023
return $converterMockA;
2124
},
2225
'b_conv' => function() {
2326
$converterMockB = $this->getMockBuilder(MarkdownConverter::class)
2427
->disableOriginalConstructor()
2528
->getMock();
26-
$converterMockB->method('convertToHtml')->willReturn('b');
29+
$converterMockB->method('convertToHtml')
30+
->willReturn(new RenderedContent(new Document(), 'b'));
2731
return $converterMockB;
2832
},
2933
]);
3034

3135
$extension = new CommonMarkExtension($serviceLocator);
3236

37+
$output = $extension->convertMarkdown('', 'a_conv');
38+
self::assertSame('a', $output);
39+
3340
$output = $extension->convertMarkdown('', 'b_conv');
3441
self::assertSame('b', $output);
3542
}
@@ -44,16 +51,15 @@ public function testFilterConverterNameIsOptional()
4451
$converterMock = $this->getMockBuilder(MarkdownConverter::class)
4552
->disableOriginalConstructor()
4653
->getMock();
47-
$converterMock->expects(self::once())->method('convertToHtml')->willReturnArgument(0);
54+
$converterMock->expects(self::once())->method('convertToHtml')
55+
->willReturn(new RenderedContent(new Document(), 'some markdown content'));
4856
return $converterMock;
4957
},
5058
]);
5159
$extension = new CommonMarkExtension($serviceLocator);
5260

53-
$expectedOutput = 'some markdown content';
54-
$actualOutput = $extension->convertMarkdown($expectedOutput);
55-
56-
self::assertSame($expectedOutput, $actualOutput);
61+
$actualOutput = $extension->convertMarkdown('');
62+
self::assertSame('some markdown content', $actualOutput);
5763
}
5864

5965
/**

0 commit comments

Comments
 (0)