10000 Speed up ObjectNormalizer by introducing ObjectPropertyAccessorInterface by fbourigault · Pull Request #29405 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Speed up ObjectNormalizer by introducing ObjectPropertyAccessorInterface #29405

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 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add PropertyAccessor::{get,set}PropertyValue tests
  • Loading branch information
fbourigault committed Jan 24, 2019
commit ff2b45016cfe826f7dbf680fda4ca8d2a6acf462
71 changes: 58 additions & 13 deletions src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function getPathsWithMissingIndex()

/**
* @dataProvider getValidPropertyPaths
* @dataProvider getValidObjectProperty
*/
public function testGetValue($objectOrArray, $path, $value)
{
Expand Down Expand Up @@ -204,6 +205,7 @@ public function testGetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $p

/**
* @dataProvider getValidPropertyPaths
* @dataProvider getValidObjectProperty
*/
public function testSetValue($objectOrArray, $path)
{
Expand Down Expand Up @@ -310,6 +312,7 @@ public function testGetValueWhenArrayValueIsNull()

/**
* @dataProvider getValidPropertyPaths
* @dataProvider getValidObjectProperty
*/
public function testIsReadable($objectOrArray, $path)
{
Expand Down Expand Up @@ -371,6 +374,7 @@ public function testIsReadableReturnsFalseIfNotObjectOrArray($objectOrArray, $pa

/**
* @dataProvider getValidPropertyPaths
* @dataProvider getValidObjectProperty
*/
public function testIsWritable($objectOrArray, $path)
{
Expand Down Expand Up @@ -430,6 +434,42 @@ public function testIsWritableReturnsFalseIfNotObjectOrArray($objectOrArray, $pa
$this->assertFalse($this->propertyAccessor->isWritable($objectOrArray, $path));
}

/**
* @dataProvider getValidObjectProperty
*/
public function testGetPropertyValue($object, $property, $value)
{
$this->assertSame($value, $this->propertyAccessor->getPropertyValue($object, $property));
}

/**
* @dataProvider getPathsWithMissingProperty
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
*/
public function testGetPropertyValueThrowsExceptionIfPropertyNotFound($object, $property)
{
$this->propertyAccessor->getPropertyValue($object, $property);
}

/**
* @dataProvider getValidObjectProperty
*/
public function testSetPropertyValue($object, $property)
{
$this->propertyAccessor->setPropertyValue($object, $property, 'Updated');

$this->assertSame('Updated', $this->propertyAccessor->getPropertyValue($object, $property));
}

/**
* @dataProvider getPathsWithMissingProperty
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
*/
public function testSetPropertyValueThrowsExceptionIfPropertyNotFound($object, $property)
{
$this->propertyAccessor->setPropertyValue($object, $property, 'Updated');
}

public function getValidPropertyPaths()
{
return [
Expand All @@ -442,19 +482,6 @@ public function getValidPropertyPaths()
[['index' => (object) ['firstName' => 'Bernhard']], '[index].firstName', 'Bernhard'],
[(object) ['property' => (object) ['firstName' => 'Bernhard']], 'property.firstName', 'Bernhard'],

// Accessor methods
[new TestClass('Bernhard'), 'publicProperty', 'Bernhard'],
[new TestClass('Bernhard'), 'publicAccessor', 'Bernhard'],
[new TestClass('Bernhard'), 'publicAccessorWithDefaultValue', 'Bernhard'],
[new TestClass('Bernhard'), 'publicAccessorWithRequiredAndDefaultValue', 'Bernhard'],
[new TestClass('Bernhard'), 'publicIsAccessor', 'Bernhard'],
[new TestClass('Bernhard'), 'publicHasAccessor', 'Bernhard'],
[new TestClass('Bernhard'), 'publicGetSetter', 'Bernhard'],

// Methods are camelized
[new TestClass('Bernhard'), 'public_accessor', 'Bernhard'],
[new TestClass('Bernhard'), '_public_accessor', 'Bernhard'],

// Missing indices
[['index' => []], '[index][firstName]', null],
[['root' => ['index' => []]], '[root][index][firstName]', null],
Expand All @@ -475,6 +502,24 @@ public function getValidPropertyPaths()
];
}

public function getValidObjectProperty()
{
return [
// Accessor methods
[new TestClass('Bernhard'), 'publicProperty', 'Bernhard'],
[new TestClass('Bernhard'), 'publicAccessor', 'Bernhard'],
[new TestClass('Bernhard'), 'publicAccessorWithDefaultValue', 'Bernhard'],
[new TestClass('Bernhard'), 'publicAccessorWithRequiredAndDefaultValue', 'Bernhard'],
[new TestClass('Bernhard'), 'publicIsAccessor', 'Bernhard'],
[new TestClass('Bernhard'), 'publicHasAccessor', 'Bernhard'],
[new TestClass('Bernhard'), 'publicGetSetter', 'Bernhard'],

// Methods are camelized
[new TestClass('Bernhard'), 'public_accessor', 'Bernhard'],
[new TestClass('Bernhard'), '_public_accessor', 'Bernhard'],
];
}

public function testTicket5755()
{
$object = new Ticket5775Object();
Expand Down
0