Skip to content

Commit

Permalink
bug #19437 [PropertyInfo] Fix an error in PropertyInfoCacheExtractor …
Browse files Browse the repository at this point in the history
…(Ener-Getick)

This PR was squashed before being merged into the 3.1 branch (closes #19437).

Discussion
----------

[PropertyInfo] Fix an error in PropertyInfoCacheExtractor

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

An argument was forgotten in the ``PropertyInfoCacheExtractor`` class leading to exceptions such as
```
PHP Warning:  ucfirst() expects parameter 1 to be string, array given in /home/guilhem/github/ast-test/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php on line 318
```
and making it unusable.

ping @dunglas

Commits
-------

d19b151 [PropertyInfo] Fix an error in PropertyInfoCacheExtractor
  • Loading branch information
fabpot committed Aug 15, 2016
2 parents 9784301 + d19b151 commit ac528c7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getProperties($class, array $context = array())
*/
public function getTypes($class, $property, array $context = array())
{
return $this->extract('getTypes', array($class, $context));
return $this->extract('getTypes', array($class, $property, $context));
}

/**
Expand All @@ -108,7 +108,7 @@ private function extract($method, array $arguments)

$key = $this->escape($method.'.'.$serializedArguments);

if (isset($this->arrayCache[$key])) {
if (array_key_exists($key, $this->arrayCache)) {
return $this->arrayCache[$key];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,58 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
*/
public function getShortDescription($class, $property, array $context = array())
{
$this->assertIsString($class);
$this->assertIsString($property);
}

/**
* {@inheritdoc}
*/
public function getLongDescription($class, $property, array $context = array())
{
$this->assertIsString($class);
$this->assertIsString($property);
}

/**
* {@inheritdoc}
*/
public function getTypes($class, $property, array $context = array())
{
$this->assertIsString($class);
$this->assertIsString($property);
}

/**
* {@inheritdoc}
*/
public function isReadable($class, $property, array $context = array())
{
$this->assertIsString($class);
$this->assertIsString($property);
}

/**
* {@inheritdoc}
*/
public function isWritable($class, $property, array $context = array())
{
$this->assertIsString($class);
$this->assertIsString($property);
}

/**
* {@inheritdoc}
*/
public function getProperties($class, array $context = array())
{
$this->assertIsString($class);
}

private function assertIsString($string)
{
if (!is_string($string)) {
throw new \InvalidArgumentException(sprintf('"%s" expects strings, given "%s".', __CLASS__, gettype($string)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,40 @@ protected function setUp()
$this->propertyInfo = new PropertyInfoCacheExtractor($this->propertyInfo, new ArrayAdapter());
}

public function testCache()
public function testGetShortDescription()
{
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array()));
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array()));
parent::testGetShortDescription();
parent::testGetShortDescription();
}

public function testNotSerializableContext()
public function testGetLongDescription()
{
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array('foo' => function () {})));
parent::testGetLongDescription();
parent::testGetLongDescription();
}

public function testGetTypes()
{
parent::testGetTypes();
parent::testGetTypes();
}

public function testIsReadable()
{
parent::testIsReadable();
parent::testIsReadable();
}

public function testIsWritable()
{
parent::testIsWritable();
parent::testIsWritable();
}

public function testGetProperties()
{
parent::testGetProperties();
parent::testGetProperties();
}

/**
Expand Down

0 comments on commit ac528c7

Please sign in to comment.