Skip to content

Commit 68bffdf

Browse files
authored
Upgrade to Twig 3 (#11)
* Upgrade to Twig 3 * Fix failing tests * Bump dev dependencies
1 parent d3d4208 commit 68bffdf

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
php_version: ["8.0", "8.1", "8.2"]
10+
php_version: ["8.1", "8.2", "8.3", "8.4"]
1111
composer_flags: ["", "--prefer-lowest"]
1212

1313
steps:

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"name": "rareloop/primer-core",
33
"require": {
4-
"php": ">=8.0",
5-
"symfony/finder": "^4.2.5||^5.0||^6.0",
6-
"twig/twig": "^2.6",
7-
"illuminate/collections": "^8.53.1||^9.0.0",
8-
"league/commonmark": "^1.5",
9-
"spatie/yaml-front-matter": "^2.0"
4+
"php": ">=8.1",
5+
"symfony/finder": "^6.4.17",
6+
"twig/twig": "^3.20",
7+
"illuminate/collections": "^8.53.1||^9.52.16",
8+
"league/commonmark": "^1.6.7",
9+
"spatie/yaml-front-matter": "^2.1"
1010
},
1111
"require-dev": {
12-
"phpunit/phpunit": "^9.0",
13-
"php-coveralls/php-coveralls": "^2.0",
14-
"mockery/mockery": "^1.4.4",
15-
"squizlabs/php_codesniffer": "^3.6.0",
16-
"mikey179/vfsstream": "^1.6.9",
17-
"antecedent/patchwork": "^2.1.8"
12+
"phpunit/phpunit": "^9.6.22",
13+
"php-coveralls/php-coveralls": "^2.7",
14+
"mockery/mockery": "^1.6.12",
15+
"squizlabs/php_codesniffer": "^3.12.2",
16+
"mikey179/vfsstream": "^1.6.12",
17+
"antecedent/patchwork": "^2.2.1"
1818
},
1919
"autoload": {
2020
"psr-4": {
@@ -26,4 +26,4 @@
2626
"Rareloop\\Primer\\Test\\": "tests"
2727
}
2828
}
29-
}
29+
}

src/Twig/PrimerLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(TemplateProvider $templateProvider)
2323
*
2424
* @throws \Twig\Error\LoaderError When $name is not found
2525
*/
26-
public function getSourceContext($name)
26+
public function getSourceContext(string $name): \Twig\Source
2727
{
2828
return new \Twig\Source($this->templateProvider->getPatternTemplate($name), $name);
2929
}
@@ -37,7 +37,7 @@ public function getSourceContext($name)
3737
*
3838
* @throws \Twig\Error\LoaderError When $name is not found
3939
*/
40-
public function getCacheKey($name)
40+
public function getCacheKey(string $name): string
4141
{
4242
return md5($name);
4343
}
@@ -52,7 +52,7 @@ public function getCacheKey($name)
5252
*
5353
* @throws \Twig\Error\LoaderError When $name is not found
5454
*/
55-
public function isFresh($name, $time)
55+
public function isFresh(string $name, int $time): bool
5656
{
5757
return $time < $this->templateProvider->getPatternTemplateLastModified($name);
5858
}

tests/DocumentParsers/TwigDocumentParserTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace Rareloop\Primer\Test\DataParsers;
44

55
use Mockery;
6-
use PHPUnit\Framework\TestCase;
6+
use Twig\Environment;
77
use Rareloop\Primer\Document;
8+
use PHPUnit\Framework\TestCase;
89
use Rareloop\Primer\DocumentParsers\TwigDocumentParser;
910
use Rareloop\Primer\DocumentParsers\YAMLDocumentParser;
10-
use Twig\Environment;
11+
use Twig\Template;
12+
use Twig\TemplateWrapper;
1113

1214
class TwigDocumentParserTest extends TestCase
1315
{
@@ -17,11 +19,13 @@ public function can_parse_twig_from_content()
1719
$doc = new Document('id', 'Twig Input');
1820
$doc->setMeta(['foo' => 'bar']);
1921

22+
$twig = Mockery::mock(Environment::class);
2023
$template = Mockery::mock(Template::class);
24+
$templateWrapper = new TemplateWrapper($twig, $template);
25+
2126
$template->shouldReceive('render')->with($doc->meta())->once()->andReturn('Twig Output');
2227

23-
$twig = Mockery::mock(Environment::class);
24-
$twig->shouldReceive('createTemplate')->with('Twig Input')->once()->andReturn($template);
28+
$twig->shouldReceive('createTemplate')->with('Twig Input')->once()->andReturn($templateWrapper);
2529

2630
$parser = new TwigDocumentParser($twig);
2731

0 commit comments

Comments
 (0)