Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac528c7

Browse files
committed
bug #19437 [PropertyInfo] Fix an error in PropertyInfoCacheExtractor (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
2 parents 9784301 + d19b151 commit ac528c7

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getProperties($class, array $context = array())
8686
*/
8787
public function getTypes($class, $property, array $context = array())
8888
{
89-
return $this->extract('getTypes', array($class, $context));
89+
return $this->extract('getTypes', array($class, $property, $context));
9090
}
9191

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

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

111-
if (isset($this->arrayCache[$key])) {
111+
if (array_key_exists($key, $this->arrayCache)) {
112112
return $this->arrayCache[$key];
113113
}
114114

src/Symfony/Component/PropertyInfo/Tests/Fixtures/NullExtractor.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,58 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
2828
*/
2929
public function getShortDescription($class, $property, array $context = array())
3030
{
31+
$this->assertIsString($class);
32+
$this->assertIsString($property);
3133
}
3234

3335
/**
3436
* {@inheritdoc}
3537
*/
3638
public function getLongDescription($class, $property, array $context = array())
3739
{
40+
$this->assertIsString($class);
41+
$this->assertIsString($property);
3842
}
3943

4044
/**
4145
* {@inheritdoc}
4246
*/
4347
public function getTypes($class, $property, array $context = array())
4448
{
49+
$this->assertIsString($class);
50+
$this->assertIsString($property);
4551
}
4652

4753
/**
4854
* {@inheritdoc}
4955
*/
5056
public function isReadable($class, $property, array $context = array())
5157
{
58+
$this->assertIsString($class);
59+
$this->assertIsString($property);
5260
}
5361

5462
/**
5563
* {@inheritdoc}
5664
*/
5765
public function isWritable($class, $property, array $context = array())
5866
{
67+
$this->assertIsString($class);
68+
$this->assertIsString($property);
5969
}
6070

6171
/**
6272
* {@inheritdoc}
6373
*/
6474
public function getProperties($class, array $context = array())
6575
{
76+
$this->assertIsString($class);
77+
}
78+
79+
private function assertIsString($string)
80+
{
81+
if (!is_string($string)) {
82+
throw new \InvalidArgumentException(sprintf('"%s" expects strings, given "%s".', __CLASS__, gettype($string)));
83+
}
6684
}
6785
}

src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,40 @@ protected function setUp()
2626
$this->propertyInfo = new PropertyInfoCacheExtractor($this->propertyInfo, new ArrayAdapter());
2727
}
2828

29-
public function testCache()
29+
public function testGetShortDescription()
3030
{
31-
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array()));
32-
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array()));
31+
parent::testGetShortDescription();
32+
parent::testGetShortDescription();
3333
}
3434

35-
public function testNotSerializableContext()
35+
public function testGetLongDescription()
3636
{
37-
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array('foo' => function () {})));
37+
parent::testGetLongDescription();
38+
parent::testGetLongDescription();
39+
}
40+
41+
public function testGetTypes()
42+
{
43+
parent::testGetTypes();
44+
parent::testGetTypes();
45+
}
46+
47+
public function testIsReadable()
48+
{
49+
parent::testIsReadable();
50+
parent::testIsReadable();
51+
}
52+
53+
public function testIsWritable()
54+
{
55+
parent::testIsWritable();
56+
parent::testIsWritable();
57+
}
58+
59+
public function testGetProperties()
60+
{
61+
parent::testGetProperties();
62+
parent::testGetProperties();
3863
}
3964

4065
/**

0 commit comments

Comments
 (0)