diff --git a/.travis.yml b/.travis.yml index 553f5ce16..6e1d49e97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ matrix: - php: hhvm php: - - 5.3 - 5.4 - 5.5 - hhvm @@ -14,7 +13,7 @@ before_script: - composer self-update - composer install --dev -script: phpunit --coverage-clover clover +script: vendor/bin/phpunit --coverage-clover clover after_success: - wget https://scrutinizer-ci.com/ocular.phar diff --git a/composer.json b/composer.json index bfd79ddd8..61e2d0002 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "symfony/translation": "~2.0", "symfony/validator": "~2.0", "symfony/form": "~2.1", - "symfony/filesystem": "2.*" + "symfony/filesystem": "2.*", + "phpunit/phpunit": "4.1.*" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index d930625b0..46b49e834 100644 --- a/composer.lock +++ b/composer.lock @@ -1,9 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" ], - "hash": "a289e033b038f46fda0632911070eefa", + "hash": "aa1b65425075772f5e5b5332b24f3214", "packages": [ { "name": "doctrine/annotations", @@ -930,6 +931,119 @@ ], "time": "2013-12-01 11:46:25" }, + { + "name": "ocramius/instantiator", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Ocramius/Instantiator.git", + "reference": "cc754c2289ffd4483c319f6ed6ee88ce21676f64" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Ocramius/Instantiator/zipball/cc754c2289ffd4483c319f6ed6ee88ce21676f64", + "reference": "cc754c2289ffd4483c319f6ed6ee88ce21676f64", + "shasum": "" + }, + "require": { + "ocramius/lazy-map": "1.0.*", + "php": "~5.3" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/", + "role": "Developer" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/Ocramius/Instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-06-15 11:44:46" + }, + { + "name": "ocramius/lazy-map", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Ocramius/LazyMap.git", + "reference": "5c77102e225d225ae2d74d5f2cc488527834b821" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Ocramius/LazyMap/zipball/5c77102e225d225ae2d74d5f2cc488527834b821", + "reference": "5c77102e225d225ae2d74d5f2cc488527834b821", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "athletic/athletic": "~0.1.7", + "phpmd/phpmd": "1.5.*", + "phpunit/phpunit": ">=3.7", + "satooshi/php-coveralls": "~0.6", + "squizlabs/php_codesniffer": "1.4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "LazyMap\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.io/", + "role": "Developer" + } + ], + "description": "A library that provides lazy instantiation logic for a map of objects", + "homepage": "https://github.com/Ocramius/LazyMap", + "keywords": [ + "lazy", + "lazy instantiation", + "lazy loading", + "map", + "service location" + ], + "time": "2014-05-01 22:15:23" + }, { "name": "phing/phing", "version": "2.6.1", @@ -1100,6 +1214,386 @@ ], "time": "2013-11-13 12:10:20" }, + { + "name": "phpunit/php-code-coverage", + "version": "2.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "09a53c29da426623e9a8a416dda1c7ed3b2d3d72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/09a53c29da426623e9a8a416dda1c7ed3b2d3d72", + "reference": "09a53c29da426623e9a8a416dda1c7ed3b2d3d72", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3.1", + "phpunit/php-text-template": "~1.2.0", + "phpunit/php-token-stream": "~1.2.2", + "sebastian/environment": "~1.0.0", + "sebastian/version": "~1.0.3" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4.0.14" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2014-06-30 09:08:59" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2013-10-10 15:34:57" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "a0802561692c3b2bb0ed972f7ffafbfab068e580" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/a0802561692c3b2bb0ed972f7ffafbfab068e580", + "reference": "a0802561692c3b2bb0ed972f7ffafbfab068e580", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2014-06-26 07:15:38" + }, + { + "name": "phpunit/phpunit", + "version": "4.1.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "6b3a337e57ce9c8bcb47cb06acacdc87c61f1b19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6b3a337e57ce9c8bcb47cb06acacdc87c61f1b19", + "reference": "6b3a337e57ce9c8bcb47cb06acacdc87c61f1b19", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.1", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0.2", + "phpunit/phpunit-mock-objects": "~2.1", + "sebastian/comparator": "~1.0", + "sebastian/diff": "~1.1", + "sebastian/environment": "~1.0", + "sebastian/exporter": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2014-07-03 04:08:15" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "215e10f6355e648faa786c0ba9093d132b30e56b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/215e10f6355e648faa786c0ba9093d132b30e56b", + "reference": "215e10f6355e648faa786c0ba9093d132b30e56b", + "shasum": "" + }, + "require": { + "ocramius/instantiator": "~1.0", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "4.3.*@dev" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2014-06-28 11:28:27" + }, { "name": "propel/propel1", "version": "dev-master", @@ -1163,6 +1657,274 @@ ], "time": "2013-11-11 11:10:35" }, + { + "name": "sebastian/comparator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.1", + "sebastian/exporter": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2014-05-11 23:00:21" + }, + { + "name": "sebastian/diff", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "ac84cfdec593945f36f24074d6ea17d296e86f76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ac84cfdec593945f36f24074d6ea17d296e86f76", + "reference": "ac84cfdec593945f36f24074d6ea17d296e86f76", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2014-05-12 05:21:40" + }, + { + "name": "sebastian/environment", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "10c7467da0622f7848cc5cadc0828c3359254df4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/10c7467da0622f7848cc5cadc0828c3359254df4", + "reference": "10c7467da0622f7848cc5cadc0828c3359254df4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2014-05-04 17:56:05" + }, + { + "name": "sebastian/exporter", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "eb54a69388e5b7ea48561a65588f067fdda0c886" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/eb54a69388e5b7ea48561a65588f067fdda0c886", + "reference": "eb54a69388e5b7ea48561a65588f067fdda0c886", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net", + "role": "Lead" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2014-05-05 08:31:02" + }, + { + "name": "sebastian/version", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2014-03-07 15:35:33" + }, { "name": "symfony/console", "version": "dev-master", diff --git a/src/JMS/Serializer/JsonSerializationVisitor.php b/src/JMS/Serializer/JsonSerializationVisitor.php index 5d917cc6b..48da2278d 100644 --- a/src/JMS/Serializer/JsonSerializationVisitor.php +++ b/src/JMS/Serializer/JsonSerializationVisitor.php @@ -54,6 +54,11 @@ public function visitArray($data, array $type, Context $context) { $result = parent::visitArray($data, $type, $context); + if ($result instanceof \ArrayObject) { + $result = $result->getArrayCopy(); + $this->setRoot($result); + } + if (null !== $this->getRoot() && isset($type['params'][1]) && 0 === count($result)) { // ArrayObject is specially treated by the json_encode function and // serialized to { } while a mere array would be serialized to []. diff --git a/tests/JMS/Serializer/Tests/Fixtures/SecondSimpleEmptyObject.php b/tests/JMS/Serializer/Tests/Fixtures/SecondSimpleEmptyObject.php new file mode 100644 index 000000000..9f7b745db --- /dev/null +++ b/tests/JMS/Serializer/Tests/Fixtures/SecondSimpleEmptyObject.php @@ -0,0 +1,20 @@ +bar = $bar; + } +} diff --git a/tests/JMS/Serializer/Tests/Fixtures/SimpleEmptyObject.php b/tests/JMS/Serializer/Tests/Fixtures/SimpleEmptyObject.php new file mode 100644 index 000000000..17f58bce8 --- /dev/null +++ b/tests/JMS/Serializer/Tests/Fixtures/SimpleEmptyObject.php @@ -0,0 +1,34 @@ +foo = new SecondSimpleEmptyObject(null); + $this->bar = $bar; + } + + public function getFoo() + { + return $this->foo; + } + + public function getBar() + { + return $this->bar; + } +} diff --git a/tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php b/tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php index d882a3ecf..c19467bb3 100644 --- a/tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php @@ -257,7 +257,6 @@ public function testArrayObjects() } } - public function testDateTimeArrays() { $data = array( diff --git a/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php b/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php index c6642e611..b952c51a0 100644 --- a/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/Doctrine/IntegrationTest.php @@ -176,4 +176,4 @@ public function getAliasNamespace($alias) throw new \RuntimeException(sprintf('The namespace alias "%s" is not known to any manager.', $alias)); } -} \ No newline at end of file +} diff --git a/tests/JMS/Serializer/Tests/Serializer/GraphNavigatorTest.php b/tests/JMS/Serializer/Tests/Serializer/GraphNavigatorTest.php index dc2772a79..293b2fadb 100644 --- a/tests/JMS/Serializer/Tests/Serializer/GraphNavigatorTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/GraphNavigatorTest.php @@ -131,23 +131,7 @@ public function testNavigatorChangeTypeOnSerialization() $event->setType($type['name'], $type['params']); }); - $subscribingHandlerClass = $this->getMockClass('JMS\Serializer\Handler\SubscribingHandlerInterface', array('getSubscribingMethods', 'serialize')); - $subscribingHandlerClass::staticExpects($this->once()) - ->method('getSubscribingMethods') - ->will($this->returnValue(array(array( - 'type' => $typeName, - 'format' => 'foo', - 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, - 'method' => 'serialize' - )))); - - $subscribingHandler = new $subscribingHandlerClass(); - $subscribingHandler->expects($this->once()) - ->method('serialize') - ->with($this->equalTo($this->context), $this->equalTo($object)); - - $this->handlerRegistry->registerSubscribingHandler($subscribingHandler); - + $this->handlerRegistry->registerSubscribingHandler(new TestSubscribingHandler()); $this->context->expects($this->any()) ->method('getDirection') ->will($this->returnValue(GraphNavigator::DIRECTION_SERIALIZATION)); @@ -176,3 +160,16 @@ class SerializableClass { public $foo = 'bar'; } + +class TestSubscribingHandler implements \JMS\Serializer\Handler\SubscribingHandlerInterface +{ + public static function getSubscribingMethods() + { + return array(array( + 'type' => 'JsonSerializable', + 'format' => 'foo', + 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, + 'method' => 'serialize' + )); + } +} diff --git a/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php b/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php index 9d74724eb..bf924f263 100644 --- a/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php @@ -19,6 +19,8 @@ namespace JMS\Serializer\Tests\Serializer; use JMS\Serializer\Context; +use JMS\Serializer\SerializationContext; +use JMS\Serializer\Tests\Fixtures\SimpleEmptyObject; use JMS\Serializer\Exception\RuntimeException; use JMS\Serializer\EventDispatcher\Event; use JMS\Serializer\EventDispatcher\EventSubscriberInterface; @@ -48,6 +50,7 @@ protected function getContent($key) $outputs['array_integers'] = '[1,3,4]'; $outputs['array_floats'] = '[1.34,3,6.42]'; $outputs['array_objects'] = '[{"foo":"foo","moo":"bar","camel_case":"boo"},{"foo":"baz","moo":"boo","camel_case":"boo"}]'; + $outputs['array_empty_objects'] = '[{"foo":{},"moo":"bar"},{"foo":{},"moo":"baz"}]'; $outputs['array_mixed'] = '["foo",1,true,{"foo":"foo","moo":"bar","camel_case":"boo"},[1,3,true]]'; $outputs['array_datetimes_object'] = '{"array_with_default_date_time":["2047-01-01T12:47:47+0000","2013-12-05T00:00:00+0000"],"array_with_formatted_date_time":["01.01.2047 12:47:47","05.12.2013 00:00:00"]}'; $outputs['array_named_datetimes_object'] = '{"named_array_with_formatted_date":{"testdate1":"01.01.2047 12:47:47","testdate2":"05.12.2013 00:00:00"}}'; @@ -201,7 +204,17 @@ public function testSerializeWithNonUtf8EncodingWhenDisplayErrorsOn() public function testSerializeArrayWithEmptyObject() { - $this->assertEquals('{"0":{}}', $this->serialize(array(new \stdClass()))); + $this->assertEquals('[{}]', $this->serialize(array(new \stdClass()))); + } + + public function testArrayEmptyObject() + { + $data = array(new SimpleEmptyObject('bar'), new SimpleEmptyObject('baz')); + $this->assertEquals($this->getContent('array_empty_objects'), $this->serialize($data)); + + if ($this->hasDeserializer()) { + $this->assertEquals($data, $this->deserialize($this->getContent('array_empty_objects'), 'array')); + } } protected function getFormat() diff --git a/tests/JMS/Serializer/Tests/Serializer/XmlSerializationTest.php b/tests/JMS/Serializer/Tests/Serializer/XmlSerializationTest.php index 9494d6c9a..93b2593ae 100644 --- a/tests/JMS/Serializer/Tests/Serializer/XmlSerializationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/XmlSerializationTest.php @@ -73,7 +73,6 @@ public function testPropertyIsCollectionOfObjectsWithAttributeAndValue() /** * @expectedException JMS\Serializer\Exception\InvalidArgumentException - * @expectedExceptionMessage The document type "]>" is not allowed. If it is safe, you may add it to the whitelist configuration. */ public function testExternalEntitiesAreDisabledByDefault() { @@ -88,7 +87,6 @@ public function testExternalEntitiesAreDisabledByDefault() /** * @expectedException JMS\Serializer\Exception\InvalidArgumentException - * @expectedExceptionMessage The document type "" is not allowed. If it is safe, you may add it to the whitelist configuration. */ public function testDocumentTypesAreNotAllowed() { @@ -97,6 +95,14 @@ public function testDocumentTypesAreNotAllowed() public function testWhitelistedDocumentTypesAreAllowed() { + if ( + (PHP_VERSION_ID >= 50429 && PHP_VERSION_ID < 50500) || + (PHP_VERSION_ID >= 50513) + ) { + $this->markTestSkipped( + sprintf('PHP version %s does not support this behavior', phpversion()) + ); + } $this->deserializationVisitors->get('xml')->get()->setDoctypeWhitelist(array( '', ']>'));