Ver Fonte

Merge remote-tracking branch 'origin/issue-199' into issue-199

Conflicts:
	src/JMS/Serializer/AbstractVisitor.php
	tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php
	tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php
Jens Hassler há 11 anos atrás
pai
commit
077e9ede16

+ 3 - 98
tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php

@@ -29,7 +29,6 @@ use JMS\Serializer\Tests\Fixtures\InlineChildEmpty;
 use JMS\Serializer\Tests\Fixtures\NamedDateTimeArraysObject;
 use JMS\Serializer\Tests\Fixtures\Tree;
 use PhpCollection\Sequence;
-use Symfony\Component\Form\FormFactoryBuilder;
 use Symfony\Component\Translation\MessageSelector;
 use Symfony\Component\Translation\IdentityTranslator;
 use JMS\Serializer\EventDispatcher\Subscriber\DoctrineProxySubscriber;
@@ -56,7 +55,6 @@ use JMS\Serializer\Tests\Fixtures\AccessorOrderChild;
 use JMS\Serializer\Tests\Fixtures\AccessorOrderParent;
 use JMS\Serializer\Tests\Fixtures\AccessorOrderMethod;
 use JMS\Serializer\Tests\Fixtures\Author;
-use JMS\Serializer\Tests\Fixtures\Publisher;
 use JMS\Serializer\Tests\Fixtures\AuthorList;
 use JMS\Serializer\Tests\Fixtures\AuthorReadOnly;
 use JMS\Serializer\Tests\Fixtures\BlogPost;
@@ -256,67 +254,6 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         }
     }
 
-
-    public function testDateTimeArrays()
-    {
-        $data = array(
-            new \DateTime('2047-01-01 12:47:47', new \DateTimeZone('UTC')),
-            new \DateTime('2013-12-05 00:00:00', new \DateTimeZone('UTC'))
-        );
-
-        $object = new DateTimeArraysObject($data, $data);
-        $serializedObject = $this->serialize( $object );
-
-        $this->assertEquals($this->getContent('array_datetimes_object'), $serializedObject);
-
-        if ($this->hasDeserializer()) {
-            /** @var DateTimeArraysObject $deserializedObject */
-            $deserializedObject = $this->deserialize($this->getContent('array_datetimes_object'), 'Jms\Serializer\Tests\Fixtures\DateTimeArraysObject');
-
-            /** deserialized object has a default timezone set depending on user's timezone settings. That's why we manually set the UTC timezone on the DateTime objects. */
-            foreach ($deserializedObject->getArrayWithDefaultDateTime() as $dateTime) {
-                $dateTime->setTimezone(new \DateTimeZone('UTC'));
-            }
-
-            foreach ($deserializedObject->getArrayWithFormattedDateTime() as $dateTime) {
-                $dateTime->setTimezone(new \DateTimeZone('UTC'));
-            }
-
-            $this->assertEquals($object, $deserializedObject);
-        }
-    }
-
-    public function testNamedDateTimeArrays()
-    {
-        $data = array(
-            new \DateTime('2047-01-01 12:47:47', new \DateTimeZone('UTC')),
-            new \DateTime('2013-12-05 00:00:00', new \DateTimeZone('UTC'))
-        );
-
-        $object = new NamedDateTimeArraysObject(array('testdate1' => $data[0], 'testdate2' => $data[1]));
-        $serializedObject = $this->serialize( $object );
-
-        $this->assertEquals($this->getContent('array_named_datetimes_object'), $serializedObject);
-
-        if ($this->hasDeserializer()) {
-
-            // skip XML deserialization
-            if ($this->getFormat() === 'xml') {
-                return;
-            }
-
-            /** @var DateTimeArraysObject $deserializedObject */
-            $deserializedObject = $this->deserialize($this->getContent('array_named_datetimes_object'), 'Jms\Serializer\Tests\Fixtures\NamedDateTimeArraysObject');
-
-            /** deserialized object has a default timezone set depending on user's timezone settings. That's why we manually set the UTC timezone on the DateTime objects. */
-            foreach ($deserializedObject->getNamedArrayWithFormattedDate() as $dateTime) {
-                $dateTime->setTimezone(new \DateTimeZone('UTC'));
-            }
-
-            $this->assertEquals($object, $deserializedObject);
-        }
-    }
-
     public function testArrayMixed()
     {
         $this->assertEquals($this->getContent('array_mixed'), $this->serialize(array('foo', 1, true, new SimpleObject('foo', 'bar'), array(1, 3, true))));
@@ -355,7 +292,7 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
 
     public function testBlogPost()
     {
-        $post = new BlogPost('This is a nice title.', $author = new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')), new Publisher('Bar Foo'));
+        $post = new BlogPost('This is a nice title.', $author = new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')));
         $post->addComment($comment = new Comment($author, 'foo'));
 
         $this->assertEquals($this->getContent('blog_post'), $this->serialize($post));
@@ -365,7 +302,6 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
             $this->assertEquals('2011-07-30T00:00:00+0000', $this->getField($deserialized, 'createdAt')->format(\DateTime::ISO8601));
             $this->assertAttributeEquals('This is a nice title.', 'title', $deserialized);
             $this->assertAttributeSame(false, 'published', $deserialized);
-            $this->assertAttributeSame('1edf9bf60a32d89afbb85b2be849e3ceed5f5b10', 'etag', $deserialized);
             $this->assertAttributeEquals(new ArrayCollection(array($comment)), 'comments', $deserialized);
             $this->assertAttributeEquals(new Sequence(array($comment)), 'comments2', $deserialized);
             $this->assertAttributeEquals($author, 'author', $deserialized);
@@ -377,10 +313,9 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         $objectConstructor = new InitializedBlogPostConstructor();
         $this->serializer = new Serializer($this->factory, $this->handlerRegistry, $objectConstructor, $this->serializationVisitors, $this->deserializationVisitors, $this->dispatcher);
 
-        $post = new BlogPost('This is a nice title.', $author = new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')), new Publisher('Bar Foo'));
+        $post = new BlogPost('This is a nice title.', $author = new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')));
 
         $this->setField($post, 'author', null);
-        $this->setField($post, 'publisher', null);
 
         $this->assertEquals($this->getContent('blog_post_unauthored'), $this->serialize($post, SerializationContext::create()->setSerializeNull(true)));
 
@@ -565,36 +500,6 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
     }
 
-    public function testFormErrorsWithNonFormComponents()
-    {
-
-        if (!class_exists('Symfony\Component\Form\Extension\Core\Type\SubmitType')) {
-            $this->markTestSkipped('Not using Symfony Form >= 2.3 with submit type');
-        }
-
-        $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
-
-        $factoryBuilder = new FormFactoryBuilder();
-        $factoryBuilder->addType(new \Symfony\Component\Form\Extension\Core\Type\SubmitType);
-        $factoryBuilder->addType(new \Symfony\Component\Form\Extension\Core\Type\ButtonType);
-        $factory = $factoryBuilder->getFormFactory();
-
-        $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('foo', null, $dispatcher);
-        $formConfigBuilder->setFormFactory($factory);
-        $formConfigBuilder->setCompound(true);
-        $formConfigBuilder->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'));
-        $fooConfig = $formConfigBuilder->getFormConfig();
-
-        $form = new Form($fooConfig);
-        $form->add('save', 'submit');
-
-        try {
-            $this->serialize($form);
-        } catch (\Exception $e) {
-            $this->assertTrue(false, 'Serialization should not throw an exception');
-        }
-    }
-
     public function testConstraintViolation()
     {
         $violation = new ConstraintViolation('Message of violation', array(), null, 'foo', null);
@@ -943,7 +848,7 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         $this->serializer = new Serializer($this->factory, $this->handlerRegistry, $objectConstructor, $this->serializationVisitors, $this->deserializationVisitors, $this->dispatcher);
     }
 
-    protected function getField($obj, $name)
+    private function getField($obj, $name)
     {
         $ref = new \ReflectionProperty($obj, $name);
         $ref->setAccessible(true);