Best Cucumber Common Library code snippet using Envelope.fromArray
XmlTest.php
Source:XmlTest.php
...202 */203 public function testFromArray()204 {205 $xml = ['tag' => 'value'];206 $obj = Xml::fromArray($xml);207 $this->assertEquals('tag', $obj->getName());208 $this->assertEquals('value', (string)$obj);209 $xml = ['tag' => null];210 $obj = Xml::fromArray($xml);211 $this->assertEquals('tag', $obj->getName());212 $this->assertEquals('', (string)$obj);213 $xml = ['tag' => ['@' => 'value']];214 $obj = Xml::fromArray($xml);215 $this->assertEquals('tag', $obj->getName());216 $this->assertEquals('value', (string)$obj);217 $xml = [218 'tags' => [219 'tag' => [220 [221 'id' => '1',222 'name' => 'defect'223 ],224 [225 'id' => '2',226 'name' => 'enhancement'227 ]228 ]229 ]230 ];231 $obj = Xml::fromArray($xml, 'attributes');232 $this->assertTrue($obj instanceof \SimpleXMLElement);233 $this->assertEquals('tags', $obj->getName());234 $this->assertEquals(2, count($obj));235 $xmlText = <<<XML236<?xml version="1.0" encoding="UTF-8"?>237<tags>238 <tag id="1" name="defect"/>239 <tag id="2" name="enhancement"/>240</tags>241XML;242 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());243 $obj = Xml::fromArray($xml);244 $this->assertTrue($obj instanceof \SimpleXMLElement);245 $this->assertEquals('tags', $obj->getName());246 $this->assertEquals(2, count($obj));247 $xmlText = <<<XML248<?xml version="1.0" encoding="UTF-8"?>249<tags>250 <tag>251 <id>1</id>252 <name>defect</name>253 </tag>254 <tag>255 <id>2</id>256 <name>enhancement</name>257 </tag>258</tags>259XML;260 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());261 $xml = [262 'tags' => [263 ]264 ];265 $obj = Xml::fromArray($xml);266 $this->assertEquals('tags', $obj->getName());267 $this->assertEquals('', (string)$obj);268 $xml = [269 'tags' => [270 'bool' => true,271 'int' => 1,272 'float' => 10.2,273 'string' => 'ok',274 'null' => null,275 'array' => []276 ]277 ];278 $obj = Xml::fromArray($xml, 'tags');279 $this->assertEquals(6, count($obj));280 $this->assertSame((string)$obj->bool, '1');281 $this->assertSame((string)$obj->int, '1');282 $this->assertSame((string)$obj->float, '10.2');283 $this->assertSame((string)$obj->string, 'ok');284 $this->assertSame((string)$obj->null, '');285 $this->assertSame((string)$obj->array, '');286 $xml = [287 'tags' => [288 'tag' => [289 [290 '@id' => '1',291 'name' => 'defect'292 ],293 [294 '@id' => '2',295 'name' => 'enhancement'296 ]297 ]298 ]299 ];300 $obj = Xml::fromArray($xml, 'tags');301 $xmlText = <<<XML302<?xml version="1.0" encoding="UTF-8"?>303<tags>304 <tag id="1">305 <name>defect</name>306 </tag>307 <tag id="2">308 <name>enhancement</name>309 </tag>310</tags>311XML;312 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());313 $xml = [314 'tags' => [315 'tag' => [316 [317 '@id' => '1',318 'name' => 'defect',319 '@' => 'Tag 1'320 ],321 [322 '@id' => '2',323 'name' => 'enhancement'324 ],325 ],326 '@' => 'All tags'327 ]328 ];329 $obj = Xml::fromArray($xml, 'tags');330 $xmlText = <<<XML331<?xml version="1.0" encoding="UTF-8"?>332<tags>All tags<tag id="1">Tag 1<name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>333XML;334 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());335 $xml = [336 'tags' => [337 'tag' => [338 'id' => 1,339 '@' => 'defect'340 ]341 ]342 ];343 $obj = Xml::fromArray($xml, 'attributes');344 $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1">defect</tag></tags>';345 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());346 $xml = [347 'tag' => [348 '@' => 0,349 '@test' => 'A test'350 ]351 ];352 $obj = Xml::fromArray($xml);353 $xmlText = <<<XML354<?xml version="1.0" encoding="UTF-8"?>355<tag test="A test">0</tag>356XML;357 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());358 }359 /**360 * Test non-sequential keys in list types.361 *362 * @return void363 */364 public function testFromArrayNonSequentialKeys()365 {366 $xmlArray = [367 'Event' => [368 [369 'id' => '235',370 'Attribute' => [371 0 => [372 'id' => '9646',373 ],374 2 => [375 'id' => '9647',376 ]377 ]378 ]379 ]380 ];381 $obj = Xml::fromArray($xmlArray);382 $expected = <<<XML383<?xml version="1.0" encoding="UTF-8"?>384<Event>385 <id>235</id>386 <Attribute>387 <id>9646</id>388 </Attribute>389 <Attribute>390 <id>9647</id>391 </Attribute>392</Event>393XML;394 $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());395 }396 /**397 * testFromArrayPretty method398 *399 * @return void400 */401 public function testFromArrayPretty()402 {403 $xml = [404 'tags' => [405 'tag' => [406 [407 'id' => '1',408 'name' => 'defect'409 ],410 [411 'id' => '2',412 'name' => 'enhancement'413 ]414 ]415 ]416 ];417 $expected = <<<XML418<?xml version="1.0" encoding="UTF-8"?>419<tags><tag><id>1</id><name>defect</name></tag><tag><id>2</id><name>enhancement</name></tag></tags>420XML;421 $xmlResponse = Xml::fromArray($xml, ['pretty' => false]);422 $this->assertTextEquals($expected, $xmlResponse->asXML());423 $expected = <<<XML424<?xml version="1.0" encoding="UTF-8"?>425<tags>426 <tag>427 <id>1</id>428 <name>defect</name>429 </tag>430 <tag>431 <id>2</id>432 <name>enhancement</name>433 </tag>434</tags>435XML;436 $xmlResponse = Xml::fromArray($xml, ['pretty' => true]);437 $this->assertTextEquals($expected, $xmlResponse->asXML());438 $xml = [439 'tags' => [440 'tag' => [441 [442 'id' => '1',443 'name' => 'defect'444 ],445 [446 'id' => '2',447 'name' => 'enhancement'448 ]449 ]450 ]451 ];452 $expected = <<<XML453<?xml version="1.0" encoding="UTF-8"?>454<tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>455XML;456 $xmlResponse = Xml::fromArray($xml, ['pretty' => false, 'format' => 'attributes']);457 $this->assertTextEquals($expected, $xmlResponse->asXML());458 $expected = <<<XML459<?xml version="1.0" encoding="UTF-8"?>460<tags>461 <tag id="1" name="defect"/>462 <tag id="2" name="enhancement"/>463</tags>464XML;465 $xmlResponse = Xml::fromArray($xml, ['pretty' => true, 'format' => 'attributes']);466 $this->assertTextEquals($expected, $xmlResponse->asXML());467 }468 /**469 * data provider for fromArray() failures470 *471 * @return array472 */473 public static function invalidArrayDataProvider()474 {475 return [476 [''],477 [null],478 [false],479 [[]],480 [['numeric key as root']],481 [['item1' => '', 'item2' => '']],482 [['items' => ['item1', 'item2']]],483 [[484 'tags' => [485 'tag' => [486 [487 [488 'string'489 ]490 ]491 ]492 ]493 ]],494 [[495 'tags' => [496 '@tag' => [497 [498 '@id' => '1',499 'name' => 'defect'500 ],501 [502 '@id' => '2',503 'name' => 'enhancement'504 ]505 ]506 ]507 ]],508 [new \DateTime()]509 ];510 }511 /**512 * testFromArrayFail method513 *514 * @dataProvider invalidArrayDataProvider515 * @expectedException \Exception516 * @return void517 */518 public function testFromArrayFail($value)519 {520 Xml::fromArray($value);521 }522 /**523 * Test that there are not unterminated errors when building xml524 *525 * @return void526 */527 public function testFromArrayUnterminatedError()528 {529 $data = [530 'product_ID' => 'GENERT-DL',531 'deeplink' => 'http://example.com/deep',532 'image_URL' => 'http://example.com/image',533 'thumbnail_image_URL' => 'http://example.com/thumb',534 'brand' => 'Malte Lange & Co',535 'availability' => 'in stock',536 'authors' => [537 'author' => ['Malte Lange & Co']538 ]539 ];540 $xml = Xml::fromArray(['products' => $data], 'tags');541 $expected = <<<XML542<?xml version="1.0" encoding="UTF-8"?>543<products>544 <product_ID>GENERT-DL</product_ID>545 <deeplink>http://example.com/deep</deeplink>546 <image_URL>http://example.com/image</image_URL>547 <thumbnail_image_URL>http://example.com/thumb</thumbnail_image_URL>548 <brand>Malte Lange & Co</brand>549 <availability>in stock</availability>550 <authors>551 <author>Malte Lange & Co</author>552 </authors>553</products>554XML;555 $this->assertXmlStringEqualsXmlString($expected, $xml->asXML());556 }557 /**558 * testToArray method559 *560 * @return void561 */562 public function testToArray()563 {564 $xml = '<tag>name</tag>';565 $obj = Xml::build($xml);566 $this->assertEquals(['tag' => 'name'], Xml::toArray($obj));567 $xml = CORE_TESTS . 'Fixture/sample.xml';568 $obj = Xml::build($xml);569 $expected = [570 'tags' => [571 'tag' => [572 [573 '@id' => '1',574 'name' => 'defect'575 ],576 [577 '@id' => '2',578 'name' => 'enhancement'579 ]580 ]581 ]582 ];583 $this->assertEquals($expected, Xml::toArray($obj));584 $array = [585 'tags' => [586 'tag' => [587 [588 'id' => '1',589 'name' => 'defect'590 ],591 [592 'id' => '2',593 'name' => 'enhancement'594 ]595 ]596 ]597 ];598 $this->assertEquals(Xml::toArray(Xml::fromArray($array, 'tags')), $array);599 $expected = [600 'tags' => [601 'tag' => [602 [603 '@id' => '1',604 '@name' => 'defect'605 ],606 [607 '@id' => '2',608 '@name' => 'enhancement'609 ]610 ]611 ]612 ];613 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, 'attributes')));614 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, ['return' => 'domdocument', 'format' => 'attributes'])));615 $this->assertEquals(Xml::toArray(Xml::fromArray($array)), $array);616 $this->assertEquals(Xml::toArray(Xml::fromArray($array, ['return' => 'domdocument'])), $array);617 $array = [618 'tags' => [619 'tag' => [620 'id' => '1',621 'posts' => [622 ['id' => '1'],623 ['id' => '2']624 ]625 ],626 'tagOther' => [627 'subtag' => [628 'id' => '1'629 ]630 ]631 ]632 ];633 $expected = [634 'tags' => [635 'tag' => [636 '@id' => '1',637 'posts' => [638 ['@id' => '1'],639 ['@id' => '2']640 ]641 ],642 'tagOther' => [643 'subtag' => [644 '@id' => '1'645 ]646 ]647 ]648 ];649 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, 'attributes')));650 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, ['format' => 'attributes', 'return' => 'domdocument'])));651 $xml = <<<XML652<root>653<tag id="1">defect</tag>654</root>655XML;656 $obj = Xml::build($xml);657 $expected = [658 'root' => [659 'tag' => [660 '@id' => 1,661 '@' => 'defect'662 ]663 ]664 ];665 $this->assertEquals($expected, Xml::toArray($obj));666 $xml = <<<XML667<root>668 <table xmlns="http://www.w3.org/TR/html4/"><tr><td>Apples</td><td>Bananas</td></tr></table>669 <table xmlns="http://www.cakephp.org"><name>CakePHP</name><license>MIT</license></table>670 <table>The book is on the table.</table>671</root>672XML;673 $obj = Xml::build($xml);674 $expected = [675 'root' => [676 'table' => [677 ['tr' => ['td' => ['Apples', 'Bananas']]],678 ['name' => 'CakePHP', 'license' => 'MIT'],679 'The book is on the table.'680 ]681 ]682 ];683 $this->assertEquals($expected, Xml::toArray($obj));684 $xml = <<<XML685<root xmlns:cake="http://www.cakephp.org/">686<tag>defect</tag>687<cake:bug>1</cake:bug>688</root>689XML;690 $obj = Xml::build($xml);691 $expected = [692 'root' => [693 'tag' => 'defect',694 'cake:bug' => 1695 ]696 ];697 $this->assertEquals($expected, Xml::toArray($obj));698 $xml = '<tag type="myType">0</tag>';699 $obj = Xml::build($xml);700 $expected = [701 'tag' => [702 '@type' => 'myType',703 '@' => 0704 ]705 ];706 $this->assertEquals($expected, Xml::toArray($obj));707 }708 /**709 * testRss710 *711 * @return void712 */713 public function testRss()714 {715 $rss = file_get_contents(CORE_TESTS . 'Fixture/rss.xml');716 $rssAsArray = Xml::toArray(Xml::build($rss));717 $this->assertEquals('2.0', $rssAsArray['rss']['@version']);718 $this->assertEquals(2, count($rssAsArray['rss']['channel']['item']));719 $atomLink = ['@href' => 'http://bakery.cakephp.org/articles/rss', '@rel' => 'self', '@type' => 'application/rss+xml'];720 $this->assertEquals($rssAsArray['rss']['channel']['atom:link'], $atomLink);721 $this->assertEquals('http://bakery.cakephp.org/', $rssAsArray['rss']['channel']['link']);722 $expected = [723 'title' => 'Alertpay automated sales via IPN',724 'link' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn',725 'description' => 'I\'m going to show you how I implemented a payment module via the Alertpay payment processor.',726 'pubDate' => 'Tue, 31 Aug 2010 01:42:00 -0500',727 'guid' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn'728 ];729 $this->assertSame($expected, $rssAsArray['rss']['channel']['item'][1]);730 $rss = [731 'rss' => [732 'xmlns:atom' => 'http://www.w3.org/2005/Atom',733 '@version' => '2.0',734 'channel' => [735 'atom:link' => [736 '@href' => 'http://bakery.cakephp.org/articles/rss',737 '@rel' => 'self',738 '@type' => 'application/rss+xml'739 ],740 'title' => 'The Bakery: ',741 'link' => 'http://bakery.cakephp.org/',742 'description' => 'Recent Articles at The Bakery.',743 'pubDate' => 'Sun, 12 Sep 2010 04:18:26 -0500',744 'item' => [745 [746 'title' => 'CakePHP 1.3.4 released',747 'link' => 'http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released'748 ],749 [750 'title' => 'Wizard Component 1.2 Tutorial',751 'link' => 'http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial'752 ]753 ]754 ]755 ]756 ];757 $rssAsSimpleXML = Xml::fromArray($rss);758 $xmlText = <<<XML759<?xml version="1.0" encoding="UTF-8"?>760<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">761 <channel>762 <atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml"/>763 <title>The Bakery: </title>764 <link>http://bakery.cakephp.org/</link>765 <description>Recent Articles at The Bakery.</description>766 <pubDate>Sun, 12 Sep 2010 04:18:26 -0500</pubDate>767 <item>768 <title>CakePHP 1.3.4 released</title>769 <link>http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released</link>770 </item>771 <item>772 <title>Wizard Component 1.2 Tutorial</title>773 <link>http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial</link>774 </item>775 </channel>776</rss>777XML;778 $this->assertXmlStringEqualsXmlString($xmlText, $rssAsSimpleXML->asXML());779 }780 /**781 * testXmlRpc782 *783 * @return void784 */785 public function testXmlRpc()786 {787 $xml = Xml::build('<methodCall><methodName>test</methodName><params /></methodCall>');788 $expected = [789 'methodCall' => [790 'methodName' => 'test',791 'params' => ''792 ]793 ];794 $this->assertSame($expected, Xml::toArray($xml));795 $xml = Xml::build('<methodCall><methodName>test</methodName><params><param><value><array><data><value><int>12</int></value><value><string>Egypt</string></value><value><boolean>0</boolean></value><value><int>-31</int></value></data></array></value></param></params></methodCall>');796 $expected = [797 'methodCall' => [798 'methodName' => 'test',799 'params' => [800 'param' => [801 'value' => [802 'array' => [803 'data' => [804 'value' => [805 ['int' => '12'],806 ['string' => 'Egypt'],807 ['boolean' => '0'],808 ['int' => '-31']809 ]810 ]811 ]812 ]813 ]814 ]815 ]816 ];817 $this->assertSame($expected, Xml::toArray($xml));818 $xmlText = <<<XML819<?xml version="1.0" encoding="UTF-8"?>820<methodResponse>821 <params>822 <param>823 <value>824 <array>825 <data>826 <value>827 <int>1</int>828 </value>829 <value>830 <string>testing</string>831 </value>832 </data>833 </array>834 </value>835 </param>836 </params>837</methodResponse>838XML;839 $xml = Xml::build($xmlText);840 $expected = [841 'methodResponse' => [842 'params' => [843 'param' => [844 'value' => [845 'array' => [846 'data' => [847 'value' => [848 ['int' => '1'],849 ['string' => 'testing']850 ]851 ]852 ]853 ]854 ]855 ]856 ]857 ];858 $this->assertSame($expected, Xml::toArray($xml));859 $xml = Xml::fromArray($expected, 'tags');860 $this->assertXmlStringEqualsXmlString($xmlText, $xml->asXML());861 }862 /**863 * testSoap864 *865 * @return void866 */867 public function testSoap()868 {869 $xmlRequest = Xml::build(CORE_TESTS . 'Fixture/soap_request.xml');870 $expected = [871 'Envelope' => [872 '@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',873 'soap:Body' => [874 'm:GetStockPrice' => [875 'm:StockName' => 'IBM'876 ]877 ]878 ]879 ];880 $this->assertEquals($expected, Xml::toArray($xmlRequest));881 $xmlResponse = Xml::build(CORE_TESTS . DS . 'Fixture/soap_response.xml');882 $expected = [883 'Envelope' => [884 '@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',885 'soap:Body' => [886 'm:GetStockPriceResponse' => [887 'm:Price' => '34.5'888 ]889 ]890 ]891 ];892 $this->assertEquals($expected, Xml::toArray($xmlResponse));893 $xml = [894 'soap:Envelope' => [895 'xmlns:soap' => 'http://www.w3.org/2001/12/soap-envelope',896 '@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',897 'soap:Body' => [898 'xmlns:m' => 'http://www.example.org/stock',899 'm:GetStockPrice' => [900 'm:StockName' => 'IBM'901 ]902 ]903 ]904 ];905 $xmlRequest = Xml::fromArray($xml, ['encoding' => null]);906 $xmlText = <<<XML907<?xml version="1.0"?>908<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">909 <soap:Body xmlns:m="http://www.example.org/stock">910 <m:GetStockPrice>911 <m:StockName>IBM</m:StockName>912 </m:GetStockPrice>913 </soap:Body>914</soap:Envelope>915XML;916 $this->assertXmlStringEqualsXmlString($xmlText, $xmlRequest->asXML());917 }918 /**919 * testNamespace920 *921 * @return void922 */923 public function testNamespace()924 {925 $xml = <<<XML926<root xmlns:ns="http://cakephp.org">927 <ns:tag id="1">928 <child>good</child>929 <otherchild>bad</otherchild>930 </ns:tag>931 <tag>Tag without ns</tag>932</root>933XML;934 $xmlResponse = Xml::build($xml);935 $expected = [936 'root' => [937 'ns:tag' => [938 '@id' => '1',939 'child' => 'good',940 'otherchild' => 'bad'941 ],942 'tag' => 'Tag without ns'943 ]944 ];945 $this->assertEquals($expected, Xml::toArray($xmlResponse));946 $xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:tag id="1" /><tag><id>1</id></tag></root>');947 $expected = [948 'root' => [949 'ns:tag' => [950 '@id' => '1'951 ],952 'tag' => [953 'id' => '1'954 ]955 ]956 ];957 $this->assertEquals($expected, Xml::toArray($xmlResponse));958 $xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:attr>1</ns:attr></root>');959 $expected = [960 'root' => [961 'ns:attr' => '1'962 ]963 ];964 $this->assertEquals($expected, Xml::toArray($xmlResponse));965 $xmlResponse = Xml::build('<root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>');966 $this->assertEquals($expected, Xml::toArray($xmlResponse));967 $xml = [968 'root' => [969 'ns:attr' => [970 'xmlns:ns' => 'http://cakephp.org',971 '@' => 1972 ]973 ]974 ];975 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>';976 $xmlResponse = Xml::fromArray($xml);977 $this->assertEquals($expected, str_replace(["\r", "\n"], '', $xmlResponse->asXML()));978 $xml = [979 'root' => [980 'tag' => [981 'xmlns:pref' => 'http://cakephp.org',982 'pref:item' => [983 'item 1',984 'item 2'985 ]986 ]987 ]988 ];989 $expected = <<<XML990<?xml version="1.0" encoding="UTF-8"?>991<root>992 <tag xmlns:pref="http://cakephp.org">993 <pref:item>item 1</pref:item>994 <pref:item>item 2</pref:item>995 </tag>996</root>997XML;998 $xmlResponse = Xml::fromArray($xml);999 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1000 $xml = [1001 'root' => [1002 'tag' => [1003 'xmlns:' => 'http://cakephp.org'1004 ]1005 ]1006 ];1007 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns="http://cakephp.org"/></root>';1008 $xmlResponse = Xml::fromArray($xml);1009 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1010 $xml = [1011 'root' => [1012 'xmlns:' => 'http://cakephp.org'1013 ]1014 ];1015 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns="http://cakephp.org"/>';1016 $xmlResponse = Xml::fromArray($xml);1017 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1018 $xml = [1019 'root' => [1020 'xmlns:ns' => 'http://cakephp.org'1021 ]1022 ];1023 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns:ns="http://cakephp.org"/>';1024 $xmlResponse = Xml::fromArray($xml);1025 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1026 }1027 /**1028 * test that CDATA blocks don't get screwed up by SimpleXml1029 *1030 * @return void1031 */1032 public function testCdata()1033 {1034 $xml = '<' . '?xml version="1.0" encoding="UTF-8"?>' .1035 '<people><name><![CDATA[ Mark ]]></name></people>';1036 $result = Xml::build($xml);1037 $this->assertEquals(' Mark ', (string)$result->name);1038 }...
RequestMatcherTest.php
Source:RequestMatcherTest.php
...70 'field1' => 'value1',71 'field2' => 'value2',72 ],73 ];74 $first = Request::fromArray($mock);75 $second = Request::fromArray($mock);76 $this->assertTrue(RequestMatcher::matchPostFields($first, $second));77 $mock['post_fields']['field2'] = 'changedvalue2';78 $third = Request::fromArray($mock);79 $this->assertFalse(RequestMatcher::matchPostFields($first, $third));80 }81 public function testMatchingQueryString(): void82 {83 $first = new Request('GET', 'http://example.com/search?query=test', []);84 $second = new Request('GET', 'http://example.com/search?query=test', []);85 $this->assertTrue(RequestMatcher::matchQueryString($first, $second));86 $first = new Request('GET', 'http://example.com/search?query=first', []);87 $second = new Request('GET', 'http://example.com/search?query=second', []);88 $this->assertFalse(RequestMatcher::matchQueryString($first, $second));89 }90 public function testMatchingBody(): void91 {92 $first = new Request('GET', 'http://example.com', []);93 $first->setBody('test');94 $second = new Request('GET', 'http://example.com', []);95 $second->setBody('test');96 $this->assertTrue(RequestMatcher::matchBody($first, $second), 'Bodies should be equal');97 $first = new Request('GET', 'http://example.com', []);98 $first->setBody('test');99 $second = new Request('POST', 'http://example.com', []);100 $second->setBody('different');101 $this->assertFalse(RequestMatcher::matchBody($first, $second), 'Bodies are different.');102 }103 public function testMatchingSoapOperation(): void104 {105 $storedRequest = Request::fromArray([106 'method' => 'POST',107 'url' => 'http://example.com',108 'headers' => [],109 'body' => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org\"><SOAP-ENV:Body><ns1:SearchAdresse><myPtr><cp>45000</cp></myPtr></ns1:SearchAdresse></SOAP-ENV:Body></SOAP-ENV:Envelope>\n",110 ]);111 $request = Request::fromArray([112 'method' => 'POST',113 'url' => 'http://example.com',114 'headers' => [],115 'body' => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org\"><SOAP-ENV:Body><ns1:SearchAdresse><myPtr><cp>75008</cp></myPtr></ns1:SearchAdresse></SOAP-ENV:Body></SOAP-ENV:Envelope>\n",116 ]);117 $this->assertTrue(RequestMatcher::matchSoapOperation($storedRequest, $request), 'Operations are the same');118 $request = Request::fromArray([119 'method' => 'POST',120 'url' => 'http://example.com',121 'headers' => [],122 'body' => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org\"><SOAP-ENV:Body><ns1:SearchFoo><myPtr><cp>75008</cp></myPtr></ns1:SearchFoo></SOAP-ENV:Body></SOAP-ENV:Envelope>\n",123 ]);124 $this->assertFalse(RequestMatcher::matchSoapOperation($storedRequest, $request), 'Operations are different');125 $request = Request::fromArray([126 'method' => 'POST',127 'url' => 'http://example.com',128 'headers' => [],129 'body' => '{}',130 ]);131 $this->assertTrue(RequestMatcher::matchSoapOperation($storedRequest, $request), 'Operation is not SOAP message');132 }133}...
JsonSerializer.php
Source:JsonSerializer.php
...19 }20 if ($data['event'] === "calculation.to.app") {21 // schema validation22 $rankingAllEventDataProvider = new RankingAllEventDataProvider();23 $rankingAllEventDataProvider->fromArray($data);24 $rankingAllEventDataProvider->setEvent($data['event']);25 return new Envelope($rankingAllEventDataProvider);26 }27 if ($data['event'] === "match.to.app") {28 // schema validation29 $matchListDataProvider = new MatchListDataProvider();30 $matchListDataProvider->fromArray($data);31 $matchListDataProvider->setEvent($data['event']);32 return new Envelope($matchListDataProvider);33 }34 throw new \RuntimeException('Incorrect event ' .$data['event']);35 }36 public function encode(Envelope $envelope): array37 {38 /** @var DataProviderInterface $message */39 $message = $envelope->getMessage();40 if (!$message instanceof DataProviderInterface) {41 throw new \RuntimeException('Message should be DataProviderInterface');42 }43 if (method_exists($message, 'getData')) {44 $eventMessage = [...
fromArray
Using AI Code Generation
1$envelope = new Envelope();2$envelope->fromArray($array);3echo $envelope->toXml();4$envelope = new Envelope();5$envelope->fromXml($xml);6echo $envelope->toXml();7$envelope = new Envelope();8$envelope->fromJson($json);9echo $envelope->toXml();10$envelope = new Envelope();11$envelope->fromString($string);12echo $envelope->toXml();13$envelope = new Envelope();14$envelope->fromObject($object);15echo $envelope->toXml();16$envelope = new Envelope();17$envelope->fromArray($array);18echo $envelope->toJson();19$envelope = new Envelope();20$envelope->fromXml($xml);21echo $envelope->toJson();22$envelope = new Envelope();23$envelope->fromJson($json);24echo $envelope->toJson();25$envelope = new Envelope();26$envelope->fromString($string);27echo $envelope->toJson();28$envelope = new Envelope();29$envelope->fromObject($object);30echo $envelope->toJson();31$envelope = new Envelope();32$envelope->fromArray($array);33echo $envelope->toString();34$envelope = new Envelope();35$envelope->fromXml($xml);
fromArray
Using AI Code Generation
1$envelope = new Envelope();2$envelope->fromArray($array);3$envelope = new Envelope();4$envelope->fromArray($array);5$envelope = new Envelope();6$envelope->fromArray($array);7$envelope = new Envelope();8$envelope->fromArray($array);9$envelope = new Envelope();10$envelope->fromArray($array);11$envelope = new Envelope();12$envelope->fromArray($array);13$envelope = new Envelope();14$envelope->fromArray($array);15$envelope = new Envelope();16$envelope->fromArray($array);17$envelope = new Envelope();18$envelope->fromArray($array);19$envelope = new Envelope();20$envelope->fromArray($array);21$envelope = new Envelope();22$envelope->fromArray($array);
fromArray
Using AI Code Generation
1include 'envelope.php';2$envelope = new Envelope();3$envelope->fromArray(array('length' => 6, 'width' => 4, 'height' => 3));4$envelopeArray = $envelope->toArray();5print_r($envelopeArray);6include 'envelope.php';7$envelope = new Envelope();8$envelope->fromArray(array('length' => 6, 'width' => 4, 'height' => 3));9$envelopeArray = $envelope->toArray();10print_r($envelopeArray);11include 'envelope.php';12$envelope = new Envelope();13$envelope->fromArray(array('length' => 6, 'width' => 4, 'height' => 3));14$envelopeArray = $envelope->toArray();15print_r($envelopeArray);16include 'envelope.php';17$envelope = new Envelope();18$envelope->fromArray(array('length' => 6
fromArray
Using AI Code Generation
1$envelope_api = new DocuSign\eSign\Api\EnvelopesApi($api_client);2$envelope = new DocuSign\eSign\Model\Envelope();3$envelope->setEmailSubject("Please sign this document set");4$envelope->setEmailBlurb("Please sign this document set.");5$envelope->setRecipients($recipients);6$envelope->setDocuments($documents);7$envelope->setStatus("sent");8$envelope = $envelope_api->createEnvelope($account_id, $envelope);9$envelope_api = new DocuSign\eSign\Api\EnvelopesApi($api_client);10$options = new DocuSign\eSign\Api\EnvelopesApi\ListStatusChangesOptions();11$options->setFrom_date("2017-01-01");12$options->setTo_date("2017-01-01");13$options->setCount("100");14$options->setOrder("desc");15$options->setInclude("recipients");
fromArray
Using AI Code Generation
1require_once("Envelope.php");2$envelope = new Envelope();3$envelope->send();4require_once("Envelope.php");5$envelope = new Envelope();6$envelope->send();7require_once("Envelope.php");8$envelope = new Envelope();9$envelope->send();10require_once("Envelope.php");11$envelope = new Envelope();12$envelope->send();13require_once("Envelope.php");14$envelope = new Envelope();15$envelope->send();
fromArray
Using AI Code Generation
1include("envelope.php");2$e = new Envelope();3$e->fromArray($_GET);4echo "Length: " . $e->getLength() . "<br />";5echo "Width: " . $e->getWidth() . "<br />";6echo "Height: " . $e->getHeight() . "<br />";7echo "Weight: " . $e->getWeight() . "<br />";8include("envelope.php");9$e = new Envelope();10$e->fromArray($_GET);11echo "Length: " . $e->getLength() . "<br />";12echo "Width: " . $e->getWidth() . "<br />";13echo "Height: " . $e->getHeight() . "<br />";14echo "Weight: " . $e->getWeight() . "<br />";
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with fromArray on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!