示例#1
0
 private function getTestObject()
 {
     $post = new BlogPost('FooooooooooooooooooooooBAR', new Author('Foo'), new \DateTime());
     for ($i = 0; $i < 10; $i++) {
         $post->addComment(new Comment(new Author('foo'), 'foobar'));
     }
     return $post;
 }
 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')));
     $post->addComment($comment = new Comment($author, 'foo'));
     $this->assertEquals($this->getContent('blog_post'), $this->serialize($post));
     if ($this->hasDeserializer()) {
         $deserialized = $this->deserialize($this->getContent('blog_post'), get_class($post));
         $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->assertAttributeEquals(new ArrayCollection(array($comment)), 'comments', $deserialized);
         $this->assertAttributeEquals($author, 'author', $deserialized);
     }
 }