8000 [WIP][Serializer]Use PropertyInfo to extract properties by fbourigault · Pull Request #28775 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][Serializer]Use PropertyInfo to extract properties #28775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
[PropertyInfo] use dataProvider for ReflectionExtractor::getPropertie…
…s tests
  • Loading branch information
fbourigault committed Nov 6, 2018
commit da41bcb7cd06b885fa078664fd5b01ee238839e2
Original file line number Diff line number Diff line change
Expand Up @@ -34,161 +34,177 @@ protected function setUp()
$this->extractor = new ReflectionExtractor();
}

public function testGetProperties()
{
$this->assertSame(
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'k',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'a',
'DOB',
'Id',
'123',
'self',
'realParent',
'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',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'k',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'c',
'd',
'e',
'f',
),
$customExtractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
);
}

public function testGetPropertiesWithNoPrefixes()
/**
* @dataProvider getPropertiesProvider
*/
public function testGetProperties($class, $expected, $mutatorPrefixes, $accessorPrefixes, $arrayMutatorPrefixes, $context)
{
$noPrefixExtractor = new ReflectionExtractor(array(), array(), array());
$extractor = new ReflectionExtractor($mutatorPrefixes, $accessorPrefixes, $arrayMutatorPrefixes);

$this->assertSame(
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'k',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
),
$noPrefixExtractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
);
$this->assertSame($expected, $extractor->getProperties($class, $context));
}

public function testGetPropertiesWithoutStaticProperties()
public function getPropertiesProvider()
{
$this->assertSame(
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'a',
'DOB',
'Id',
'123',
'self',
'realParent',
'c',
'd',
'e',
'f',
),
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', array(
ReflectionExtractor::EXCLUDE_STATIC_PROPERTIES => true,
))
);

$this->assertNull($this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\NoProperties'));
return [
[
'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy',
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'k',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'a',
'DOB',
'Id',
'123',
'self',
'realParent',
'c',
'd',
'e',
'f',
),
null,
null,
null,
array(),
],
[
'Symfony\Component\PropertyInfo\Tests\Fixtures\NoProperties',
null,
null,
null,
null,
array(),
],
[
'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy',
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'k',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'c',
'd',
'e',
'f',
),
array('add', 'remove'),
array('is', 'can'),
null,
array(),
],
[
'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy',
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'k',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
),
array(),
array(),
array(),
array(),
],
[
'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy',
array(
'bal',
'parent',
'collection',
'nestedCollection',
'mixedCollection',
'B',
'Guid',
'g',
'h',
'i',
'j',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
'nestedIterators',
'foo',
'foo2',
'foo3',
'foo4',
'foo5',
'files',
'a',
'DOB',
'Id',
'123',
'self',
'realParent',
'c',
'd',
'e',
'f',
),
null,
null,
null,
array(
ReflectionExtractor::EXCLUDE_STATIC_PROPERTIES => true,
)
]
];
}

/**
Expand Down
0