Skip to content

Commit 0474c6c

Browse files
wip #33
1 parent 1a18875 commit 0474c6c

File tree

11 files changed

+53
-60
lines changed

11 files changed

+53
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
2+
cache/*
23
.php_cs
34
.php_cs.cache
45
.phpunit.result.cache

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
],
1818
"require": {
1919
"php": "^7.4|^8.0",
20-
"twig/twig": "^3.0"
20+
"twig/twig": "^3.21"
2121
},
2222
"require-dev": {
23-
"friendsofphp/php-cs-fixer": "^3.0",
24-
"pestphp/pest": "^1.0",
25-
"phpunit/phpunit": "^9.3",
26-
"symfony/var-dumper": "^5.2",
27-
"vimeo/psalm": "^3.11"
23+
"friendsofphp/php-cs-fixer": "^3.75",
24+
"pestphp/pest": "^3.8",
25+
"symfony/var-dumper": "^7.2",
26+
"vimeo/psalm": "^6.10"
2827
},
2928
"autoload": {
3029
"psr-4": {

phpunit.xml.dist

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
verbose="true"
126
>
137
<testsuites>
14-
<testsuite name="Digital Test Suite">
8+
<testsuite name="Arch">
159
<directory>tests</directory>
1610
</testsuite>
1711
</testsuites>
18-
<coverage>
12+
<source>
1913
<include>
20-
<directory suffix=".php">./src</directory>
14+
<directory>src</directory>
2115
</include>
22-
<report>
23-
<html outputDirectory="build/coverage"/>
24-
<text outputFile="build/coverage.txt"/>
25-
<clover outputFile="build/logs/clover.xml"/>
26-
</report>
27-
</coverage>
28-
<logging>
29-
<junit outputFile="build/report.junit.xml"/>
30-
</logging>
16+
<exclude>
17+
<directory>vendor</directory>
18+
</exclude>
19+
</source>
3120
</phpunit>

src/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public function setup()
157157
$this->twig->setLexer(new ComponentLexer($this->twig));
158158
}
159159

160-
/** @var \Twig\Extension\EscaperExtension */
161-
$escaper = $this->twig->getExtension(\Twig\Extension\EscaperExtension::class);
160+
/** @var \Twig\Runtime\EscaperRuntime */
161+
$escaper = $this->twig->getRuntime(\Twig\Runtime\EscaperRuntime::class);
162162
$escaper->addSafeClass(ComponentAttributeBag::class, ['all']);
163163
$escaper->addSafeClass(ComponentSlot::class, ['all']);
164164
}

src/Node/ComponentNode.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,12 @@ protected function addGetTemplate(Compiler $compiler)
6161
$repr = $this->isDynamicComponent() ? 'raw' : 'repr';
6262

6363
$compiler
64-
->raw('$this->loadTemplate(' . PHP_EOL)
64+
->raw('$this->load(' . PHP_EOL)
6565
->indent(1)
6666
->write('')
6767
->$repr($this->getTemplateName())
6868
->raw(', ' . PHP_EOL)
6969
->write('')
70-
->$repr($this->getTemplateName())
71-
->raw(', ' . PHP_EOL)
72-
->write('')
7370
->repr($this->getTemplateLine())
7471
->indent(-1)
7572
->raw(PHP_EOL . ');' . PHP_EOL . PHP_EOL);

src/Node/SlotNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class SlotNode extends Node implements NodeOutputInterface
1313
{
1414
public function __construct($name, $body, ?AbstractExpression $variables, int $lineno = 0)
1515
{
16-
parent::__construct(['body' => $body], ['name' => $name], $lineno, null);
16+
parent::__construct(['body' => $body], ['name' => $name], $lineno);
1717

1818
if ($variables) {
1919
$this->setNode('variables', $variables);

src/TokenParser/ComponentTokenParser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function parseArguments()
6666
}
6767

6868
if ($stream->nextIf(/* Token::NAME_TYPE */5, 'with')) {
69-
$variables = $this->parser->getExpressionParser()->parseExpression();
69+
$variables = $this->parser->parseExpression();
7070
}
7171

7272
$stream->expect(/* Token::BLOCK_END_TYPE */3);
@@ -80,9 +80,9 @@ public function parseComponentName(): string
8080

8181
$path = [];
8282

83-
if ($this->parser->getCurrentToken()->getType() != /** Token::NAME_TYPE */ 5) {
84-
throw new Exception('First token must be a name type');
85-
}
83+
// if ($this->parser->getCurrentToken()->getType() !== Token::NAME_TYPE) {
84+
// throw new Exception('First token must be a name type');
85+
// }
8686

8787
$name = $this->getNameSection();
8888

@@ -93,7 +93,7 @@ public function parseComponentName(): string
9393

9494
$path[] = $name;
9595

96-
while ($stream->nextIf(9 /** Token::PUNCTUATION_TYPE */, '.')) {
96+
while ($stream->nextIf(8 /** Token::PUNCTUATION_TYPE */, '.')) {
9797
$path[] = $this->getNameSection();
9898
}
9999

src/TokenParser/SlotTokenParser.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function parseArguments(): array
3333
}
3434

3535
if ($stream->nextIf(/* Token::NAME_TYPE */5, 'with')) {
36-
$variables = $this->parser->getExpressionParser()->parseExpression();
36+
$variables = $this->parser->parseExpression();
3737
}
3838

3939
$stream->expect(/* Token::BLOCK_END_TYPE */3);
@@ -45,9 +45,10 @@ public function parseSlotName(): string
4545
{
4646
$stream = $this->parser->getStream();
4747

48-
if ($this->parser->getCurrentToken()->getType() != /** Token::NAME_TYPE */ 5) {
49-
throw new Exception('First token must be a name type');
50-
}
48+
//$stream->expect(5);
49+
// if ($this->parser->getCurrentToken()->getType() != /** Token::NAME_TYPE */ 5) {
50+
// throw new Exception('First token must be a name type');
51+
// }
5152

5253
return $stream->next()->getValue();
5354
}

tests/ComponentTokenParserTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use Performing\TwigComponents\Configuration;
66
use Performing\TwigComponents\TokenParser\ComponentTokenParser;
7+
use PHPUnit\Framework\Attributes\Test;
78
use PHPUnit\Framework\TestCase;
89

910
class ComponentTokenParserTest extends TestCase
1011
{
12+
#[Test]
1113
public function testGetComponentPathWithHintPath()
1214
{
1315
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates');
@@ -27,6 +29,7 @@ public function testGetComponentPathWithHintPath()
2729
$this->assertEquals('mynamespace.myplugin::components.test.component', $componentPath);
2830
}
2931

32+
#[Test]
3033
public function testGetComponentPathWithoutHintPath()
3134
{
3235
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates');

tests/ComponentsTestTrait.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Performing\TwigComponents\Tests;
44

5+
use PHPUnit\Framework\Attributes\Test;
6+
57
trait ComponentsTestTrait
68
{
7-
/** @test */
9+
#[Test]
810
public function render_simple_component()
911
{
1012
$html = $this->twig->render('test_simple_component.twig');
@@ -14,7 +16,7 @@ public function render_simple_component()
1416
HTML, $html);
1517
}
1618

17-
/** @test */
19+
#[Test]
1820
public function render_simple_component_with_dash()
1921
{
2022
$html = $this->twig->render('test_simple_component_with_dash.twig');
@@ -24,7 +26,7 @@ public function render_simple_component_with_dash()
2426
HTML, $html);
2527
}
2628

27-
/** @test */
29+
#[Test]
2830
public function render_simple_component_in_folder()
2931
{
3032
$html = $this->twig->render('test_simple_component_in_folder.twig');
@@ -34,7 +36,7 @@ public function render_simple_component_in_folder()
3436
HTML, $html);
3537
}
3638

37-
/** @test */
39+
#[Test]
3840
public function render_component_with_slots()
3941
{
4042
$html = $this->twig->render('test_with_slots.twig');
@@ -44,7 +46,7 @@ public function render_component_with_slots()
4446
HTML, $html);
4547
}
4648

47-
/** @test */
49+
#[Test]
4850
public function render_xtags_with_slots()
4951
{
5052
$html = $this->twig->render('test_xtags_with_slots.twig');
@@ -54,7 +56,7 @@ public function render_xtags_with_slots()
5456
HTML, $html);
5557
}
5658

57-
/** @test */
59+
#[Test]
5860
public function render_nested_xtags_with_slots()
5961
{
6062
$html = $this->twig->render('test_nested_xtags_with_slots.twig');
@@ -64,7 +66,7 @@ public function render_nested_xtags_with_slots()
6466
HTML, $html);
6567
}
6668

67-
/** @test */
69+
#[Test]
6870
public function render_deeply_nested_xtags_with_slots()
6971
{
7072
$html = $this->twig->render('test_deeply_nested_xtags_with_slots.twig');
@@ -75,7 +77,7 @@ public function render_deeply_nested_xtags_with_slots()
7577
HTML, $html);
7678
}
7779

78-
/** @test */
80+
#[Test]
7981
public function render_component_with_xtags()
8082
{
8183
$html = $this->twig->render('test_xtags_component.twig');
@@ -87,7 +89,7 @@ public function render_component_with_xtags()
8789
HTML, $html);
8890
}
8991

90-
/** @test */
92+
#[Test]
9193
public function render_component_with_attributes()
9294
{
9395
$html = $this->twig->render('test_with_attributes.twig');
@@ -101,7 +103,7 @@ public function render_component_with_attributes()
101103
HTML, $html);
102104
}
103105

104-
/** @test */
106+
#[Test]
105107
public function render_namespaced_component()
106108
{
107109
$html = $this->twig->render('test_namespaced_component.twig');
@@ -111,7 +113,7 @@ public function render_namespaced_component()
111113
HTML, $html);
112114
}
113115

114-
/** @test */
116+
#[Test]
115117
public function render_namespaced_xtags_component()
116118
{
117119
$html = $this->twig->render('test_namespaced_xtags_component.twig');
@@ -123,7 +125,7 @@ public function render_namespaced_xtags_component()
123125
HTML, $html);
124126
}
125127

126-
/** @test */
128+
#[Test]
127129
public function test_class_merge_works_with_components_in_components()
128130
{
129131
$template = $this->twig->createTemplate(<<<HTML
@@ -134,7 +136,7 @@ public function test_class_merge_works_with_components_in_components()
134136
$this->assertEquals('<button class="mb-5 bg-red-500 text-white">Click me</button>', $html);
135137
}
136138

137-
/** @test */
139+
#[Test]
138140
public function test_attributes_dont_conflict_with_components_in_components()
139141
{
140142
$template = $this->twig->createTemplate(<<<HTML
@@ -145,7 +147,7 @@ public function test_attributes_dont_conflict_with_components_in_components()
145147
$this->assertEquals('<div class="mb-5 bg-red-500"><button class="text-white">Click me</button></div>', $html);
146148
}
147149

148-
/** @test */
150+
#[Test]
149151
public function render_simple_dynamic_component()
150152
{
151153
$html = $this->twig->render('test_simple_dynamic_component.twig');
@@ -156,7 +158,7 @@ public function render_simple_dynamic_component()
156158
HTML, $html);
157159
}
158160

159-
/** @test */
161+
#[Test]
160162
public function render_dynamic_component_with_xtags()
161163
{
162164
$html = $this->twig->render('test_xtags_dynamic_component.twig');
@@ -168,7 +170,7 @@ public function render_dynamic_component_with_xtags()
168170
HTML, $html);
169171
}
170172

171-
/** @test */
173+
#[Test]
172174
public function render_namespaced_dynamic_component()
173175
{
174176
$html = $this->twig->render('test_namespaced_dynamic_component.twig');
@@ -178,7 +180,7 @@ public function render_namespaced_dynamic_component()
178180
HTML, $html);
179181
}
180182

181-
/** @test */
183+
#[Test]
182184
public function render_namespaced_xtags_dynamic_component()
183185
{
184186
$html = $this->twig->render('test_namespaced_xtags_dynamic_component.twig');

0 commit comments

Comments
 (0)