Ejemplo n.º 1
0
 public function testToObject()
 {
     $xml = new SimpleXML($this->_xmlString);
     $books = $xml->toObject();
     $this->assertObjectHasAttribute('book', $books);
     $this->assertInternalType('array', $books->book);
     $this->assertCount(3, $books->book);
     foreach ($books->book as $book) {
         $this->assertObjectHasAttribute('title', $book);
         $this->assertStringStartsWith('Book 0', $book->title);
         $this->assertObjectHasAttribute('public', $book);
         $this->assertSame('1999', $book->public);
         $this->assertObjectHasAttribute('publisher', $book);
         $this->assertStringStartsWith('Publisher 0', $book->publisher);
         $this->assertObjectHasAttribute('author', $book);
         if (!is_array($book->author)) {
             $this->assertObjectHasAttribute('name', $book->author);
             $this->assertStringStartsWith('Author 0', $book->author->name);
         } else {
             foreach ($book->author as $author) {
                 $this->assertObjectHasAttribute('name', $author);
                 $this->assertStringStartsWith('Author 0', $author->name);
             }
         }
     }
 }