public function testSerialization()
 {
     $element1 = new ProductImage('MOB_12543');
     $element1->add(new ImageUri('http://host.com/img1.jpg'));
     $element2 = new ProductImage('ASM_A8012');
     $element2->add(new ImageUri('http://host.com/img2.jpg'));
     $collection = new ProductImageCollection();
     $collection->add($element1);
     $collection->add($element2);
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $xml = '
         <Request>
             <ProductImage>
                 <SellerSku>MOB_12543</SellerSku>
                 <Images>
                     <Image>http://host.com/img1.jpg</Image>
                 </Images>
             </ProductImage>
             <ProductImage>
                 <SellerSku>ASM_A8012</SellerSku>
                 <Images>
                     <Image>http://host.com/img2.jpg</Image>
                 </Images>
             </ProductImage>
         </Request>
     ';
     $this->assertXmlStringEqualsXmlString($xml, $serializer->serialize($collection, 'xml'));
 }
Пример #2
0
 public function testSerialization()
 {
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $xml = '<Image>http://www.mobly.com.br/img/product-1.jpg</Image>';
     $imageUri = new ImageUri('http://www.mobly.com.br/img/product-1.jpg');
     $this->assertXmlStringEqualsXmlString($xml, $serializer->serialize($imageUri, 'xml'));
 }
 public function __invoke(ResponseInterface $response)
 {
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     if (count($response->xml()->xpath('/ErrorResponse'))) {
         $serializer = SerializerBuilder::create()->build();
         return $serializer->deserialize($response->xml()->asXML(), 'SellerCenter\\SDK\\Common\\Api\\Response\\Error\\ErrorResponse', 'xml');
     }
     return;
 }
 public function testSerialization()
 {
     $collection = new ImageUriCollection();
     $collection->add(new ImageUri('http://host.com/img1.jpg'));
     $collection->add(new ImageUri('http://host.com/img2.jpg'));
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $xml = '
         <Images>
             <Image>http://host.com/img1.jpg</Image>
             <Image>http://host.com/img2.jpg</Image>
         </Images>
     ';
     $this->assertXmlStringEqualsXmlString($xml, $serializer->serialize($collection, 'xml'));
 }
Пример #5
0
    public function testeDeserialization()
    {
        $xml = '<SuccessResponse>
  <Head>
    <RequestId><![CDATA[]]></RequestId>
    <RequestAction><![CDATA[GetProducts]]></RequestAction>
    <ResponseType><![CDATA[Products]]></ResponseType>
  </Head>
  <Body>
    <Products>
      <Product>
        <ParentSku><![CDATA[ASM_A8012]]></ParentSku>
        <Status><![CDATA[inactive]]></Status>
        <Name><![CDATA[Product name]]></Name>
        <Variation><![CDATA[...]]></Variation>
        <Quantity><![CDATA[0]]></Quantity>
        <SellerSku><![CDATA[ASM_A8012]]></SellerSku>
        <Price>123.99</Price>
      </Product>
      <Product>
        <ParentSku><![CDATA[DC_10000]]></ParentSku>
        <Status><![CDATA[inactive]]></Status>
        <Name><![CDATA[Produto teste 1 0 0 1 3]]></Name>
        <Variation><![CDATA[...]]></Variation>
        <Quantity><![CDATA[0]]></Quantity>
        <SellerSku><![CDATA[DC_10000]]></SellerSku>
        <Price>123</Price>
      </Product>
    </Products>
  </Body>
</SuccessResponse>';
        \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
        $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
        /* @var Response $response */
        $response = $serializer->deserialize($xml, 'SellerCenter\\SDK\\Product\\Api\\GetProducts\\Response', 'xml');
        $this->assertInstanceOf('SellerCenter\\SDK\\Product\\Api\\GetProducts\\Response', $response);
        $this->assertInstanceOf('SellerCenter\\SDK\\Common\\Api\\Response\\Success\\Head', $response->getHead());
        $this->assertInstanceOf('SellerCenter\\SDK\\Product\\Api\\GetProducts\\Body', $response->getBody());
        $this->assertEquals('GetProducts', $response->getHead()->getRequestAction());
        $this->assertEquals('Products', $response->getHead()->getResponseType());
        $this->assertCount(2, $response->getBody()->getProducts());
        /* @var \SellerCenter\SDK\Product\Product $product */
        $product = $response->getBody()->getProducts()->first();
        $this->assertInstanceOf('SellerCenter\\SDK\\Product\\Product', $product);
        $this->assertEquals('ASM_A8012', $product->getSellerSku());
        $this->assertCount(2, $response->getBody()->toArray());
    }
Пример #6
0
 /**
  * @param SimpleXMLElement $value
  * @param string           $deserialize
  *
  * @return mixed
  */
 public function parse(SimpleXMLElement $value, $deserialize)
 {
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     $serializer = SerializerBuilder::create()->build();
     return $serializer->deserialize($value->asXML(), $deserialize, 'xml');
 }
 /**
  * Builds the XML body based on an anotated class.
  *
  * @param $class
  *
  * @return string
  */
 public function serialize($class)
 {
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     $serializer = SerializerBuilder::create()->build();
     return $serializer->serialize($class, 'xml');
 }
Пример #8
0
 public function testDeserialization()
 {
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $xml = '<Product><SellerSku>ASM_A8012</SellerSku></Product>';
     /* @var \SellerCenter\SDK\Product\Product $product */
     $product = $serializer->deserialize($xml, 'SellerCenter\\SDK\\Product\\Product', 'xml');
     $this->assertEquals('ASM_A8012', $product->getSellerSku());
 }