Merge branch '2.7' into 2.8

* 2.7:
  [Twig+FrameworkBundle] Fix forward compat with Form 2.8
  [2.6] Static Code Analysis for Components
  [Security/Http] Fix test relying on a private property
  [Serializer] Fix bugs reported in b5990be491 (commitcomment-12301266)

Conflicts:
	src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
	src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php
	src/Symfony/Component/Security/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php
This commit is contained in:
Nicolas Grekas 2015-07-24 10:37:00 +02:00
commit 415e6f658f
6 changed files with 56 additions and 11 deletions

View File

@ -101,7 +101,7 @@ class Client extends BaseClient
$r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader');
$requirePath = str_replace("'", "\\'", $r->getFileName());
$symfonyPath = str_replace("'", "\\'", realpath(__DIR__.'/../../..'));
$symfonyPath = str_replace("'", "\\'", dirname(dirname(dirname(__DIR__))));
$errorReporting = error_reporting();
$code = <<<EOF

View File

@ -178,8 +178,7 @@ echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n
$compiler = new GenrbCompiler($genrb, $genrbEnv);
$config = new GeneratorConfig($sourceDir.'/data', $icuVersionInDownload);
// Don't wrap "/data" in realpath(), in case the directory does not exist
$baseDir = realpath(__DIR__.'/..').'/data';
$baseDir = dirname(__DIR__).'/data';
//$txtDir = $baseDir.'/txt';
$jsonDir = $baseDir;

View File

@ -54,10 +54,9 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$authenticationManager
->expects($this->once())
->method('authenticate')
->with(self::logicalAnd(
$this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken'),
$this->attributeEqualTo('secret', 'TheSecret')
))
->with($this->callback(function ($token) {
return 'TheSecret' === $token->getSecret();
}))
->will($this->returnValue($anonymousToken))
;

View File

@ -291,7 +291,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
*
* @throws RuntimeException
*/
protected function instantiateObject(array $data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
{
if (
isset($context['object_to_populate']) &&

View File

@ -102,6 +102,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
$reflectionClass = new \ReflectionClass($class);
$object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes);
$classMethods = get_class_methods($object);
foreach ($normalizedData as $attribute => $value) {
if ($this->nameConverter) {
$attribute = $this->nameConverter->denormalize($attribute);
@ -113,7 +114,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
if ($allowed && !$ignored) {
$setter = 'set'.ucfirst($attribute);
if (method_exists($object, $setter)) {
if (in_array($setter, $classMethods)) {
$object->$setter($value);
}
}

View File

@ -228,6 +228,12 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar', $obj->getBar());
}
public function testConstructorWArgWithPrivateMutator()
{
$obj = $this->normalizer->denormalize(array('foo' => 'bar'), __NAMESPACE__.'\ObjectConstructorArgsWithPrivateMutatorDummy', 'any');
$this->assertEquals('bar', $obj->getFoo());
}
public function testGroupsNormalize()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
@ -511,8 +517,8 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
public function testDenormalizeNonExistingAttribute()
{
$this->assertEquals(
new PropertyDummy(),
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\PropertyDummy')
new GetSetDummy(),
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\GetSetDummy')
);
}
@ -520,6 +526,12 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
{
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
}
public function testPrivateSetter()
{
$obj = $this->normalizer->denormalize(array('foo' => 'foobar'), __NAMESPACE__.'\ObjectWithPrivateSetterDummy');
$this->assertEquals('bar', $obj->getFoo());
}
}
class GetSetDummy
@ -726,3 +738,37 @@ class GetCamelizedDummy
return $this->bar_foo;
}
}
class ObjectConstructorArgsWithPrivateMutatorDummy
{
private $foo;
public function __construct($foo)
{
$this->setFoo($foo);
}
public function getFoo()
{
return $this->foo;
}
private function setFoo($foo)
{
$this->foo = $foo;
}
}
class ObjectWithPrivateSetterDummy
{
private $foo = 'bar';
public function getFoo()
{
return $this->foo;
}
private function setFoo($foo)
{
}
}