diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index d1f4265..e27aea1 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04]
- php: [7.4]
+ php: [8.0]
steps:
- name: Checkout repository
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4232b8b..1822a43 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [2.0.0] - 2022-04-13
+
+### Added
+
+- Update to PHP 8.0 and CommonMark v2.
+
## [1.0.0] - 2022-04-13
### Added
diff --git a/README.md b/README.md
index 8b4d602..a49732d 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# YouTube iframe extension
An extension for [league/commonmark](https://github.com/thephpleague/commonmark)
-version 1 built using PHP 7.4. This replaces YouTube links with the embed iframe.
+version 2 built using PHP 8.0. This replaces YouTube links with the embed iframe.
The extension supports for the primary YouTube URL, with and without prefixed with
the `www`. It also supports the short shareable URL using the `youtu.be` domain.
@@ -21,25 +21,24 @@ composer require surface/commonmark-ext-youtube-iframe
Configure your CommonMark `Environment` and add the extension.
```php
-use League\CommonMark\CommonMarkConverter as Converter;
-// use League\CommonMark\GithubFlavoredMarkdownConverter as Converter;
-use League\CommonMark\Environment;
+use League\CommonMark\Environment\Environment;
+use League\CommonMark\MarkdownConverter as Converter;
use Surface\CommonMark\Ext\YouTubeIframe\Extension as YouTubeExtension;
-$environment = Environment::createCommonMarkEnvironment();
-$environment->addExtension(new YouTubeExtension());
-
-$config = [
+$options = [
'youtube_width' => '800',
'youtube_height' => '600',
];
-$converter = new Converter($config, $environment);
+$environment = new Environment($options);
+$environment->addExtension(new YouTubeExtension());
+
+$converter = new Converter($environment);
-echo $converter->convertToHtml('[](https://youtu.be/xxx)');
-echo $converter->convertToHtml('[](https://www.youtube.com/watch?v=xxx)');
-echo $converter->convertToHtml('[](https://youtu.be/xxx?height=480)');
-echo $converter->convertToHtml('[](https://www.youtube.com/watch?v=xxx&width=640)');
+echo $converter->convert('[](https://youtu.be/xxx)');
+echo $converter->convert('[](https://www.youtube.com/watch?v=xxx)');
+echo $converter->convert('[](https://youtu.be/xxx?height=480)');
+echo $converter->convert('[](https://www.youtube.com/watch?v=xxx&width=640)');
```
### Dimensions
diff --git a/composer.json b/composer.json
index 98f6b07..6b3d362 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "surface/commonmark-ext-youtube-iframe",
"type": "commonmark-extension",
"description": "Extension for league/commonmark to replace YouTube link with an iframe.",
- "version": "1.0.0",
+ "version": "2.0.0",
"keywords": [
"markdown",
"commonmark",
@@ -23,8 +23,8 @@
}
],
"require": {
- "php" : "^7.4|^8.0",
- "league/commonmark": "^1.6"
+ "php" : "^8.0",
+ "league/commonmark": "^2.3"
},
"require-dev": {
"phpmd/phpmd": "^2.12",
diff --git a/grumphp.yml b/grumphp.yml
index 2136cc9..faecfe9 100644
--- a/grumphp.yml
+++ b/grumphp.yml
@@ -12,7 +12,7 @@ grumphp:
with_dependencies: false
strict: false
phpversion:
- project: '7.4'
+ project: '8.0'
phpstan:
configuration: phpstan.neon
memory_limit: "2G"
diff --git a/phpcs.xml b/phpcs.xml
index 2e4b3d1..b955558 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -34,10 +34,12 @@
+
+
@@ -67,8 +69,4 @@
/tests/TestCase.php
-
-
- /tests/Unit/Url/ParserTest.php
-
diff --git a/phpstan.neon b/phpstan.neon
index 839b42d..2778c32 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -11,10 +11,6 @@ parameters:
- src
- tests
ignoreErrors:
- -
- message: "#^Parameter \\#2 \\$attributes of class League\\\\CommonMark\\\\HtmlElement constructor expects array\\, array\\ given\\.$#"
- count: 1
- path: src/Renderer.php
-
message: "#^Cannot call method (getType|getUuid|getTimestamp|getWidth|getHeight)\\(\\) on [A-Za-z\\\\]+\\\\Url\\\\Url\\|null\\.$#"
path: tests/Unit/Url
diff --git a/src/Extension.php b/src/Extension.php
index b4ebfab..7e4aea1 100644
--- a/src/Extension.php
+++ b/src/Extension.php
@@ -2,7 +2,7 @@
namespace Surface\CommonMark\Ext\YouTubeIframe;
-use League\CommonMark\ConfigurableEnvironmentInterface;
+use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Extension\ExtensionInterface;
use Surface\CommonMark\Ext\YouTubeIframe\Iframe;
@@ -14,12 +14,11 @@
final class Extension implements ExtensionInterface
{
- /** @return void */
- public function register(ConfigurableEnvironmentInterface $environment)
+ public function register(EnvironmentBuilderInterface $environment): void
{
- $width = (int) $environment->getConfig('youtube_width', 800);
- $height = (int) $environment->getConfig('youtube_height', 600);
- $fullScreen = (bool) $environment->getConfig('youtube_allowfullscreen', true);
+ $width = $this->getWidth($environment);
+ $height = $this->getHeight($environment);
+ $fullScreen = $this->allowFullscreen($environment);
$environment
->addEventListener(DocumentParsedEvent::class, new Processor([
@@ -27,11 +26,38 @@ public function register(ConfigurableEnvironmentInterface $environment)
new Full($width, $height),
new WithoutWww($width, $height),
]))
- ->addInlineRenderer(Iframe::class, new Renderer(
+ ->addRenderer(Iframe::class, new Renderer(
$width,
$height,
$fullScreen
))
;
}
+
+ protected function getWidth(EnvironmentBuilderInterface $environment): int
+ {
+ if ($environment->getConfiguration()->exists('youtube_width')) {
+ return (int) $environment->getConfiguration()->get('youtube_width');
+ }
+
+ return 800;
+ }
+
+ protected function getHeight(EnvironmentBuilderInterface $environment): int
+ {
+ if ($environment->getConfiguration()->exists('youtube_height')) {
+ return (int) $environment->getConfiguration()->get('youtube_height');
+ }
+
+ return 600;
+ }
+
+ protected function allowFullscreen(EnvironmentBuilderInterface $environment): bool
+ {
+ if ($environment->getConfiguration()->exists('youtube_allowfullscreen')) {
+ return (bool) $environment->getConfiguration()->get('youtube_allowfullscreen');
+ }
+
+ return true;
+ }
}
diff --git a/src/Iframe.php b/src/Iframe.php
index 7332ffe..554932e 100644
--- a/src/Iframe.php
+++ b/src/Iframe.php
@@ -2,14 +2,12 @@
namespace Surface\CommonMark\Ext\YouTubeIframe;
-use League\CommonMark\Inline\Element\AbstractInline;
+use League\CommonMark\Node\Inline\AbstractInline;
use Surface\CommonMark\Ext\YouTubeIframe\Url\Contracts\Url;
final class Iframe extends AbstractInline
{
- protected Url $url;
-
- public function __construct(Url $url)
+ public function __construct(protected Url $url)
{
$this->url = $url;
}
diff --git a/src/Processor.php b/src/Processor.php
index ea7b775..f306db9 100644
--- a/src/Processor.php
+++ b/src/Processor.php
@@ -3,16 +3,14 @@
namespace Surface\CommonMark\Ext\YouTubeIframe;
use League\CommonMark\Event\DocumentParsedEvent;
-use League\CommonMark\Inline\Element\Link;
+use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
use Surface\CommonMark\Ext\YouTubeIframe\Iframe;
use Surface\CommonMark\Ext\YouTubeIframe\Url\Contracts\Parser;
use TypeError;
final class Processor
{
- protected array $parsers;
-
- public function __construct(array $parsers)
+ public function __construct(protected array $parsers)
{
foreach ($parsers as $parser) {
if (! ($parser instanceof Parser)) {
@@ -43,14 +41,6 @@ public function __invoke(DocumentParsedEvent $event): void
$walker = $event->getDocument()->walker();
while ($item = $walker->next()) {
- if (! ($item->getNode() instanceof Link)) {
- continue;
- }
-
- if ($item->isEntering()) {
- continue;
- }
-
$link = $item->getNode();
if (! ($link instanceof Link)) {
diff --git a/src/Renderer.php b/src/Renderer.php
index 6ef65c7..e0fa82c 100644
--- a/src/Renderer.php
+++ b/src/Renderer.php
@@ -3,31 +3,24 @@
namespace Surface\CommonMark\Ext\YouTubeIframe;
use InvalidArgumentException;
-use League\CommonMark\ElementRendererInterface;
-use League\CommonMark\HtmlElement;
-use League\CommonMark\Inline\Element\AbstractInline;
-use League\CommonMark\Inline\Renderer\InlineRendererInterface;
+use League\CommonMark\Node\Node;
+use League\CommonMark\Renderer\ChildNodeRendererInterface;
+use League\CommonMark\Renderer\NodeRendererInterface;
+use League\CommonMark\Util\HtmlElement;
use Surface\CommonMark\Ext\YouTubeIframe\Iframe;
-final class Renderer implements InlineRendererInterface
+final class Renderer implements NodeRendererInterface
{
- protected int $height;
- protected int $width;
- protected bool $allowFullScreen;
-
- public function __construct(int $width, int $height, bool $allowFullScreen = false)
+ public function __construct(protected int $width, protected int $height, protected bool $allowFullScreen = false)
{
- $this->width = $width;
- $this->height = $height;
- $this->allowFullScreen = $allowFullScreen;
}
- /** @return \League\CommonMark\HtmlElement|string|null */
+ /** @return \League\CommonMark\Util\HtmlElement|string|null */
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
- public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
+ public function render(Node $inline, ChildNodeRendererInterface $htmlRenderer)
{
if (! ($inline instanceof Iframe)) {
- throw new InvalidArgumentException('Incompatible inline type: ' . get_class($inline));
+ throw new InvalidArgumentException('Incompatible inline type: ' . $inline::class);
}
$src = "https://www.youtube.com/embed/{$inline->getUrl()->getUuid()}";
@@ -40,10 +33,10 @@ public function render(AbstractInline $inline, ElementRendererInterface $htmlRen
}
return new HtmlElement('iframe', [
- 'width' => $width ?: $this->width,
- 'height' => $height ?: $this->height,
+ 'width' => (string) ($width ?: $this->width),
+ 'height' => (string) ($height ?: $this->height),
'src' => $src,
- 'frameborder' => 0,
+ 'frameborder' => '0',
'allowfullscreen' => $this->allowFullScreen,
'allow' => 'autoplay; fullscreen; picture-in-picture',
]);
diff --git a/src/Url/Parser.php b/src/Url/Parser.php
index a5cb618..d9ddf20 100644
--- a/src/Url/Parser.php
+++ b/src/Url/Parser.php
@@ -9,16 +9,12 @@ abstract class Parser implements Contract
{
protected string $host = '';
protected string $type;
- protected int $defaultWidth;
- protected int $defaultHeight;
abstract protected function getUuid(string $url): ?string;
- public function __construct(int $defaultWidth = 800, int $defaultHeight = 600)
+ public function __construct(protected int $defaultWidth = 800, protected int $defaultHeight = 600)
{
$this->setType();
- $this->defaultWidth = $defaultWidth;
- $this->defaultHeight = $defaultHeight;
}
public function parse(string $url): ?Url
diff --git a/src/Url/Url.php b/src/Url/Url.php
index c15234d..45fbf64 100644
--- a/src/Url/Url.php
+++ b/src/Url/Url.php
@@ -6,19 +6,13 @@
final class Url implements Contract
{
- protected string $type;
- protected string $uuid;
- protected ?int $width;
- protected ?int $height;
- protected ?int $timestamp;
-
- public function __construct(string $type, string $uuid, ?int $width, ?int $height, ?int $timestamp)
- {
- $this->type = $type;
- $this->uuid = $uuid;
- $this->width = $width;
- $this->height = $height;
- $this->timestamp = $timestamp;
+ public function __construct(
+ protected string $type,
+ protected string $uuid,
+ protected ?int $width,
+ protected ?int $height,
+ protected ?int $timestamp
+ ) {
}
public function getType(): string
diff --git a/tests/Integration/FullTest.php b/tests/Integration/FullTest.php
index 5ff878b..8416fa2 100644
--- a/tests/Integration/FullTest.php
+++ b/tests/Integration/FullTest.php
@@ -2,9 +2,6 @@
namespace Surface\CommonMark\Ext\YouTubeIframe\Tests\Integration;
-use League\CommonMark\CommonMarkConverter;
-use League\CommonMark\Environment;
-use Surface\CommonMark\Ext\YouTubeIframe\Extension;
use Surface\CommonMark\Ext\YouTubeIframe\Tests\TestCase;
/** @group full */
@@ -20,11 +17,7 @@ public function urlConversion(): void
{
$markdown = "[]({$this->url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl), $html);
}
@@ -36,11 +29,7 @@ public function urlConversionWithTimestamp(): void
$embedUrl = "{$this->embedUrl}?start=10";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($embedUrl), $html);
}
@@ -51,11 +40,7 @@ public function urlConversionWithWidth(): void
$url = "{$this->url}&width=640";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 640, 600), $html);
}
@@ -66,11 +51,7 @@ public function urlConversionWithHeight(): void
$url = "{$this->url}&height=480";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 800, 480), $html);
}
@@ -81,11 +62,7 @@ public function urlConversionWithWidthAndHeight(): void
$url = "{$this->url}&width=640&height=480";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 640, 480), $html);
}
@@ -97,17 +74,15 @@ public function urlConversionWithWidthAndHeightTimestamp(): void
$embedUrl = "{$this->embedUrl}?start=15";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($embedUrl, 640, 480), $html);
}
protected function setUp(): void
{
+ parent::setUp();
+
$this->uuid = uniqid();
$this->url = "https://www.youtube.com/watch?v={$this->uuid}";
$this->embedUrl = "https://www.youtube.com/embed/{$this->uuid}";
diff --git a/tests/Integration/ShortTest.php b/tests/Integration/ShortTest.php
index 96815e6..e06813e 100644
--- a/tests/Integration/ShortTest.php
+++ b/tests/Integration/ShortTest.php
@@ -2,12 +2,9 @@
namespace Surface\CommonMark\Ext\YouTubeIframe\Tests\Integration;
-use League\CommonMark\CommonMarkConverter;
-use League\CommonMark\Environment;
-use Surface\CommonMark\Ext\YouTubeIframe\Extension;
use Surface\CommonMark\Ext\YouTubeIframe\Tests\TestCase;
-/** @group full */
+/** @group short */
final class ShortTest extends TestCase
{
protected string $type;
@@ -20,11 +17,7 @@ public function urlConversion(): void
{
$markdown = "[]({$this->url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl), $html);
}
@@ -36,11 +29,7 @@ public function urlConversionWithTimestamp(): void
$embedUrl = "{$this->embedUrl}?start=10";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($embedUrl), $html);
}
@@ -51,11 +40,7 @@ public function urlConversionWithWidth(): void
$url = "{$this->url}?width=640";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 640, 600), $html);
}
@@ -66,11 +51,7 @@ public function urlConversionWithHeight(): void
$url = "{$this->url}?height=480";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 800, 480), $html);
}
@@ -81,11 +62,7 @@ public function urlConversionWithWidthAndHeight(): void
$url = "{$this->url}?width=640&height=480";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 640, 480), $html);
}
@@ -97,17 +74,15 @@ public function urlConversionWithWidthAndHeightTimestamp(): void
$embedUrl = "{$this->embedUrl}?start=15";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($embedUrl, 640, 480), $html);
}
protected function setUp(): void
{
+ parent::setUp();
+
$this->uuid = uniqid();
$this->url = "https://youtu.be/{$this->uuid}";
$this->embedUrl = "https://www.youtube.com/embed/{$this->uuid}";
diff --git a/tests/Integration/WithoutWwwTest.php b/tests/Integration/WithoutWwwTest.php
index 26882bc..3a04aa1 100644
--- a/tests/Integration/WithoutWwwTest.php
+++ b/tests/Integration/WithoutWwwTest.php
@@ -2,9 +2,6 @@
namespace Surface\CommonMark\Ext\YouTubeIframe\Tests\Integration;
-use League\CommonMark\CommonMarkConverter;
-use League\CommonMark\Environment;
-use Surface\CommonMark\Ext\YouTubeIframe\Extension;
use Surface\CommonMark\Ext\YouTubeIframe\Tests\TestCase;
/** @group without-www */
@@ -20,11 +17,7 @@ public function urlConversion(): void
{
$markdown = "[]({$this->url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl), $html);
}
@@ -36,11 +29,7 @@ public function urlConversionWithTimestamp(): void
$embedUrl = "{$this->embedUrl}?start=10";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($embedUrl), $html);
}
@@ -51,11 +40,7 @@ public function urlConversionWithWidth(): void
$url = "{$this->url}&width=640";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 640, 600), $html);
}
@@ -66,11 +51,7 @@ public function urlConversionWithHeight(): void
$url = "{$this->url}&height=480";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 800, 480), $html);
}
@@ -81,11 +62,7 @@ public function urlConversionWithWidthAndHeight(): void
$url = "{$this->url}&width=640&height=480";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($this->embedUrl, 640, 480), $html);
}
@@ -97,17 +74,15 @@ public function urlConversionWithWidthAndHeightTimestamp(): void
$embedUrl = "{$this->embedUrl}?start=15";
$markdown = "[]({$url})";
- $environment = Environment::createCommonMarkEnvironment();
- $environment->addExtension(new Extension());
- $converter = new CommonMarkConverter([], $environment);
-
- $html = $converter->convertToHtml($markdown);
+ $html = $this->converter->convert($markdown);
$this->assertStringContainsString($this->getHtml($embedUrl, 640, 480), $html);
}
protected function setUp(): void
{
+ parent::setUp();
+
$this->uuid = uniqid();
$this->url = "https://youtube.com/watch?v={$this->uuid}";
$this->embedUrl = "https://www.youtube.com/embed/{$this->uuid}";
diff --git a/tests/TestCase.php b/tests/TestCase.php
index e778a79..dc67fcf 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,10 +2,16 @@
namespace Surface\CommonMark\Ext\YouTubeIframe\Tests;
+use League\CommonMark\Environment\Environment;
+use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
+use League\CommonMark\MarkdownConverter;
use PHPUnit\Framework\TestCase as BaseTestCase;
+use Surface\CommonMark\Ext\YouTubeIframe\Extension;
abstract class TestCase extends BaseTestCase
{
+ protected MarkdownConverter $converter;
+
public function widthProvider(): iterable
{
return [
@@ -35,6 +41,15 @@ public function timestampProvider(): iterable
protected function getHtml(string $url, int $width = 800, int $height = 600): string
{
- return '';
+ return '';
+ }
+
+ protected function setUp(): void
+ {
+ $environment = new Environment();
+ $environment->addExtension(new CommonMarkCoreExtension());
+ $environment->addExtension(new Extension());
+
+ $this->converter = new MarkdownConverter($environment);
}
}
diff --git a/tests/Unit/Url/ParserTest.php b/tests/Unit/Url/ParserTest.php
index aee9f8a..d3b3712 100644
--- a/tests/Unit/Url/ParserTest.php
+++ b/tests/Unit/Url/ParserTest.php
@@ -42,10 +42,8 @@ public function urlWithoutWidth(): void
/**
* @test
* @dataProvider widthProvider
- * @param int|string $width
- * @param int|string|null $same
*/
- public function urlWithWidth($width, $same): void
+ public function urlWithWidth(int|string $width, int|string|null $same): void
{
$uuid = uniqid();
$url = "https://example.com/example/{$uuid}?width={$width}";
@@ -73,10 +71,8 @@ public function urlWithoutHeight(): void
/**
* @test
* @dataProvider heightProvider
- * @param int|string $height
- * @param int|string|null $same
*/
- public function urlWithHeight($height, $same): void
+ public function urlWithHeight(int|string $height, int|string|null $same): void
{
$uuid = uniqid();
$url = "https://example.com/example/{$uuid}?height={$height}";
@@ -104,10 +100,8 @@ public function urlWithoutTimestamp(): void
/**
* @test
* @dataProvider timestampProvider
- * @param int|string $timestamp
- * @param int|string|null $same
*/
- public function urlWithTimestamp($timestamp, $same): void
+ public function urlWithTimestamp(int|string $timestamp, int|string|null $same): void
{
$uuid = uniqid();
$url = "https://example.com/example/{$uuid}?t={$timestamp}";
@@ -124,10 +118,9 @@ protected function setUp(): void
$this->parser = $this->getMockForAbstractClass(Parser::class, [], 'Example');
}
- /** @return mixed */
- protected function invokeMethod(object $object, string $methodName, array $parameters = [])
+ protected function invokeMethod(object $object, string $methodName, array $parameters = []): mixed
{
- $reflection = new ReflectionClass(get_class($object));
+ $reflection = new ReflectionClass($object::class);
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);