Requires --enable-xmlreader and --enable-xmlwriter (default in most PHP installations)
Since: 2.0
Author: Richard Fullmer (richard.fullmer@opensoftdev.com)
Inheritance: implements Doctrine\OXM\Marshaller\Marshaller
Example #1
0
 /**
  * @test
  */
 public function itShouldDoDeepInheritedFieldsCorrectly()
 {
     $request = new Request();
     $request->id = 1;
     $bo = new ConcreteBO3();
     $bo->inherit = 1;
     $bo->overridden = 'yes';
     $bo->description = 'Scooby Doo';
     $request->bo = $bo;
     $xml = $this->marshaller->marshalToString($request);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="UTF-8"?>
         <request id="1">
             <concrete-bo3 inherit="1" description="Scooby Doo">
                 <overridden>yes</overridden>
             </concrete-bo3>
         </request>', $xml);
     $otherRequest = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals(1, $otherRequest->id);
     $this->assertInstanceOf('Doctrine\\Tests\\OXM\\Entities\\MappedSuperclass\\ConcreteBO3', $otherRequest->bo);
     $this->assertInstanceOf('Doctrine\\Tests\\OXM\\Entities\\MappedSuperclass\\BusinessObject', $otherRequest->bo);
     $this->assertInstanceOf('Doctrine\\Tests\\OXM\\Entities\\MappedSuperclass\\AbstractBusinessObject', $otherRequest->bo);
     $this->assertEquals(1, $otherRequest->bo->inherit);
     $this->assertEquals('yes', $otherRequest->bo->overridden);
     $this->assertEquals('Scooby Doo', $otherRequest->bo->description);
 }
Example #2
0
 /**
  * @test
  */
 public function collectionWrapsXmlText()
 {
     $wrapper = new Wrapper();
     $wrapper->list = array('red', 'green', 'blue');
     $wrapper->enum = array('one', 'two', 'three', 'four');
     $xml = $this->marshaller->marshalToString($wrapper);
     $this->assertXmlStringEqualsXmlString('<wrapper xmlns:prfx="http://www.foo.bar.baz.com/schema">
         <foo>
             <list>red</list>
             <list>green</list>
             <list>blue</list>
         </foo>
         <prfx:bar>
             <prfx:enum>one</prfx:enum>
             <prfx:enum>two</prfx:enum>
             <prfx:enum>three</prfx:enum>
             <prfx:enum>four</prfx:enum>
         </prfx:bar>
     </wrapper>', $xml);
     $otherWrapper = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals(3, count($otherWrapper->list));
     $this->assertContains('red', $otherWrapper->list);
     $this->assertContains('green', $otherWrapper->list);
     $this->assertContains('blue', $otherWrapper->list);
     $this->assertEquals(4, count($otherWrapper->enum));
     $this->assertContains('one', $otherWrapper->enum);
     $this->assertContains('two', $otherWrapper->enum);
     $this->assertContains('three', $otherWrapper->enum);
     $this->assertContains('four', $otherWrapper->enum);
 }
Example #3
0
 private function initialize()
 {
     if ($this->streamUri !== null) {
         $this->cursor->openUri($this->streamUri);
     } else {
         $this->cursor->openMemory();
     }
     $this->cursor->startDocument($this->marshaller->getSchemaVersion(), $this->marshaller->getEncoding());
     if ($this->marshaller->getIndent() > 0) {
         $this->cursor->setIndent((int) $this->marshaller->getIndent());
     }
 }
Example #4
0
 /**
  * @test
  */
 public function collectionWrapsXmlMappedSuperclass()
 {
     $wrapperForSuperclass = new WrapperForSuperclass();
     $childA = new ChildA();
     $childA->aField = 'blue';
     $childB = new ChildB();
     $childB->bField = 'red';
     $wrapperForSuperclass->children = array($childA, $childB);
     $xml = $this->marshaller->marshalToString($wrapperForSuperclass);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="UTF-8"?>
     <wrapper-for-superclass>
         <foo>
             <child-a>
                 <a-field>blue</a-field>
             </child-a>
             <child-b>
                 <b-field>red</b-field>
             </child-b>
         </foo>
     </wrapper-for-superclass>', $xml);
     $otherWrapperForSuperclass = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals(2, count($otherWrapperForSuperclass->children));
     $this->assertContains('blue', $otherWrapperForSuperclass->children[0]->aField);
     $this->assertContains('red', $otherWrapperForSuperclass->children[1]->bField);
 }
 /**
  * @test
  */
 public function itShouldHandleUnknownElements()
 {
     $xml = '<?xml version="1.0" encoding="UTF-8"?>
                 <article name="article one">
                  <tag name="oxm">
                      <unknownExtensionGroup attr1="bip">
                          Tom
                          <unknownExtension attr2="bap">
                              Jerry
                              <foo>bar</foo>
                              <tag name="xml" />
                              Mouse
                          </unknownExtension>
                      </unknownExtensionGroup>
                  </tag>
                  <tag name="xml" />
                 </article>';
     $this->marshaller->setAllowUnknownElements(TRUE);
     $article1 = $this->marshaller->unmarshalFromString($xml);
     $firstTag = $article1->tags[0];
     $this->assertObjectHasAttribute('unknownExtensionGroup', $firstTag, 'Has unknownExtensionGroup');
     $this->assertAttributeInstanceof('stdClass', 'unknownExtensionGroup', $firstTag, 'unknownExtensionGroup is a stdClass');
     $unknownExtensionGroup = $firstTag->unknownExtensionGroup;
     $this->assertAttributeCount(1, '_attrs', $unknownExtensionGroup, 'unknownExtensionGroup has 1 attribute');
     // FIXME: Add in more tests
     $article1xml = $this->marshaller->marshalToString($article1);
 }
Example #6
0
 /**
  * @test
  */
 public function itShouldHandleCircularReferences()
 {
     $article = new Article();
     $article->name = 'article one';
     $tag = new Tag();
     $tag->name = 'oxm';
     $tag->article = $article;
     $tag2 = new Tag();
     $tag2->name = 'xml';
     $tag2->article = $article;
     $article->tags = array($tag, $tag2);
     $xml = $this->marshaller->marshalToString($article);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="UTF-8"?>
         <article name="article one">
          <tag name="oxm" />
          <tag name="xml" />
         </article>', $xml);
     $otherArticle = $this->marshaller->unmarshalFromString($xml);
     $this->assertTrue($otherArticle instanceof Article);
     $this->assertEquals('article one', $otherArticle->name);
     $this->assertCount(2, $otherArticle->tags);
     $this->assertEquals('oxm', $otherArticle->tags[0]->name);
     $this->assertEquals('xml', $otherArticle->tags[1]->name);
     $article2 = new Article();
     $article2->name = 'article two';
     $tag3 = new Tag();
     $tag3->name = 'three';
     $tag3->article = $article2;
     $tag4 = new Tag();
     $tag4->name = 'four';
     $tag4->article = $article2;
     $article2->tags = array($tag3, $tag4);
     $xml = $this->marshaller->marshalToString($article2);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="UTF-8"?>
         <article name="article two">
          <tag name="three" />
          <tag name="four" />
         </article>', $xml);
     $article2 = $this->marshaller->unmarshalFromString($xml);
     $this->assertTrue($article2 instanceof Article);
     $this->assertEquals('article two', $article2->name);
     $this->assertCount(2, $article2->tags);
     $this->assertEquals('three', $article2->tags[0]->name);
     $this->assertEquals('four', $article2->tags[1]->name);
     //        $this->assertEquals($article2, $article2->tags[1]->article);
     $tag4Article = new Article();
     $tag4Article->name = 'article for tag4';
     $tag4->article = $tag4Article;
     $xml = $this->marshaller->marshalToString($tag4);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="UTF-8"?>
          <tag name="four">
             <article name="article for tag4" />
          </tag>', $xml);
     $otherTag4 = $this->marshaller->unmarshalFromString($xml);
     $this->assertTrue($otherTag4 instanceof Tag);
     $this->assertEquals('article for tag4', $otherTag4->article->name);
     $this->assertEquals('four', $otherTag4->name);
 }
Example #7
0
 /**
  * @test
  */
 public function itShouldSupportMarshallingToOtherEncodings()
 {
     $simple = new SimpleChild();
     $this->marshaller->setEncoding('ISO-8859-1');
     $xml = $this->marshaller->marshalToString($simple);
     $this->assertTrue(strlen($xml) > 0);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="ISO-8859-1"?><simple-child><other>yes</other></simple-child>', $xml);
     $obj = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals('yes', $obj->other);
 }
Example #8
0
 public function itShouldSupportEmptyElement()
 {
     $xml = '<?xml version="1.0" encoding="UTF-8"?>
         <address street="street">
             <city></city>
         </address>';
     $address = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals('', $address->getCity());
     $xml = '<?xml version="1.0" encoding="UTF-8"?>
         <address street="street">
             <city />
         </address>';
     $address = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals('', $address->getCity());
 }
 public function send()
 {
     $commands = new \Opensoft\Drools\Entity\BatchExecution('ksession1', $this->commands);
     $xml = $this->marshaller->marshalToString($commands);
     $this->logger->info("Sending to Drools: " . $xml);
     print_r($xml);
     $response = $this->httpClient->setRawData($xml, 'text/plain')->request('POST');
     if (!$response->isSuccessful()) {
         $this->logger->err($response->getHeadersAsString());
         throw new \RuntimeException("Drools Execution server returned an invalid response");
     }
     $responseXml = $response->getBody();
     if (empty($responseXml)) {
         print_r($response);
         throw new \RuntimeException("Drools Execution server returned an invalid response");
     }
     $this->logger->info("Server returned: " . $responseXml);
     print_r($responseXml);
     return $this->marshaller->unmarshalFromString($responseXml);
 }