|
28 | 28 | useSymfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy; |
29 | 29 | useSymfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy; |
30 | 30 | useSymfony\Component\PropertyInfo\Tests\Fixtures\SnakeCaseDummy; |
| 31 | +useSymfony\Component\PropertyInfo\Tests\Fixtures\UnderscoreDummy; |
31 | 32 | useSymfony\Component\PropertyInfo\Tests\Fixtures\VirtualProperties; |
32 | 33 | useSymfony\Component\PropertyInfo\Type; |
33 | 34 |
|
@@ -361,31 +362,31 @@ public static function defaultValueProvider() |
361 | 362 | /** |
362 | 363 | * @dataProvider getReadableProperties |
363 | 364 | */ |
364 | | -publicfunctiontestIsReadable($property,$expected) |
| 365 | +publicfunctiontestIsReadable(string$class,string$property,bool$expected) |
365 | 366 | { |
366 | | -$this->assertSame( |
367 | | -$expected, |
368 | | -$this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy',$property, []) |
369 | | - ); |
| 367 | +$this->assertSame($expected,$this->extractor->isReadable($class,$property, [])); |
370 | 368 | } |
371 | 369 |
|
372 | 370 | publicstaticfunctiongetReadableProperties() |
373 | 371 | { |
374 | 372 | return [ |
375 | | - ['bar',false], |
376 | | - ['baz',false], |
377 | | - ['parent',true], |
378 | | - ['a',true], |
379 | | - ['b',false], |
380 | | - ['c',true], |
381 | | - ['d',true], |
382 | | - ['e',false], |
383 | | - ['f',false], |
384 | | - ['Id',true], |
385 | | - ['id',true], |
386 | | - ['Guid',true], |
387 | | - ['guid',false], |
388 | | - ['element',false], |
| 373 | + [Dummy::class,'bar',false], |
| 374 | + [Dummy::class,'baz',false], |
| 375 | + [Dummy::class,'parent',true], |
| 376 | + [Dummy::class,'a',true], |
| 377 | + [Dummy::class,'b',false], |
| 378 | + [Dummy::class,'c',true], |
| 379 | + [Dummy::class,'d',true], |
| 380 | + [Dummy::class,'e',false], |
| 381 | + [Dummy::class,'f',false], |
| 382 | + [Dummy::class,'Id',true], |
| 383 | + [Dummy::class,'id',true], |
| 384 | + [Dummy::class,'Guid',true], |
| 385 | + [Dummy::class,'guid',false], |
| 386 | + [Dummy::class,'element',false], |
| 387 | + [UnderscoreDummy::class,'_',true], |
| 388 | + [UnderscoreDummy::class,'__',true], |
| 389 | + [UnderscoreDummy::class,'___',false], |
389 | 390 | ]; |
390 | 391 | } |
391 | 392 |
|
@@ -560,6 +561,10 @@ public static function readAccessorProvider(): array |
560 | 561 | [Dummy::class,'foo',true, PropertyReadInfo::TYPE_PROPERTY,'foo', PropertyReadInfo::VISIBILITY_PUBLIC,false], |
561 | 562 | [Php71Dummy::class,'foo',true, PropertyReadInfo::TYPE_METHOD,'getFoo', PropertyReadInfo::VISIBILITY_PUBLIC,false], |
562 | 563 | [Php71Dummy::class,'buz',true, PropertyReadInfo::TYPE_METHOD,'getBuz', PropertyReadInfo::VISIBILITY_PUBLIC,false], |
| 564 | + [UnderscoreDummy::class,'_',true, PropertyReadInfo::TYPE_METHOD,'get_', PropertyReadInfo::VISIBILITY_PUBLIC,false], |
| 565 | + [UnderscoreDummy::class,'__',true, PropertyReadInfo::TYPE_METHOD,'get__', PropertyReadInfo::VISIBILITY_PUBLIC,false], |
| 566 | + [UnderscoreDummy::class,'foo_bar',false,null,null,null,null],// No getter named getFoo_Bar |
| 567 | + [UnderscoreDummy::class,'_foo_',false,null,null,null,null],// No getter named get_Foo_ |
563 | 568 | ]; |
564 | 569 | } |
565 | 570 |
|
@@ -792,4 +797,32 @@ public static function provideVirtualPropertiesMutator(): iterable |
792 | 797 | yield ['virtualSetHookOnly', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PUBLIC]; |
793 | 798 | yield ['virtualHook', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PUBLIC]; |
794 | 799 | } |
| 800 | + |
| 801 | +/** |
| 802 | + * @dataProvider camelizeProvider |
| 803 | + */ |
| 804 | +publicfunctiontestCamelize(string$input,string$expected) |
| 805 | + { |
| 806 | +$reflection =new \ReflectionClass($this->extractor); |
| 807 | +$method =$reflection->getMethod('camelize'); |
| 808 | +$method->setAccessible(true); |
| 809 | + |
| 810 | +$this->assertSame($expected,$method->invoke($this->extractor,$input)); |
| 811 | + } |
| 812 | + |
| 813 | +publicstaticfunctioncamelizeProvider():iterable |
| 814 | + { |
| 815 | +yield'single underscore' => ['_','_']; |
| 816 | +yield'double underscore' => ['__','__']; |
| 817 | +yield'triple underscore' => ['___','___']; |
| 818 | + |
| 819 | +yield'snake case' => ['foo_bar','FooBar']; |
| 820 | +yield'double snake case' => ['foo__bar','FooBar']; |
| 821 | +yield'leading underscore' => ['_foo','Foo']; |
| 822 | +yield'trailing underscore' => ['foo_','Foo']; |
| 823 | +yield'leading and trailing' => ['_foo_bar_','FooBar']; |
| 824 | +yield'empty string' => ['','']; |
| 825 | +yield'no underscore' => ['fooBar','FooBar']; |
| 826 | +yield'pascal case' => ['FooBar','FooBar']; |
| 827 | + } |
795 | 828 | } |