Skip to content

Commit 5b338e7

Browse files
Merge branch '2.8'
* 2.8: Fix undefined array $server Fix call to undefined function json_last_error_message Fix bug in windows detection [ProxyManager] Tmp fix composer reqs issue in ZF Fix PropertyInfo extractor namespace in framework bundle Add missing exclusions from phpunit.xml.dist [Serializer] ObjectNormalizer: don't serialize static methods and props [Form] Enhance some FormRegistry deprecation messages [Validator] [sl] BIC (SWIFT-BIC) validation constraint [WebProfilerBundle] correct typo in show stack trace link bumped Symfony version to 2.8.0 updated VERSION for 2.8.0-BETA1 updated CHANGELOG for 2.8.0-BETA1 Fix the server variables in the router_*.php files [Validator] Allow an empty path with a non empty fragment or a query The following change adds support for Armenian pluralization. [2.3][Process] fix Proccess run with pts enabled Conflicts: src/Symfony/Bridge/ProxyManager/composer.json src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php src/Symfony/Component/Form/FormRegistry.php
2 parents ae1ecdc + 9505516 commit 5b338e7

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

Encoder/JsonDecode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function decode($data, $format, array $context = array())
8888
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
8989

9090
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
91-
throw new UnexpectedValueException(json_last_error_message());
91+
throw new UnexpectedValueException(json_last_error_msg());
9292
}
9393

9494
return $decodedData;

Encoder/JsonEncode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function encode($data, $format, array $context = array())
4040
$encodedJson = json_encode($data, $context['json_encode_options']);
4141

4242
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
43-
throw new UnexpectedValueException(json_last_error_message());
43+
throw new UnexpectedValueException(json_last_error_msg());
4444
}
4545

4646
return $encodedJson;

Normalizer/ObjectNormalizer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function normalize($object, $format = null, array $context = array())
6868
$reflClass = new \ReflectionClass($object);
6969
foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) {
7070
if (
71+
!$reflMethod->isStatic() &&
7172
!$reflMethod->isConstructor() &&
7273
!$reflMethod->isDestructor() &&
7374
0 === $reflMethod->getNumberOfRequiredParameters()
@@ -86,7 +87,9 @@ public function normalize($object, $format = null, array $context = array())
8687

8788
// properties
8889
foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflProperty) {
89-
$attributes[$reflProperty->getName()] = true;
90+
if (!$reflProperty->isStatic()) {
91+
$attributes[$reflProperty->getName()] = true;
92+
}
9093
}
9194

9295
$attributes = array_keys($attributes);

Tests/Encoder/JsonDecodeTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Encoder;
13+
14+
use Symfony\Component\Serializer\Encoder\JsonDecode;
15+
16+
class JsonDecodeTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/** @var \Symfony\Component\Serializer\Encoder\JsonDecode */
19+
private $decoder;
20+
21+
protected function setUp()
22+
{
23+
$this->decoder = new JsonDecode(true);
24+
}
25+
26+
public function testDecodeWithValidData()
27+
{
28+
$json = json_encode(array(
29+
'hello' => 'world',
30+
));
31+
$result = $this->decoder->decode($json, 'json');
32+
$this->assertEquals(array(
33+
'hello' => 'world',
34+
), $result);
35+
}
36+
37+
/**
38+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
39+
*/
40+
public function testDecodeWithInvalidData()
41+
{
42+
$result = $this->decoder->decode('kaboom!', 'json');
43+
}
44+
}

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ public function testNoTraversableSupport()
428428
{
429429
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
430430
}
431+
432+
public function testNormalizeStatic()
433+
{
434+
$this->assertEquals(array('foo' => 'K'), $this->normalizer->normalize(new ObjectWithStaticPropertiesAndMethods()));
435+
}
431436
}
432437

433438
class ObjectDummy
@@ -577,3 +582,14 @@ public function otherMethod()
577582
throw new \RuntimeException('Dummy::otherMethod() should not be called');
578583
}
579584
}
585+
586+
class ObjectWithStaticPropertiesAndMethods
587+
{
588+
public $foo = 'K';
589+
public static $bar = 'A';
590+
591+
public static function getBaz()
592+
{
593+
return 'L';
594+
}
595+
}

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<whitelist>
2121
<directory>./</directory>
2222
<exclude>
23-
<directory>./vendor</directory>
2423
<directory>./Tests</directory>
24+
<directory>./vendor</directory>
2525
</exclude>
2626
</whitelist>
2727
</filter>

0 commit comments

Comments
 (0)