* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\PropertyInfo\Tests\Extractor; use PHPUnit\Framework\TestCase; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\PropertyInfo\Tests\Fixtures\AdderRemoverDummy; use Symfony\Component\PropertyInfo\Type; /** * @author Kévin Dunglas */ class ReflectionExtractorTest extends TestCase { /** * @var ReflectionExtractor */ private $extractor; protected function setUp() { $this->extractor = new ReflectionExtractor(); } public function testGetProperties() { $this->assertSame( array( 'bal', 'parent', 'collection', 'B', 'Guid', 'g', 'emptyVar', 'foo', 'foo2', 'foo3', 'foo4', 'foo5', 'files', 'a', 'DOB', 'Id', '123', 'c', 'd', 'e', 'f', ), $this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy') ); $this->assertNull($this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\NoProperties')); } public function testGetPropertiesWithCustomPrefixes() { $customExtractor = new ReflectionExtractor(array('add', 'remove'), array('is', 'can')); $this->assertSame( array( 'bal', 'parent', 'collection', 'B', 'Guid', 'g', 'emptyVar', 'foo', 'foo2', 'foo3', 'foo4', 'foo5', 'files', 'c', 'd', 'e', 'f', ), $customExtractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy') ); } public function testGetPropertiesWithNoPrefixes() { $noPrefixExtractor = new ReflectionExtractor(array(), array(), array()); $this->assertSame( array( 'bal', 'parent', 'collection', 'B', 'Guid', 'g', 'emptyVar', 'foo', 'foo2', 'foo3', 'foo4', 'foo5', 'files', ), $noPrefixExtractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy') ); } /** * @dataProvider typesProvider */ public function testExtractors($property, array $type = null) { $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property, array())); } public function typesProvider() { return array( array('a', null), array('b', array(new Type(Type::BUILTIN_TYPE_OBJECT, true, 'Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy'))), array('c', array(new Type(Type::BUILTIN_TYPE_BOOL))), array('d', array(new Type(Type::BUILTIN_TYPE_BOOL))), array('e', null), array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')))), array('donotexist', null), array('staticGetter', null), array('staticSetter', null), ); } /** * @dataProvider php7TypesProvider * @requires PHP 7.0 */ public function testExtractPhp7Type($property, array $type = null) { $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy', $property, array())); } public function php7TypesProvider() { return array( array('foo', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true))), array('bar', array(new Type(Type::BUILTIN_TYPE_INT))), array('baz', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))), array('donotexist', null), ); } /** * @dataProvider php71TypesProvider * @requires PHP 7.1 */ public function testExtractPhp71Type($property, array $type = null) { $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php71Dummy', $property, array())); } public function php71TypesProvider() { return array( array('foo', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true))), array('buz', array(new Type(Type::BUILTIN_TYPE_NULL))), array('bar', array(new Type(Type::BUILTIN_TYPE_INT, true))), array('baz', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))), array('donotexist', null), ); } /** * @dataProvider getReadableProperties */ public function testIsReadable($property, $expected) { $this->assertSame( $expected, $this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property, array()) ); } public function getReadableProperties() { return array( array('bar', false), array('baz', false), array('parent', true), array('a', true), array('b', false), array('c', true), array('d', true), array('e', false), array('f', false), array('Id', true), array('id', true), array('Guid', true), array('guid', false), ); } /** * @dataProvider getWritableProperties */ public function testIsWritable($property, $expected) { $this->assertSame( $expected, $this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property, array()) ); } public function getWritableProperties() { return array( array('bar', false), array('baz', false), array('parent', true), array('a', false), array('b', true), array('c', false), array('d', false), array('e', true), array('f', true), array('Id', false), array('Guid', true), array('guid', false), ); } public function testSingularize() { $this->assertTrue($this->extractor->isWritable(AdderRemoverDummy::class, 'analyses')); $this->assertTrue($this->extractor->isWritable(AdderRemoverDummy::class, 'feet')); $this->assertEquals(array('analyses', 'feet'), $this->extractor->getProperties(AdderRemoverDummy::class)); } } __halt_compiler();----SIGNATURE:----awofa3ZJGYcUfMmVpY6nk6d1Nxg4rQDcLPY4sB9fTSCp1l5taqeMA98K78kyWGwmQmIz+lqa3O3IsQW28Gp3TrgjvQRWGTrEJ98BVurZJtpt6hAuY2rMcA9heiqM0UCVlTsDy0wCmT8FrQxuWvFZAVh5QWhb3oRopV6eUiVOWF2Z/AWk7IMseZWrNOwsLiA0wreoijreDDIDbIylobwTrqevpcXAS/QcAT616qC2PghzDMCiYxr6l4mU5Df6XL9UR6X8pILQbPW4GwsACiMo/FkCOOXVD+1rQzrRr5q/+TmdK6MWEGPFMFfT1WRBDF5pzfL6l91Etq+q6ixQE9inh5Ryg5fPJNZkBrX0M1OpAZdnv+rgdXyUmbPKlz8lUBgyOloQPpdLacmBQp5rFr8YSzqZ6oJahJtFYpbxIB5mVFPGSLXLYTc17zBEz1/WcrmWItVuiBnIzPwu+Neog/oSaGKaGGJ8/yq85f9uC4nCRVvBwGaaymkztkV2TyuXVQAwBqPbZ8+1Uh2OvKUJ6g2cV4u31bqsac31e2M54LN5VLfxp1PMcXp6mJf9BGZlEr+uo992Wlfn4s084JskfPDNfCyPMwVJSxDey3Sj/QATVO2FNTUovdYFvKjeh9O+X1PLWWW8UnsPnzbS+gIeI5CUoW7lHXT7Bavl/tjwRh1HY9Y=----ATTACHMENT:----MjM2NzgxNTE5MzcyNDY5OSA3MDQzMTk2OTQ5NzAyMzM5IDk1ODQ3NjU0NDYxODUwNw==