Skip to content

Commit 21af89f

Browse files
committed
Rename props in tests to be more explicit
1 parent 4532537 commit 21af89f

File tree

7 files changed

+101
-75
lines changed

7 files changed

+101
-75
lines changed

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

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,59 @@ class ComponentWithUrlBoundProps
2323
use DefaultActionTrait;
2424

2525
#[LiveProp(url: true)]
26-
public ?string $prop1 = null;
26+
public ?string $stringProp = null;
2727

2828
#[LiveProp(url: true)]
29-
public ?int $prop2 = null;
29+
public ?int $intProp = null;
3030

3131
#[LiveProp(url: true)]
32-
public array $prop3 = [];
32+
public array $arrayProp = [];
3333

3434
#[LiveProp]
35-
public ?string $prop4 = null;
35+
public ?string $unboundProp = null;
3636

3737
#[LiveProp(url: true)]
38-
public ?Address $prop5 = null;
38+
public ?Address $objectProp = null;
3939

40-
#[LiveProp(fieldName: 'field6', url: true)]
41-
public ?string $prop6 = null;
40+
#[LiveProp(fieldName: 'field1', url: true)]
41+
public ?string $propWithField1 = null;
4242

43-
#[LiveProp(fieldName: 'getProp7Name()', url: true)]
44-
public ?string $prop7 = null;
43+
#[LiveProp(fieldName: 'getField2()', url: true)]
44+
public ?string $propWithField2 = null;
4545

46-
#[LiveProp(modifier: 'modifyProp8')]
47-
public ?string $prop8 = null;
46+
#[LiveProp(modifier: 'modifyMaybeBoundProp')]
47+
public ?string $maybeBoundProp = null;
4848

4949
#[LiveProp]
50-
public ?bool $prop8InUrl = false;
50+
public ?bool $maybeBoundPropInUrl = false;
5151

52-
public function getProp7Name(): string
52+
public function getField2(): string
5353
{
54-
return 'field7';
54+
return 'field2';
5555
}
5656

57-
public function modifyProp8(LiveProp $prop): LiveProp
57+
public function modifyMaybeBoundProp(LiveProp $prop): LiveProp
5858
{
59-
return $prop->withUrl($this->prop8InUrl);
59+
return $prop->withUrl($this->maybeBoundPropInUrl);
6060
}
6161

62-
#[LiveProp(url: new UrlMapping('q'))]
63-
public ?string $prop9 = null;
62+
#[LiveProp(url: new UrlMapping(as: 'q'))]
63+
public ?string $boundPropWithAlias = null;
64+
65+
#[LiveProp(url: true, modifier: 'modifyBoundPropWithCustomAlias')]
66+
public ?string $boundPropWithCustomAlias = null;
67+
68+
#[LiveProp]
69+
public ?string $customAlias = null;
70+
71+
public function modifyBoundPropWithCustomAlias(LiveProp $liveProp): LiveProp
72+
{
73+
if ($this->customAlias) {
74+
$liveProp = $liveProp->withUrl(new UrlMapping(as: $this->customAlias));
75+
}
76+
77+
return $liveProp;
78+
}
79+
80+
6481
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<div {{ attributes }}>
2-
Prop1: {{ prop1 }}
3-
Prop2: {{ prop2 }}
4-
Prop3: {{ prop3|join(',') }}
5-
Prop4: {{ prop4 }}
6-
Prop5: address: {{ prop5.address ?? '' }} city: {{ prop5.city ?? '' }}
7-
Prop6: {{ prop6 }}
8-
Prop7: {{ prop7 }}
9-
Prop8: {{ prop8 }}
10-
Prop9: {{ prop9 }}
2+
StringProp: {{ stringProp }}
3+
IntProp: {{ intProp }}
4+
ArrayProp: {{ arrayProp|join(',') }}
5+
UnboundProp: {{ unboundProp }}
6+
ObjectProp: address: {{ objectProp.address ?? '' }} city: {{ objectProp.city ?? '' }}
7+
PropWithField1: {{ propWithField1 }}
8+
PropWithField2: {{ propWithField2 }}
9+
MaybeBoundProp: {{ maybeBoundProp }}
10+
BoundPropWithAlias: {{ boundPropWithAlias }}
11+
BoundPropWithCustomAlias: {{ boundPropWithCustomAlias }}
1112
</div>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{{ component('component_with_url_bound_props', {
2-
prop8InUrl: true
2+
maybeBoundPropInUrl: true,
3+
customAlias: 'customAlias',
34
}) }}

src/LiveComponent/tests/Functional/EventListener/AddLiveAttributesSubscriberTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ public function testQueryStringMappingAttribute()
146146

147147
$queryMapping = json_decode($div->attr('data-live-query-mapping-value'), true);
148148
$expected = [
149-
'prop1' => ['name' => 'prop1'],
150-
'prop2' => ['name' => 'prop2'],
151-
'prop3' => ['name' => 'prop3'],
152-
'prop5' => ['name' => 'prop5'],
153-
'field6' => ['name' => 'field6'],
154-
'field7' => ['name' => 'field7'],
155-
'prop8' => ['name' => 'prop8'],
156-
'prop9' => ['name' => 'q'],
149+
'stringProp' => ['name' => 'stringProp'],
150+
'intProp' => ['name' => 'intProp'],
151+
'arrayProp' => ['name' => 'arrayProp'],
152+
'objectProp' => ['name' => 'objectProp'],
153+
'field1' => ['name' => 'field1'],
154+
'field2' => ['name' => 'field2'],
155+
'maybeBoundProp' => ['name' => 'maybeBoundProp'],
156+
'boundPropWithAlias' => ['name' => 'q'],
157+
'boundPropWithCustomAlias' => ['name' => 'customAlias'],
157158
];
158159

159160
$this->assertEquals($expected, $queryMapping);

src/LiveComponent/tests/Functional/EventListener/QueryStringInitializerSubscriberTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,31 @@ class QueryStringInitializerSubscriberTest extends KernelTestCase
2020

2121
public function testQueryStringPropsInitialization()
2222
{
23+
$queryString = '?'
24+
.'stringProp=foo'
25+
.'&intProp=42'
26+
.'&arrayProp[]=foo&arrayProp[]=bar'
27+
.'&unboundProp=unbound'
28+
.'&objectProp[address]=foo&objectProp[city]=bar'
29+
.'&field1=foo'
30+
.'&field2=foo'
31+
.'&maybeBoundProp=foo'
32+
.'&q=foo'
33+
.'&customAlias=foo'
34+
;
2335
$this->browser()
24-
->get('/render-template/render_component_with_url_bound_props?prop1=foo&prop2=42&prop3[]=foo&prop3[]=bar&prop4=unbound&prop5[address]=foo&prop5[city]=bar&field6=foo&field7=foo&prop8=foo&q=foo')
36+
->get('/render-template/render_component_with_url_bound_props'.$queryString)
2537
->assertSuccessful()
26-
->assertContains('Prop1: foo')
27-
->assertContains('Prop2: 42')
28-
->assertContains('Prop3: foo,bar')
29-
->assertContains('Prop4:')
30-
->assertContains('Prop5: address: foo city: bar')
31-
->assertContains('Prop6: foo')
32-
->assertContains('Prop7: foo')
33-
->assertContains('Prop8: foo')
34-
->assertContains('Prop9: foo')
38+
->assertContains('StringProp: foo')
39+
->assertContains('IntProp: 42')
40+
->assertContains('ArrayProp: foo,bar')
41+
->assertContains('UnboundProp:')
42+
->assertContains('ObjectProp: address: foo city: bar')
43+
->assertContains('PropWithField1: foo')
44+
->assertContains('PropWithField2: foo')
45+
->assertContains('MaybeBoundProp: foo')
46+
->assertContains('BoundPropWithAlias: foo')
47+
->assertContains('BoundPropWithCustomAlias: foo')
3548
;
3649
}
3750
}

src/LiveComponent/tests/Functional/Metadata/LiveComponentMetadataFactoryTest.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ public function testQueryStringMapping()
3131
$propsMetadataByName[$propMetadata->getName()] = $propMetadata;
3232
}
3333

34-
$this->assertNotNull($propsMetadataByName['prop1']->urlMapping());
35-
36-
$this->assertNotNull($propsMetadataByName['prop2']->urlMapping());
37-
38-
$this->assertNotNull($propsMetadataByName['prop3']->urlMapping());
39-
40-
$this->assertNull($propsMetadataByName['prop4']->urlMapping());
41-
42-
$this->assertNotNull($propsMetadataByName['prop5']->urlMapping());
43-
44-
$this->assertNotNull($propsMetadataByName['prop6']->urlMapping());
45-
46-
$this->assertNotNull($propsMetadataByName['prop7']->urlMapping());
47-
48-
$this->assertNull($propsMetadataByName['prop8']->urlMapping());
49-
50-
$this->assertEquals(new UrlMapping(as: 'q'), $propsMetadataByName['prop9']->urlMapping());
34+
$this->assertNotNull($propsMetadataByName['stringProp']->urlMapping());
35+
$this->assertNotNull($propsMetadataByName['intProp']->urlMapping());
36+
$this->assertNotNull($propsMetadataByName['arrayProp']->urlMapping());
37+
$this->assertNull($propsMetadataByName['unboundProp']->urlMapping());
38+
$this->assertNotNull($propsMetadataByName['objectProp']->urlMapping());
39+
$this->assertNotNull($propsMetadataByName['propWithField1']->urlMapping());
40+
$this->assertNotNull($propsMetadataByName['propWithField2']->urlMapping());
41+
$this->assertNull($propsMetadataByName['maybeBoundProp']->urlMapping());
42+
$this->assertEquals(new UrlMapping(as: 'q'), $propsMetadataByName['boundPropWithAlias']->urlMapping());
43+
$this->assertNotNull($propsMetadataByName['boundPropWithCustomAlias']);
5144
}
5245
}

src/LiveComponent/tests/Functional/Util/QueryStringPropsExtractorTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@ public function getQueryStringTests(): iterable
4646
{
4747
yield from [
4848
'no query string' => ['', []],
49-
'empty value for nullable string' => ['prop1=', ['prop1' => null]],
50-
'string value' => ['prop1=foo', ['prop1' => 'foo']],
51-
'empty value for nullable int' => ['prop2=', ['prop2' => null]],
52-
'int value' => ['prop2=42', ['prop2' => 42]],
53-
'array value' => ['prop3[]=foo&prop3[]=bar', ['prop3' => ['foo', 'bar']]],
54-
'array value indexed' => ['prop3[1]=foo&prop3[0]=bar', ['prop3' => [1 => 'foo', 0 => 'bar']]],
55-
'not bound prop' => ['prop4=foo', []],
56-
'object value' => ['prop5[address]=foo&prop5[city]=bar', ['prop5' => (function () {
49+
'empty value for nullable string' => ['stringProp=', ['stringProp' => null]],
50+
'string value' => ['stringProp=foo', ['stringProp' => 'foo']],
51+
'empty value for nullable int' => ['intProp=', ['intProp' => null]],
52+
'int value' => ['intProp=42', ['intProp' => 42]],
53+
'array value' => ['arrayProp[]=foo&arrayProp[]=bar', ['arrayProp' => ['foo', 'bar']]],
54+
'array value indexed' => ['arrayProp[1]=foo&arrayProp[0]=bar', ['arrayProp' => [1 => 'foo', 0 => 'bar']]],
55+
'not bound prop' => ['unboundProp=foo', []],
56+
'object value' => ['objectProp[address]=foo&objectProp[city]=bar', ['objectProp' => (function () {
5757
$address = new Address();
5858
$address->address = 'foo';
5959
$address->city = 'bar';
6060

6161
return $address;
6262
})(),
6363
]],
64-
'invalid scalar value' => ['prop1[]=foo&prop1[]=bar', []],
65-
'invalid array value' => ['prop3=foo', []],
66-
'invalid object value' => ['prop5=foo', []],
67-
'aliased prop' => ['q=foo', ['prop9' => 'foo']],
64+
'invalid scalar value' => ['stringProp[]=foo&stringProp[]=bar', []],
65+
'invalid array value' => ['arrayProp=foo', []],
66+
'invalid object value' => ['objectProp=foo', []],
67+
'aliased prop' => ['q=foo', ['boundPropWithAlias' => 'foo']],
6868
];
6969
}
7070
}

0 commit comments

Comments
 (0)