|
28 | 28 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy; |
29 | 29 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy; |
30 | 30 | use Symfony\Component\PropertyInfo\Tests\Fixtures\SnakeCaseDummy; |
| 31 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\UnderscoreDummy; |
31 | 32 | use Symfony\Component\PropertyInfo\Tests\Fixtures\VirtualProperties; |
32 | 33 | use Symfony\Component\PropertyInfo\Type; |
33 | 34 |
|
@@ -361,31 +362,31 @@ public static function defaultValueProvider() |
361 | 362 | /** |
362 | 363 | * @dataProvider getReadableProperties |
363 | 364 | */ |
364 | | - public function testIsReadable($property, $expected) |
| 365 | + public function testIsReadable(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 | public static function getReadableProperties() |
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], |
| 567 | + [UnderscoreDummy::class, '_foo_', false, null, null, null, null], |
563 | 568 | ]; |
564 | 569 | } |
565 | 570 |
|
@@ -792,4 +797,35 @@ 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 | + public function testCamelize(string $input, string $expected) |
| 805 | + { |
| 806 | + $reflection = new \ReflectionClass($this->extractor); |
| 807 | + $method = $reflection->getMethod('camelize'); |
| 808 | + |
| 809 | + if (\PHP_VERSION_ID < 80500) { |
| 810 | + $method->setAccessible(true); |
| 811 | + } |
| 812 | + |
| 813 | + $this->assertSame($expected, $method->invoke($this->extractor, $input)); |
| 814 | + } |
| 815 | + |
| 816 | + public static function camelizeProvider(): iterable |
| 817 | + { |
| 818 | + yield 'single underscore' => ['_', '_']; |
| 819 | + yield 'double underscore' => ['__', '__']; |
| 820 | + yield 'triple underscore' => ['___', '___']; |
| 821 | + |
| 822 | + yield 'snake case' => ['foo_bar', 'FooBar']; |
| 823 | + yield 'double snake case' => ['foo__bar', 'FooBar']; |
| 824 | + yield 'leading underscore' => ['_foo', 'Foo']; |
| 825 | + yield 'trailing underscore' => ['foo_', 'Foo']; |
| 826 | + yield 'leading and trailing' => ['_foo_bar_', 'FooBar']; |
| 827 | + yield 'empty string' => ['', '']; |
| 828 | + yield 'no underscore' => ['fooBar', 'FooBar']; |
| 829 | + yield 'pascal case' => ['FooBar', 'FooBar']; |
| 830 | + } |
795 | 831 | } |
0 commit comments