Skip to content

Commit fd97102

Browse files
committed
Fixes various tests
1 parent 9701450 commit fd97102

16 files changed

+190
-86
lines changed

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
102102
new Reference('ux.live_component.component_hydrator'),
103103
])
104104
->addTag('kernel.event_subscriber');
105-
;
106105

107106
$container->register('ux.live_component.reset_deterministic_id_subscriber', ResetDeterministicIdSubscriber::class)
108107
->setArguments([
109108
new Reference('ux.live_component.deterministic_id_calculator'),
110109
new Reference('ux.twig_component.component_stack'),
111110
])
112111
->addTag('kernel.event_subscriber');
113-
;
114112

115113
$container->register('ux.live_component.twig.component_extension', LiveComponentTwigExtension::class)
116114
->addTag('twig.extension')

src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
use Symfony\UX\LiveComponent\DehydratedComponent;
2020
use Symfony\UX\LiveComponent\LiveComponentHydrator;
2121
use Symfony\UX\LiveComponent\Twig\DeterministicTwigIdCalculator;
22-
use Symfony\UX\LiveComponent\Util\TwigAttributeHelper;
2322
use Symfony\UX\LiveComponent\Util\FingerprintCalculator;
23+
use Symfony\UX\LiveComponent\Util\TwigAttributeHelper;
2424
use Symfony\UX\TwigComponent\ComponentAttributes;
2525
use Symfony\UX\TwigComponent\ComponentMetadata;
2626
use Symfony\UX\TwigComponent\ComponentStack;
2727
use Symfony\UX\TwigComponent\Event\PreRenderEvent;
2828
use Symfony\UX\TwigComponent\MountedComponent;
29-
use Twig\Environment;
3029

3130
/**
3231
* @author Kevin Bond <[email protected]>

src/LiveComponent/src/EventListener/InterceptChildComponentRenderSubscriber.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* @author Ryan Weaver <[email protected]>
2727
*
2828
* @experimental
29+
*
2930
* @internal
3031
*/
3132
class InterceptChildComponentRenderSubscriber implements EventSubscriberInterface
@@ -39,17 +40,17 @@ public function __construct(
3940
private TwigAttributeHelper $twigAttributeHelper,
4041
private ComponentFactory $componentFactory,
4142
private LiveComponentHydrator $liveComponentHydrator,
42-
)
43-
{
43+
) {
4444
}
4545

4646
public function preComponentCreated(PreCreateForRenderEvent $event): void
4747
{
48-
if (!$this->componentStack->hasParentComponent()) {
48+
// if there is already a component, that's a parent. Else, this is not a child.
49+
if (!$this->componentStack->getCurrentComponent()) {
4950
return;
5051
}
5152

52-
$parentComponent = $this->componentStack->getParentComponent();
53+
$parentComponent = $this->componentStack->getCurrentComponent();
5354
if (!$parentComponent->hasExtraMetadata(self::CHILDREN_FINGERPRINTS_METADATA_KEY)) {
5455
return;
5556
}
@@ -66,7 +67,7 @@ public function preComponentCreated(PreCreateForRenderEvent $event): void
6667
// increment the internal counter now to keep "counter" consistency if we're
6768
// in a loop of children being rendered on the same line
6869
// we need to do this because this component will *not* ever hit
69-
// AddLiveAttributesSubscriber where the counter is normally incrememented
70+
// AddLiveAttributesSubscriber where the counter is normally incremented
7071
$this->deterministicTwigIdCalculator->calculateDeterministicId(increment: true);
7172

7273
$newPropsFingerprint = $this->fingerprintCalculator->calculateFingerprint($event->getProps());
@@ -106,7 +107,7 @@ public function preComponentCreated(PreCreateForRenderEvent $event): void
106107
public static function getSubscribedEvents(): array
107108
{
108109
return [
109-
PreCreateForRenderEvent::class => 'preComponentCreated'
110+
PreCreateForRenderEvent::class => 'preComponentCreated',
110111
];
111112
}
112113
}

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private static function parseDataFor(Request $request): array
219219
'data' => $requestData['data'] ?? [],
220220
'args' => $requestData['args'] ?? [],
221221
'actions' => $requestData['actions'] ?? [],
222-
'childrenFingerprints' => $requestData['childrenFingerprints'] ?? []
222+
'childrenFingerprints' => $requestData['childrenFingerprints'] ?? [],
223223
];
224224
}
225225

@@ -318,7 +318,7 @@ private function isLiveComponentRequest(Request $request): bool
318318
private function hydrateComponent(object $component, string $componentName, Request $request): MountedComponent
319319
{
320320
$hydrator = $this->container->get(LiveComponentHydrator::class);
321-
assert($hydrator instanceof LiveComponentHydrator);
321+
\assert($hydrator instanceof LiveComponentHydrator);
322322

323323
$mountedComponent = $hydrator->hydrate(
324324
$component,

src/LiveComponent/src/EventListener/ResetDeterministicIdSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
* @author Ryan Weaver <[email protected]>
3838
*
3939
* @experimental
40+
*
4041
* @internal
4142
*/
4243
final class ResetDeterministicIdSubscriber implements EventSubscriberInterface
4344
{
4445
public function __construct(
4546
private DeterministicTwigIdCalculator $idCalculator,
4647
private ComponentStack $componentStack
47-
)
48-
{
48+
) {
4949
}
5050

5151
public function onPostRender(): void

src/LiveComponent/src/Twig/DeterministicTwigIdCalculator.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function reset(): void
6666
}
6767

6868
/**
69-
* Adapted from Twig\Error\Error::guessTemplateInfo()
69+
* Adapted from Twig\Error\Error::guessTemplateInfo().
7070
*
7171
* Any differences are marked below.
7272
*
@@ -84,10 +84,10 @@ private function guessTemplateInfo(): array
8484
$isEmbedContainer = null === $templateClass ? false : 0 === strpos($templateClass, $currentClass);
8585
// START CHANGE
8686
// if statement not needed
87-
//if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
88-
$template = $trace['object'];
89-
//$templateClass = \get_class($trace['object']);
90-
//}
87+
// if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
88+
$template = $trace['object'];
89+
// $templateClass = \get_class($trace['object']);
90+
// }
9191
// END CHANGE
9292

9393
// START CHANGE
@@ -100,9 +100,9 @@ private function guessTemplateInfo(): array
100100
// update template name
101101
// START CHANGE
102102
// don't check name poroperty
103-
//if (null !== $template && null === $this->name) {
103+
// if (null !== $template && null === $this->name) {
104104
if (null !== $template) {
105-
// END CHANGE
105+
// END CHANGE
106106
// START CHANGE
107107
// set local variable
108108
$name = $template->getTemplateName();
@@ -121,22 +121,22 @@ private function guessTemplateInfo(): array
121121
*/
122122

123123
// START CHANGE
124-
//if (null === $template || $this->lineno > -1) {
124+
// if (null === $template || $this->lineno > -1) {
125125
// remove lineno property check
126126
if (null === $template) {
127-
// END CHANGE
127+
// END CHANGE
128128
// START CHANGE
129129
// throw exception instead
130130
throw new \LogicException('Could not determine template while generating deterministic id.');
131-
//return;
131+
// return;
132132
//
133133
}
134134

135135
$r = new \ReflectionObject($template);
136136
$file = $r->getFileName();
137137

138138
// START CHANGE
139-
//$exceptions = [$e = $this];
139+
// $exceptions = [$e = $this];
140140
$exceptions = [new Error('')];
141141
// not other exceptions to check
142142
/*
@@ -164,7 +164,7 @@ private function guessTemplateInfo(): array
164164

165165
// return the values
166166
return ['name' => $name, 'line' => $lineno];
167-
//return;
167+
// return;
168168
// END CHANGE
169169
}
170170
}

src/LiveComponent/tests/Fixtures/Component/TodoListComponent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class TodoListComponent
2121
#[LiveProp(writable: true)]
2222
public string $name = '';
2323

24+
#[LiveProp]
2425
public array $items = [];
2526

2627
use DefaultActionTrait;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<li{{ attributes }}>
2-
Child Component! {{ text }}
2+
todo item: {{ text }}
33
</li>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ include('deterministic_id.html.twig') }}

src/LiveComponent/tests/Functional/Controller/BatchActionControllerTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\UX\LiveComponent\Tests\Functional\Controller;
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15+
use Symfony\Component\DomCrawler\Crawler;
1516
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper;
1617
use Zenstruck\Browser\KernelBrowser;
17-
use Zenstruck\Browser\Response\HtmlResponse;
1818
use Zenstruck\Browser\Test\HasBrowser;
1919

2020
/**
@@ -34,8 +34,8 @@ public function testCanBatchActions(): void
3434
->get('/_components/with_actions', ['json' => ['data' => $dehydrated]])
3535
->assertSuccessful()
3636
->assertSee('initial')
37-
->use(function (HtmlResponse $response, KernelBrowser $browser) {
38-
$rootElement = $response->crawler()->filter('ul')->first();
37+
->use(function (Crawler $crawler, KernelBrowser $browser) {
38+
$rootElement = $crawler->filter('ul')->first();
3939
$liveData = json_decode($rootElement->attr('data-live-data-value'), true);
4040
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
4141

@@ -44,13 +44,13 @@ public function testCanBatchActions(): void
4444
'data' => $liveData + $liveProps,
4545
'args' => ['what' => 'first'],
4646
],
47-
'headers' => ['X-CSRF-TOKEN' => $response->crawler()->filter('ul')->first()->attr('data-live-csrf-value')],
47+
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
4848
]);
4949
})
5050
->assertSee('initial')
5151
->assertSee('first')
52-
->use(function (HtmlResponse $response, KernelBrowser $browser) {
53-
$rootElement = $response->crawler()->filter('ul')->first();
52+
->use(function (Crawler $crawler, KernelBrowser $browser) {
53+
$rootElement = $crawler->filter('ul')->first();
5454
$liveData = json_decode($rootElement->attr('data-live-data-value'), true);
5555
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
5656

@@ -63,7 +63,7 @@ public function testCanBatchActions(): void
6363
['name' => 'add', 'args' => ['what' => 'fourth']],
6464
],
6565
],
66-
'headers' => ['X-CSRF-TOKEN' => $response->crawler()->filter('ul')->first()->attr('data-live-csrf-value')],
66+
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
6767
]);
6868
})
6969
->assertSee('initial')
@@ -96,8 +96,8 @@ public function testRedirect(): void
9696
->get('/_components/with_actions', ['json' => ['data' => $dehydrated]])
9797
->assertSuccessful()
9898
->interceptRedirects()
99-
->use(function (HtmlResponse $response, KernelBrowser $browser) {
100-
$rootElement = $response->crawler()->filter('ul')->first();
99+
->use(function (Crawler $crawler, KernelBrowser $browser) {
100+
$rootElement = $crawler->filter('ul')->first();
101101
$liveData = json_decode($rootElement->attr('data-live-data-value'), true);
102102
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
103103

@@ -110,7 +110,7 @@ public function testRedirect(): void
110110
['name' => 'add', 'args' => ['what' => 'fourth']],
111111
],
112112
],
113-
'headers' => ['X-CSRF-TOKEN' => $response->crawler()->filter('ul')->first()->attr('data-live-csrf-value')],
113+
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
114114
]);
115115
})
116116
->assertRedirectedTo('/')
@@ -124,8 +124,8 @@ public function testException(): void
124124
$this->browser()
125125
->get('/_components/with_actions', ['json' => ['data' => $dehydrated]])
126126
->assertSuccessful()
127-
->use(function (HtmlResponse $response, KernelBrowser $browser) {
128-
$rootElement = $response->crawler()->filter('ul')->first();
127+
->use(function (Crawler $crawler, KernelBrowser $browser) {
128+
$rootElement = $crawler->filter('ul')->first();
129129
$liveData = json_decode($rootElement->attr('data-live-data-value'), true);
130130
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
131131

@@ -138,7 +138,7 @@ public function testException(): void
138138
['name' => 'add', 'args' => ['what' => 'fourth']],
139139
],
140140
],
141-
'headers' => ['X-CSRF-TOKEN' => $response->crawler()->filter('ul')->first()->attr('data-live-csrf-value')],
141+
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
142142
]);
143143
})
144144
->assertStatus(500)
@@ -153,8 +153,8 @@ public function testCannotBatchWithNonLiveAction(): void
153153
$this->browser()
154154
->get('/_components/with_actions', ['json' => ['data' => $dehydrated]])
155155
->assertSuccessful()
156-
->use(function (HtmlResponse $response, KernelBrowser $browser) {
157-
$rootElement = $response->crawler()->filter('ul')->first();
156+
->use(function (Crawler $crawler, KernelBrowser $browser) {
157+
$rootElement = $crawler->filter('ul')->first();
158158
$liveData = json_decode($rootElement->attr('data-live-data-value'), true);
159159
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
160160

@@ -167,7 +167,7 @@ public function testCannotBatchWithNonLiveAction(): void
167167
['name' => 'add', 'args' => ['what' => 'fourth']],
168168
],
169169
],
170-
'headers' => ['X-CSRF-TOKEN' => $response->crawler()->filter('ul')->first()->attr('data-live-csrf-value')],
170+
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
171171
]);
172172
})
173173
->assertStatus(404)

0 commit comments

Comments
 (0)