From bd6dd03718f9a70c64ae177ac981511d6e30b560 Mon Sep 17 00:00:00 2001 From: Joe Lambert Date: Fri, 25 Apr 2025 17:20:11 +0100 Subject: [PATCH 1/3] Upgrade to Twig 3 --- .github/workflows/ci.yml | 2 +- composer.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3598348..4239750 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php_version: ["8.0", "8.1", "8.2"] + php_version: ["8.1", "8.2", "8.3", "8.4"] composer_flags: ["", "--prefer-lowest"] steps: diff --git a/composer.json b/composer.json index bd99416..b00f718 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { "name": "rareloop/primer-core", "require": { - "php": ">=8.0", + "php": ">=8.1", "symfony/finder": "^4.2.5||^5.0||^6.0", - "twig/twig": "^2.6", + "twig/twig": "^3.0", "illuminate/collections": "^8.53.1||^9.0.0", "league/commonmark": "^1.5", "spatie/yaml-front-matter": "^2.0" @@ -26,4 +26,4 @@ "Rareloop\\Primer\\Test\\": "tests" } } -} \ No newline at end of file +} From 937302ce7315045006df2998220483b4605e7934 Mon Sep 17 00:00:00 2001 From: Joe Lambert Date: Fri, 25 Apr 2025 17:35:19 +0100 Subject: [PATCH 2/3] Fix failing tests --- src/Twig/PrimerLoader.php | 6 +++--- tests/DocumentParsers/TwigDocumentParserTest.php | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Twig/PrimerLoader.php b/src/Twig/PrimerLoader.php index 80cb924..9f865aa 100644 --- a/src/Twig/PrimerLoader.php +++ b/src/Twig/PrimerLoader.php @@ -23,7 +23,7 @@ public function __construct(TemplateProvider $templateProvider) * * @throws \Twig\Error\LoaderError When $name is not found */ - public function getSourceContext($name) + public function getSourceContext(string $name): \Twig\Source { return new \Twig\Source($this->templateProvider->getPatternTemplate($name), $name); } @@ -37,7 +37,7 @@ public function getSourceContext($name) * * @throws \Twig\Error\LoaderError When $name is not found */ - public function getCacheKey($name) + public function getCacheKey(string $name): string { return md5($name); } @@ -52,7 +52,7 @@ public function getCacheKey($name) * * @throws \Twig\Error\LoaderError When $name is not found */ - public function isFresh($name, $time) + public function isFresh(string $name, int $time): bool { return $time < $this->templateProvider->getPatternTemplateLastModified($name); } diff --git a/tests/DocumentParsers/TwigDocumentParserTest.php b/tests/DocumentParsers/TwigDocumentParserTest.php index 9240ef3..6193c5b 100644 --- a/tests/DocumentParsers/TwigDocumentParserTest.php +++ b/tests/DocumentParsers/TwigDocumentParserTest.php @@ -3,11 +3,13 @@ namespace Rareloop\Primer\Test\DataParsers; use Mockery; -use PHPUnit\Framework\TestCase; +use Twig\Environment; use Rareloop\Primer\Document; +use PHPUnit\Framework\TestCase; use Rareloop\Primer\DocumentParsers\TwigDocumentParser; use Rareloop\Primer\DocumentParsers\YAMLDocumentParser; -use Twig\Environment; +use Twig\Template; +use Twig\TemplateWrapper; class TwigDocumentParserTest extends TestCase { @@ -17,11 +19,13 @@ public function can_parse_twig_from_content() $doc = new Document('id', 'Twig Input'); $doc->setMeta(['foo' => 'bar']); + $twig = Mockery::mock(Environment::class); $template = Mockery::mock(Template::class); + $templateWrapper = new TemplateWrapper($twig, $template); + $template->shouldReceive('render')->with($doc->meta())->once()->andReturn('Twig Output'); - $twig = Mockery::mock(Environment::class); - $twig->shouldReceive('createTemplate')->with('Twig Input')->once()->andReturn($template); + $twig->shouldReceive('createTemplate')->with('Twig Input')->once()->andReturn($templateWrapper); $parser = new TwigDocumentParser($twig); From bee67ae97aaf8ce9cd0241994464c94018792aa0 Mon Sep 17 00:00:00 2001 From: Joe Lambert Date: Fri, 25 Apr 2025 17:37:32 +0100 Subject: [PATCH 3/3] Bump dev dependencies --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index b00f718..0f07717 100644 --- a/composer.json +++ b/composer.json @@ -2,19 +2,19 @@ "name": "rareloop/primer-core", "require": { "php": ">=8.1", - "symfony/finder": "^4.2.5||^5.0||^6.0", - "twig/twig": "^3.0", - "illuminate/collections": "^8.53.1||^9.0.0", - "league/commonmark": "^1.5", - "spatie/yaml-front-matter": "^2.0" + "symfony/finder": "^6.4.17", + "twig/twig": "^3.20", + "illuminate/collections": "^8.53.1||^9.52.16", + "league/commonmark": "^1.6.7", + "spatie/yaml-front-matter": "^2.1" }, "require-dev": { - "phpunit/phpunit": "^9.0", - "php-coveralls/php-coveralls": "^2.0", - "mockery/mockery": "^1.4.4", - "squizlabs/php_codesniffer": "^3.6.0", - "mikey179/vfsstream": "^1.6.9", - "antecedent/patchwork": "^2.1.8" + "phpunit/phpunit": "^9.6.22", + "php-coveralls/php-coveralls": "^2.7", + "mockery/mockery": "^1.6.12", + "squizlabs/php_codesniffer": "^3.12.2", + "mikey179/vfsstream": "^1.6.12", + "antecedent/patchwork": "^2.2.1" }, "autoload": { "psr-4": {