How to use fromArray method of Tag class

Best Cucumber Common Library code snippet using Tag.fromArray

XmlTest.php

Source:XmlTest.php Github

copy

Full Screen

...201 */202 public function testFromArray()203 {204 $xml = ['tag' => 'value'];205 $obj = Xml::fromArray($xml);206 $this->assertEquals('tag', $obj->getName());207 $this->assertEquals('value', (string)$obj);208 $xml = ['tag' => null];209 $obj = Xml::fromArray($xml);210 $this->assertEquals('tag', $obj->getName());211 $this->assertEquals('', (string)$obj);212 $xml = ['tag' => ['@' => 'value']];213 $obj = Xml::fromArray($xml);214 $this->assertEquals('tag', $obj->getName());215 $this->assertEquals('value', (string)$obj);216 $xml = [217 'tags' => [218 'tag' => [219 [220 'id' => '1',221 'name' => 'defect'222 ],223 [224 'id' => '2',225 'name' => 'enhancement'226 ]227 ]228 ]229 ];230 $obj = Xml::fromArray($xml, 'attributes');231 $this->assertTrue($obj instanceof \SimpleXMLElement);232 $this->assertEquals('tags', $obj->getName());233 $this->assertEquals(2, count($obj));234 $xmlText = <<<XML235<?xml version="1.0" encoding="UTF-8"?>236<tags>237 <tag id="1" name="defect"/>238 <tag id="2" name="enhancement"/>239</tags>240XML;241 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());242 $obj = Xml::fromArray($xml);243 $this->assertTrue($obj instanceof \SimpleXMLElement);244 $this->assertEquals('tags', $obj->getName());245 $this->assertEquals(2, count($obj));246 $xmlText = <<<XML247<?xml version="1.0" encoding="UTF-8"?>248<tags>249 <tag>250 <id>1</id>251 <name>defect</name>252 </tag>253 <tag>254 <id>2</id>255 <name>enhancement</name>256 </tag>257</tags>258XML;259 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());260 $xml = [261 'tags' => [262 ]263 ];264 $obj = Xml::fromArray($xml);265 $this->assertEquals('tags', $obj->getName());266 $this->assertEquals('', (string)$obj);267 $xml = [268 'tags' => [269 'bool' => true,270 'int' => 1,271 'float' => 10.2,272 'string' => 'ok',273 'null' => null,274 'array' => []275 ]276 ];277 $obj = Xml::fromArray($xml, 'tags');278 $this->assertEquals(6, count($obj));279 $this->assertSame((string)$obj->bool, '1');280 $this->assertSame((string)$obj->int, '1');281 $this->assertSame((string)$obj->float, '10.2');282 $this->assertSame((string)$obj->string, 'ok');283 $this->assertSame((string)$obj->null, '');284 $this->assertSame((string)$obj->array, '');285 $xml = [286 'tags' => [287 'tag' => [288 [289 '@id' => '1',290 'name' => 'defect'291 ],292 [293 '@id' => '2',294 'name' => 'enhancement'295 ]296 ]297 ]298 ];299 $obj = Xml::fromArray($xml, 'tags');300 $xmlText = <<<XML301<?xml version="1.0" encoding="UTF-8"?>302<tags>303 <tag id="1">304 <name>defect</name>305 </tag>306 <tag id="2">307 <name>enhancement</name>308 </tag>309</tags>310XML;311 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());312 $xml = [313 'tags' => [314 'tag' => [315 [316 '@id' => '1',317 'name' => 'defect',318 '@' => 'Tag 1'319 ],320 [321 '@id' => '2',322 'name' => 'enhancement'323 ],324 ],325 '@' => 'All tags'326 ]327 ];328 $obj = Xml::fromArray($xml, 'tags');329 $xmlText = <<<XML330<?xml version="1.0" encoding="UTF-8"?>331<tags>All tags<tag id="1">Tag 1<name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>332XML;333 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());334 $xml = [335 'tags' => [336 'tag' => [337 'id' => 1,338 '@' => 'defect'339 ]340 ]341 ];342 $obj = Xml::fromArray($xml, 'attributes');343 $xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1">defect</tag></tags>';344 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());345 $xml = [346 'tag' => [347 '@' => 0,348 '@test' => 'A test'349 ]350 ];351 $obj = Xml::fromArray($xml);352 $xmlText = <<<XML353<?xml version="1.0" encoding="UTF-8"?>354<tag test="A test">0</tag>355XML;356 $this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());357 }358 /**359 * Test non-sequential keys in list types.360 *361 * @return void362 */363 public function testFromArrayNonSequentialKeys()364 {365 $xmlArray = [366 'Event' => [367 [368 'id' => '235',369 'Attribute' => [370 0 => [371 'id' => '9646',372 ],373 2 => [374 'id' => '9647',375 ]376 ]377 ]378 ]379 ];380 $obj = Xml::fromArray($xmlArray);381 $expected = <<<XML382<?xml version="1.0" encoding="UTF-8"?>383<Event>384 <id>235</id>385 <Attribute>386 <id>9646</id>387 </Attribute>388 <Attribute>389 <id>9647</id>390 </Attribute>391</Event>392XML;393 $this->assertXmlStringEqualsXmlString($expected, $obj->asXML());394 }395 /**396 * testFromArrayPretty method397 *398 * @return void399 */400 public function testFromArrayPretty()401 {402 $xml = [403 'tags' => [404 'tag' => [405 [406 'id' => '1',407 'name' => 'defect'408 ],409 [410 'id' => '2',411 'name' => 'enhancement'412 ]413 ]414 ]415 ];416 $expected = <<<XML417<?xml version="1.0" encoding="UTF-8"?>418<tags><tag><id>1</id><name>defect</name></tag><tag><id>2</id><name>enhancement</name></tag></tags>419XML;420 $xmlResponse = Xml::fromArray($xml, ['pretty' => false]);421 $this->assertTextEquals($expected, $xmlResponse->asXML());422 $expected = <<<XML423<?xml version="1.0" encoding="UTF-8"?>424<tags>425 <tag>426 <id>1</id>427 <name>defect</name>428 </tag>429 <tag>430 <id>2</id>431 <name>enhancement</name>432 </tag>433</tags>434XML;435 $xmlResponse = Xml::fromArray($xml, ['pretty' => true]);436 $this->assertTextEquals($expected, $xmlResponse->asXML());437 $xml = [438 'tags' => [439 'tag' => [440 [441 'id' => '1',442 'name' => 'defect'443 ],444 [445 'id' => '2',446 'name' => 'enhancement'447 ]448 ]449 ]450 ];451 $expected = <<<XML452<?xml version="1.0" encoding="UTF-8"?>453<tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>454XML;455 $xmlResponse = Xml::fromArray($xml, ['pretty' => false, 'format' => 'attributes']);456 $this->assertTextEquals($expected, $xmlResponse->asXML());457 $expected = <<<XML458<?xml version="1.0" encoding="UTF-8"?>459<tags>460 <tag id="1" name="defect"/>461 <tag id="2" name="enhancement"/>462</tags>463XML;464 $xmlResponse = Xml::fromArray($xml, ['pretty' => true, 'format' => 'attributes']);465 $this->assertTextEquals($expected, $xmlResponse->asXML());466 }467 /**468 * data provider for fromArray() failures469 *470 * @return array471 */472 public static function invalidArrayDataProvider()473 {474 return [475 [''],476 [null],477 [false],478 [[]],479 [['numeric key as root']],480 [['item1' => '', 'item2' => '']],481 [['items' => ['item1', 'item2']]],482 [[483 'tags' => [484 'tag' => [485 [486 [487 'string'488 ]489 ]490 ]491 ]492 ]],493 [[494 'tags' => [495 '@tag' => [496 [497 '@id' => '1',498 'name' => 'defect'499 ],500 [501 '@id' => '2',502 'name' => 'enhancement'503 ]504 ]505 ]506 ]],507 [new \DateTime()]508 ];509 }510 /**511 * testFromArrayFail method512 *513 * @dataProvider invalidArrayDataProvider514 * @expectedException \Exception515 * @return void516 */517 public function testFromArrayFail($value)518 {519 Xml::fromArray($value);520 }521 /**522 * Test that there are not unterminated errors when building xml523 *524 * @return void525 */526 public function testFromArrayUnterminatedError()527 {528 $data = [529 'product_ID' => 'GENERT-DL',530 'deeplink' => 'http://example.com/deep',531 'image_URL' => 'http://example.com/image',532 'thumbnail_image_URL' => 'http://example.com/thumb',533 'brand' => 'Malte Lange & Co',534 'availability' => 'in stock',535 'authors' => [536 'author' => ['Malte Lange & Co']537 ]538 ];539 $xml = Xml::fromArray(['products' => $data], 'tags');540 $expected = <<<XML541<?xml version="1.0" encoding="UTF-8"?>542<products>543 <product_ID>GENERT-DL</product_ID>544 <deeplink>http://example.com/deep</deeplink>545 <image_URL>http://example.com/image</image_URL>546 <thumbnail_image_URL>http://example.com/thumb</thumbnail_image_URL>547 <brand>Malte Lange &amp; Co</brand>548 <availability>in stock</availability>549 <authors>550 <author>Malte Lange &amp; Co</author>551 </authors>552</products>553XML;554 $this->assertXmlStringEqualsXmlString($expected, $xml->asXML());555 }556 /**557 * testToArray method558 *559 * @return void560 */561 public function testToArray()562 {563 $xml = '<tag>name</tag>';564 $obj = Xml::build($xml);565 $this->assertEquals(['tag' => 'name'], Xml::toArray($obj));566 $xml = CORE_TESTS . 'Fixture/sample.xml';567 $obj = Xml::build($xml);568 $expected = [569 'tags' => [570 'tag' => [571 [572 '@id' => '1',573 'name' => 'defect'574 ],575 [576 '@id' => '2',577 'name' => 'enhancement'578 ]579 ]580 ]581 ];582 $this->assertEquals($expected, Xml::toArray($obj));583 $array = [584 'tags' => [585 'tag' => [586 [587 'id' => '1',588 'name' => 'defect'589 ],590 [591 'id' => '2',592 'name' => 'enhancement'593 ]594 ]595 ]596 ];597 $this->assertEquals(Xml::toArray(Xml::fromArray($array, 'tags')), $array);598 $expected = [599 'tags' => [600 'tag' => [601 [602 '@id' => '1',603 '@name' => 'defect'604 ],605 [606 '@id' => '2',607 '@name' => 'enhancement'608 ]609 ]610 ]611 ];612 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, 'attributes')));613 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, ['return' => 'domdocument', 'format' => 'attributes'])));614 $this->assertEquals(Xml::toArray(Xml::fromArray($array)), $array);615 $this->assertEquals(Xml::toArray(Xml::fromArray($array, ['return' => 'domdocument'])), $array);616 $array = [617 'tags' => [618 'tag' => [619 'id' => '1',620 'posts' => [621 ['id' => '1'],622 ['id' => '2']623 ]624 ],625 'tagOther' => [626 'subtag' => [627 'id' => '1'628 ]629 ]630 ]631 ];632 $expected = [633 'tags' => [634 'tag' => [635 '@id' => '1',636 'posts' => [637 ['@id' => '1'],638 ['@id' => '2']639 ]640 ],641 'tagOther' => [642 'subtag' => [643 '@id' => '1'644 ]645 ]646 ]647 ];648 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, 'attributes')));649 $this->assertEquals($expected, Xml::toArray(Xml::fromArray($array, ['format' => 'attributes', 'return' => 'domdocument'])));650 $xml = <<<XML651<root>652<tag id="1">defect</tag>653</root>654XML;655 $obj = Xml::build($xml);656 $expected = [657 'root' => [658 'tag' => [659 '@id' => 1,660 '@' => 'defect'661 ]662 ]663 ];664 $this->assertEquals($expected, Xml::toArray($obj));665 $xml = <<<XML666<root>667 <table xmlns="http://www.w3.org/TR/html4/"><tr><td>Apples</td><td>Bananas</td></tr></table>668 <table xmlns="http://www.cakephp.org"><name>CakePHP</name><license>MIT</license></table>669 <table>The book is on the table.</table>670</root>671XML;672 $obj = Xml::build($xml);673 $expected = [674 'root' => [675 'table' => [676 ['tr' => ['td' => ['Apples', 'Bananas']]],677 ['name' => 'CakePHP', 'license' => 'MIT'],678 'The book is on the table.'679 ]680 ]681 ];682 $this->assertEquals($expected, Xml::toArray($obj));683 $xml = <<<XML684<root xmlns:cake="http://www.cakephp.org/">685<tag>defect</tag>686<cake:bug>1</cake:bug>687</root>688XML;689 $obj = Xml::build($xml);690 $expected = [691 'root' => [692 'tag' => 'defect',693 'cake:bug' => 1694 ]695 ];696 $this->assertEquals($expected, Xml::toArray($obj));697 $xml = '<tag type="myType">0</tag>';698 $obj = Xml::build($xml);699 $expected = [700 'tag' => [701 '@type' => 'myType',702 '@' => 0703 ]704 ];705 $this->assertEquals($expected, Xml::toArray($obj));706 }707 /**708 * testRss709 *710 * @return void711 */712 public function testRss()713 {714 $rss = file_get_contents(CORE_TESTS . 'Fixture/rss.xml');715 $rssAsArray = Xml::toArray(Xml::build($rss));716 $this->assertEquals('2.0', $rssAsArray['rss']['@version']);717 $this->assertEquals(2, count($rssAsArray['rss']['channel']['item']));718 $atomLink = ['@href' => 'http://bakery.cakephp.org/articles/rss', '@rel' => 'self', '@type' => 'application/rss+xml'];719 $this->assertEquals($rssAsArray['rss']['channel']['atom:link'], $atomLink);720 $this->assertEquals('http://bakery.cakephp.org/', $rssAsArray['rss']['channel']['link']);721 $expected = [722 'title' => 'Alertpay automated sales via IPN',723 'link' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn',724 'description' => 'I\'m going to show you how I implemented a payment module via the Alertpay payment processor.',725 'pubDate' => 'Tue, 31 Aug 2010 01:42:00 -0500',726 'guid' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn'727 ];728 $this->assertSame($expected, $rssAsArray['rss']['channel']['item'][1]);729 $rss = [730 'rss' => [731 'xmlns:atom' => 'http://www.w3.org/2005/Atom',732 '@version' => '2.0',733 'channel' => [734 'atom:link' => [735 '@href' => 'http://bakery.cakephp.org/articles/rss',736 '@rel' => 'self',737 '@type' => 'application/rss+xml'738 ],739 'title' => 'The Bakery: ',740 'link' => 'http://bakery.cakephp.org/',741 'description' => 'Recent Articles at The Bakery.',742 'pubDate' => 'Sun, 12 Sep 2010 04:18:26 -0500',743 'item' => [744 [745 'title' => 'CakePHP 1.3.4 released',746 'link' => 'http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released'747 ],748 [749 'title' => 'Wizard Component 1.2 Tutorial',750 'link' => 'http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial'751 ]752 ]753 ]754 ]755 ];756 $rssAsSimpleXML = Xml::fromArray($rss);757 $xmlText = <<<XML758<?xml version="1.0" encoding="UTF-8"?>759<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">760 <channel>761 <atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml"/>762 <title>The Bakery: </title>763 <link>http://bakery.cakephp.org/</link>764 <description>Recent Articles at The Bakery.</description>765 <pubDate>Sun, 12 Sep 2010 04:18:26 -0500</pubDate>766 <item>767 <title>CakePHP 1.3.4 released</title>768 <link>http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released</link>769 </item>770 <item>771 <title>Wizard Component 1.2 Tutorial</title>772 <link>http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial</link>773 </item>774 </channel>775</rss>776XML;777 $this->assertXmlStringEqualsXmlString($xmlText, $rssAsSimpleXML->asXML());778 }779 /**780 * testXmlRpc781 *782 * @return void783 */784 public function testXmlRpc()785 {786 $xml = Xml::build('<methodCall><methodName>test</methodName><params /></methodCall>');787 $expected = [788 'methodCall' => [789 'methodName' => 'test',790 'params' => ''791 ]792 ];793 $this->assertSame($expected, Xml::toArray($xml));794 $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>');795 $expected = [796 'methodCall' => [797 'methodName' => 'test',798 'params' => [799 'param' => [800 'value' => [801 'array' => [802 'data' => [803 'value' => [804 ['int' => '12'],805 ['string' => 'Egypt'],806 ['boolean' => '0'],807 ['int' => '-31']808 ]809 ]810 ]811 ]812 ]813 ]814 ]815 ];816 $this->assertSame($expected, Xml::toArray($xml));817 $xmlText = <<<XML818<?xml version="1.0" encoding="UTF-8"?>819<methodResponse>820 <params>821 <param>822 <value>823 <array>824 <data>825 <value>826 <int>1</int>827 </value>828 <value>829 <string>testing</string>830 </value>831 </data>832 </array>833 </value>834 </param>835 </params>836</methodResponse>837XML;838 $xml = Xml::build($xmlText);839 $expected = [840 'methodResponse' => [841 'params' => [842 'param' => [843 'value' => [844 'array' => [845 'data' => [846 'value' => [847 ['int' => '1'],848 ['string' => 'testing']849 ]850 ]851 ]852 ]853 ]854 ]855 ]856 ];857 $this->assertSame($expected, Xml::toArray($xml));858 $xml = Xml::fromArray($expected, 'tags');859 $this->assertXmlStringEqualsXmlString($xmlText, $xml->asXML());860 }861 /**862 * testSoap863 *864 * @return void865 */866 public function testSoap()867 {868 $xmlRequest = Xml::build(CORE_TESTS . 'Fixture/soap_request.xml');869 $expected = [870 'Envelope' => [871 '@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',872 'soap:Body' => [873 'm:GetStockPrice' => [874 'm:StockName' => 'IBM'875 ]876 ]877 ]878 ];879 $this->assertEquals($expected, Xml::toArray($xmlRequest));880 $xmlResponse = Xml::build(CORE_TESTS . DS . 'Fixture/soap_response.xml');881 $expected = [882 'Envelope' => [883 '@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',884 'soap:Body' => [885 'm:GetStockPriceResponse' => [886 'm:Price' => '34.5'887 ]888 ]889 ]890 ];891 $this->assertEquals($expected, Xml::toArray($xmlResponse));892 $xml = [893 'soap:Envelope' => [894 'xmlns:soap' => 'http://www.w3.org/2001/12/soap-envelope',895 '@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',896 'soap:Body' => [897 'xmlns:m' => 'http://www.example.org/stock',898 'm:GetStockPrice' => [899 'm:StockName' => 'IBM'900 ]901 ]902 ]903 ];904 $xmlRequest = Xml::fromArray($xml, ['encoding' => null]);905 $xmlText = <<<XML906<?xml version="1.0"?>907<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">908 <soap:Body xmlns:m="http://www.example.org/stock">909 <m:GetStockPrice>910 <m:StockName>IBM</m:StockName>911 </m:GetStockPrice>912 </soap:Body>913</soap:Envelope>914XML;915 $this->assertXmlStringEqualsXmlString($xmlText, $xmlRequest->asXML());916 }917 /**918 * testNamespace919 *920 * @return void921 */922 public function testNamespace()923 {924 $xml = <<<XML925<root xmlns:ns="http://cakephp.org">926 <ns:tag id="1">927 <child>good</child>928 <otherchild>bad</otherchild>929 </ns:tag>930 <tag>Tag without ns</tag>931</root>932XML;933 $xmlResponse = Xml::build($xml);934 $expected = [935 'root' => [936 'ns:tag' => [937 '@id' => '1',938 'child' => 'good',939 'otherchild' => 'bad'940 ],941 'tag' => 'Tag without ns'942 ]943 ];944 $this->assertEquals($expected, Xml::toArray($xmlResponse));945 $xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:tag id="1" /><tag><id>1</id></tag></root>');946 $expected = [947 'root' => [948 'ns:tag' => [949 '@id' => '1'950 ],951 'tag' => [952 'id' => '1'953 ]954 ]955 ];956 $this->assertEquals($expected, Xml::toArray($xmlResponse));957 $xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:attr>1</ns:attr></root>');958 $expected = [959 'root' => [960 'ns:attr' => '1'961 ]962 ];963 $this->assertEquals($expected, Xml::toArray($xmlResponse));964 $xmlResponse = Xml::build('<root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>');965 $this->assertEquals($expected, Xml::toArray($xmlResponse));966 $xml = [967 'root' => [968 'ns:attr' => [969 'xmlns:ns' => 'http://cakephp.org',970 '@' => 1971 ]972 ]973 ];974 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>';975 $xmlResponse = Xml::fromArray($xml);976 $this->assertEquals($expected, str_replace(["\r", "\n"], '', $xmlResponse->asXML()));977 $xml = [978 'root' => [979 'tag' => [980 'xmlns:pref' => 'http://cakephp.org',981 'pref:item' => [982 'item 1',983 'item 2'984 ]985 ]986 ]987 ];988 $expected = <<<XML989<?xml version="1.0" encoding="UTF-8"?>990<root>991 <tag xmlns:pref="http://cakephp.org">992 <pref:item>item 1</pref:item>993 <pref:item>item 2</pref:item>994 </tag>995</root>996XML;997 $xmlResponse = Xml::fromArray($xml);998 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());999 $xml = [1000 'root' => [1001 'tag' => [1002 'xmlns:' => 'http://cakephp.org'1003 ]1004 ]1005 ];1006 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns="http://cakephp.org"/></root>';1007 $xmlResponse = Xml::fromArray($xml);1008 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1009 $xml = [1010 'root' => [1011 'xmlns:' => 'http://cakephp.org'1012 ]1013 ];1014 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns="http://cakephp.org"/>';1015 $xmlResponse = Xml::fromArray($xml);1016 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1017 $xml = [1018 'root' => [1019 'xmlns:ns' => 'http://cakephp.org'1020 ]1021 ];1022 $expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns:ns="http://cakephp.org"/>';1023 $xmlResponse = Xml::fromArray($xml);1024 $this->assertXmlStringEqualsXmlString($expected, $xmlResponse->asXML());1025 }1026 /**1027 * test that CDATA blocks don't get screwed up by SimpleXml1028 *1029 * @return void1030 */1031 public function testCdata()1032 {1033 $xml = '<' . '?xml version="1.0" encoding="UTF-8"?>' .1034 '<people><name><![CDATA[ Mark ]]></name></people>';1035 $result = Xml::build($xml);1036 $this->assertEquals(' Mark ', (string)$result->name);1037 }...

Full Screen

Full Screen

Manager.php

Source:Manager.php Github

copy

Full Screen

...29 'name' => 'Manager',30 'namespacename' => $this->data['_namespace'] . '\Table',31 'extendedclass' => $this->useTableGatewayClass,32 'flags' => ClassGenerator::FLAG_ABSTRACT,33 'docblock' => DocBlockGenerator::fromArray(34 [35 'shortDescription' => 'Application Model DbTables',36 'longDescription' => null,37 'tags' => [38 [39 'name' => 'package',40 'description' => $this->data['_namespace'],41 ],42 [43 'name' => 'author',44 'description' => $this->data['_author'],45 ],46 [47 'name' => 'copyright',48 'description' => $this->data['_copyright'],49 ],50 [51 'name' => 'license',52 'description' => $this->data['_license'],53 ],54 ],55 ]56 ),57 'properties' => [58 ['entity', null, PropertyGenerator::FLAG_PROTECTED],59 ['container', null, PropertyGenerator::FLAG_PROTECTED],60 ['debug', false, PropertyGenerator::FLAG_PROTECTED],61 PropertyGenerator::fromArray(62 [63 'name' => 'wasInTransaction',64 'defaultvalue' => false,65 'flags' => PropertyGenerator::FLAG_PROTECTED,66 'docblock' => DocBlockGenerator::fromArray(67 [68 'shortDescription' => 'True if we were already in a transaction when try to start a new one',69 'longDescription' => '',70 'tags' => [71 new GenericTag('var', 'bool'),72 ],73 ]74 ),75 ]76 ),77 ],78 'methods' => [79 [80 'name' => '__construct',81 'parameters' => [82 ParameterGenerator::fromArray(83 [84 'name' => 'adapter',85 //'type' => 'Adapter',86 ]87 ),88 ParameterGenerator::fromArray(89 [90 'name' => 'entity',91 'type' => $this->data['_namespace'] . '\Entity\Entity',92 ]93 ),94 ],95 'flags' => MethodGenerator::FLAG_PUBLIC,96 'body' =>97 '$this->adapter = $adapter;' . "\n" .98 '$this->entity = $entity;' . "\n" .99 '$this->featureSet = new Feature\FeatureSet();' . "\n" .100 '$this->initialize();',101 'docblock' => DocBlockGenerator::fromArray(102 [103 'shortDescription' => 'Constructor',104 'longDescription' => null,105 'tags' => [106 new ParamTag('adapter', ['Adapter']),107 new ParamTag('entity', [$this->data['_namespace'] . '\Entity\Entity']),108 ],109 ]110 ),111 ],112 [113 'name' => 'setDebug',114 'parameters' => [115 ParameterGenerator::fromArray(116 [117 'type' => 'bool',118 'name' => 'debug',119 'defaultvalue' => true,120 ]121 ),122 ],123 'flags' => MethodGenerator::FLAG_PUBLIC,124 'body' =>125 '$this->debug = $debug;' . "\n" .126 'return $this;',127 'docblock' => DocBlockGenerator::fromArray(128 [129 'shortDescription' => 'Set debug mode',130 'longDescription' => null,131 'tags' => [132 new ParamTag('debug', ['boolean']),133 new ReturnTag([134 'datatype' => 'self',135 ]),136 ],137 ]138 ),139 ],140 [141 'name' => 'setContainer',142 'parameters' => [143 ParameterGenerator::fromArray(144 [145 'name' => 'c',146 'type' => 'Pimple\Container',147 ]148 ),149 ],150 'flags' => MethodGenerator::FLAG_PUBLIC,151 'body' =>152 '$this->container = $c;' . "\n" .153 'return $this;',154 'docblock' => DocBlockGenerator::fromArray(155 [156 'shortDescription' => 'Inject container',157 'longDescription' => null,158 'tags' => [159 new ParamTag('c', ['Pimple\Container']),160 new ReturnTag([161 'datatype' => 'self',162 ]),163 ],164 ]165 ),166 ],167 [168 'name' => 'getContainer',169 'parameters' => [],170 'flags' => MethodGenerator::FLAG_PUBLIC,171 'body' => 'return $this->container;',172 'docblock' => DocBlockGenerator::fromArray(173 [174 'shortDescription' => '',175 'longDescription' => null,176 'tags' => [177 new ReturnTag([178 'datatype' => '\Pimple\Container',179 ]),180 ],181 ]182 ),183 ],184 [185 'name' => 'getPrimaryKeyName',186 'parameters' => [],187 'flags' => MethodGenerator::FLAG_PUBLIC,188 'body' => 'return $this->id;',189 'docblock' => DocBlockGenerator::fromArray(190 [191 'shortDescription' => '',192 'longDescription' => null,193 'tags' => [194 new ReturnTag([195 'datatype' => 'array|string',196 ]),197 ],198 ]199 ),200 ],201 [202 'name' => 'getTableName',203 'parameters' => [],204 'flags' => MethodGenerator::FLAG_PUBLIC,205 'body' => 'return $this->table;',206 'docblock' => DocBlockGenerator::fromArray(207 [208 'shortDescription' => '',209 'longDescription' => null,210 'tags' => [211 new ReturnTag([212 'datatype' => 'array|string',213 ]),214 ],215 ]216 ),217 ],218 [219 'name' => 'findBy',220 'parameters' => [221 ParameterGenerator::fromArray([222 'name' => 'criteria',223 'defaultvalue' => [],224 'type' => 'array',225 ]),226 ParameterGenerator::fromArray([227 'name' => 'order',228 'defaultvalue' => null,229 ]),230 ParameterGenerator::fromArray([231 'type' => 'int',232 'name' => 'limit',233 'defaultvalue' => null,234 ]),235 ParameterGenerator::fromArray([236 'type' => 'int',237 'name' => 'offset',238 'defaultvalue' => null,239 ]),240 ParameterGenerator::fromArray([241 'type' => 'bool',242 'name' => 'toEntity',243 'defaultvalue' => false,244 ]),245 ],246 'flags' => MethodGenerator::FLAG_PUBLIC,247 'body' => '$select = $this->sql->select();' . PHP_EOL .248 '$select->where($criteria);' . PHP_EOL .249 'if ($order) {' . PHP_EOL .250 ' $select->order($order);' . PHP_EOL .251 '}' . PHP_EOL .252 'if ($limit) {' . PHP_EOL .253 ' $select->limit($limit);' . PHP_EOL .254 '}' . PHP_EOL .255 'if ($offset) {' . PHP_EOL .256 ' $select->offset($offset);' . PHP_EOL .257 '}' . PHP_EOL .258 '$result = $this->selectWith($select)->toArray();' . PHP_EOL .259 'if ($toEntity) {' . PHP_EOL .260 ' foreach($result as &$v){' . PHP_EOL .261 ' $entity = clone $this->entity;' . PHP_EOL .262 ' $v = $entity->exchangeArray($v);' . PHP_EOL .263 ' }' . PHP_EOL .264 '}' . PHP_EOL .265 'return $result;' . PHP_EOL,266 'docblock' => DocBlockGenerator::fromArray(267 [268 'shortDescription' => 'Find by criteria',269 'longDescription' => null,270 'tags' => [271 new ParamTag('criteria', ['array'], 'Search criteria'),272 new ParamTag('order', ['string'], 'sorting option'),273 new ParamTag('limit', ['int'], 'limit option'),274 new ParamTag('offset', ['int'], 'offset option'),275 new ParamTag('toEntity', ['boolean'], 'return entity result'),276 new ReturnTag(['array'], ''),277 ],278 ]279 ),280 ],281 [282 'name' => 'getResult',283 'parameters' => [284 ParameterGenerator::fromArray([285 'name' => 'columns',286 'type' => 'array',287 ]),288 ParameterGenerator::fromArray([289 'type' => 'array',290 'name' => 'join',291 'defaultvalue' => [],292 ]),293 ParameterGenerator::fromArray([294 'type' => 'array',295 'name' => 'where',296 'defaultvalue' => [],297 ]),298 ParameterGenerator::fromArray([299 'type' => 'array',300 'name' => 'orderBy',301 'defaultvalue' => [],302 ]),303 ParameterGenerator::fromArray([304 'name' => 'groupBy',305 'defaultvalue' => [],306 ]),307 ParameterGenerator::fromArray([308 'type' => 'array',309 'name' => 'having',310 'defaultvalue' => [],311 ]),312 ParameterGenerator::fromArray([313 'type' => 'int',314 'name' => 'limit',315 'defaultvalue' => null,316 ]),317 ParameterGenerator::fromArray([318 'type' => 'int',319 'name' => 'offset',320 'defaultvalue' => null,321 ]),322 ],323 'flags' => MethodGenerator::FLAG_PROTECTED,324 'body' => <<<'BODY'325$select = $this->sql->select();326 $select->columns($columns);327 foreach ($join as $j) {328 $select->join($j['name'], $j['on'], $j['columns'], $j['type']);329 }330 foreach ($where as $w) {331 $select->where($w);332 }333 foreach ($orderBy as $o) {334 $select->order($o);335 }336 foreach ($groupBy as $g) {337 $select->group($g);338 }339 foreach ($having as $h) {340 $select->having($h);341 }342 if ($limit) {343 $select->limit($limit);344 }345 if ($offset) {346 $select->offset($offset);347 }348 return $this->selectWith($select)->toArray();349BODY350 ,351 'docblock' =>DocBlockGenerator::fromArray(352 [353 'shortDescription'=>'Manage params of sql request and return results',354 'longDescription' =>null,355 'tags' =>[356 new ParamTag('columns',['array'],''),357 new ParamTag('join',['array'],''),358 new ParamTag('where',['array'],''),359 new ParamTag('orderBy',['array'],''),360 new ParamTag('groupBy',['array'],''),361 new ParamTag('having',['array'],''),362 new ParamTag('limit',['int'],''),363 new ParamTag('offset',['int'],''),364 new ReturnTag(['array','null'],'Found results'),365 ],366 ]367 )368 ],369 [370 'name' =>'countBy',371 'parameters'=>[372 ParameterGenerator::fromArray([373 'name' =>'criteria',374 'defaultvalue'=>[],375 'type' =>'array',376 ]),377 ],378 'flags' =>MethodGenerator::FLAG_PUBLIC,379 'body' =>'$r = $this->sql->select()->columns(array("count" => new Expression("count(*)")))->where($criteria);'.PHP_EOL.380 'return (int)current($this->selectWith($r)->toArray())["count"];'.PHP_EOL,381 'docblock' =>DocBlockGenerator::fromArray(382 [383 'shortDescription'=>'Count by criteria',384 'longDescription' =>null,385 'tags' =>[386 new ParamTag('criteria',['array'],'Criteria'),387 new ReturnTag(['int'],''),388 ],389 ]390 ),391 ],392 [393 'name' =>'exists',394 'parameters'=>[395 ParameterGenerator::fromArray([396 'name' =>'criteria',397 'defaultvalue'=>[],398 'type' =>'array',399 ]),400 ],401 'flags' =>MethodGenerator::FLAG_PUBLIC,402 'body' =>'$r = $this->sql->select()->where($criteria);'.PHP_EOL.403 '$r->limit(1);'.PHP_EOL.404 '$result = $this->selectWith($r);'.PHP_EOL.PHP_EOL.405 'return $result->count() === 1;',406 'docblock' =>DocBlockGenerator::fromArray(407 [408 'shortDescription'=>'Is a least one row exists with criteria',409 'longDescription' =>null,410 'tags' =>[411 new ParamTag('criteria',['array'],'Criteria'),412 new ReturnTag(['bool'],''),413 ],414 ]415 ),416 ],417 [418 'name' =>'deleteEntity',419 'parameters'=>[420 ParameterGenerator::fromArray(421 [422 'name'=>'entity',423 'type'=>$this->data['_namespace'].'\Entity\Entity',424 ]425 ),426 ParameterGenerator::fromArray([427 'type' =>'bool',428 'name' =>'useTransaction',429 'defaultValue'=>true,430 ]),431 ],432 'flags' =>[MethodGenerator::FLAG_PUBLIC,MethodGenerator::FLAG_ABSTRACT],433 'body' =>null,434 'docblock' =>DocBlockGenerator::fromArray(435 [436 'shortDescription'=>'Converts database column name to php setter/getter function name',437 'longDescription' =>null,438 'tags' =>[439 new ParamTag('entity',[$this->data['_namespace'].'\Entity\Entity']),440 new ParamTag('useTransaction',['boolean']),441 new ReturnTag([442 'datatype'=>'int',443 ]),444 ],445 ]446 ),447 ],448 [449 'name' =>'beginTransaction',450 'parameters'=>[],451 'flags' =>MethodGenerator::FLAG_PUBLIC,452 'body' =><<<'BODY'453if ($this->adapter->getDriver()->getConnection()->inTransaction()) {454 $this->wasInTransaction = true;455 return;456}457$this->adapter->getDriver()->getConnection()->beginTransaction();458BODY459 ,460 'docblock' =>DocBlockGenerator::fromArray(461 [462 'shortDescription'=>'Begin a transaction',463 'longDescription' =>null,464 'tags' =>[],465 ]466 )467 ],468 [469 'name' =>'rollback',470 'parameters'=>[],471 'flags' =>MethodGenerator::FLAG_PUBLIC,472 'body' =><<<'BODY'473if ($this->wasInTransaction) {474 throw new \Exception('Inside transaction rollback call');475}476$this->adapter->getDriver()->getConnection()->rollback();477BODY478 ,479 'docblock' =>DocBlockGenerator::fromArray(480 [481 'shortDescription'=>'Rollback a transaction',482 'longDescription' =>null,483 'tags' =>[],484 ]485 )486 ],487 [488 'name' =>'commit',489 'parameters'=>[],490 'flags' =>MethodGenerator::FLAG_PUBLIC,491 'body' =><<<'BODY'492if (!$this->wasInTransaction) {493 $this->adapter->getDriver()->getConnection()->commit();494}495BODY496 ,497 'docblock' =>DocBlockGenerator::fromArray(498 [499 'shortDescription'=>' Commit a transaction',500 'longDescription' =>null,501 'tags' =>[],502 ]503 )504 ],505 [506 'name' =>'selectWith',507 'parameters'=>[508 ParameterGenerator::fromArray([509 'name'=>'select',510 'type'=>'Laminas\Db\Sql\Select',511 ]),512 ],513 'flags' =>MethodGenerator::FLAG_PUBLIC,514 'body' =><<<'BODY'515 if ($this->debug) {516 !isset($this->getContainer()['logger']) ? : $this->getContainer()['logger']->debug('debug.sql', ['extra'=>[517 'class'=> __CLASS__,518 'function'=> __FUNCTION__,519 'sql' => $select->getSqlString($this->getAdapter()->getPlatform())520 ]]);521 }522 try {523 return parent::selectWith($select);524 } catch(\Exception $e){525 !isset($this->getContainer()['logger']) ? : $this->getContainer()['logger']->error($e->getMessage(), ['extra'=>[526 'class'=> __CLASS__,527 'function'=> __FUNCTION__,528 'sql' => $select->getSqlString($this->getAdapter()->getPlatform())529 ]]);530 return (new ResultSet())->initialize([]);531 }532BODY533 ,534 'docblock' =>DocBlockGenerator::fromArray(535 [536 'shortDescription'=>' @see Laminas\Db\TableGateway\AbstractTableGateway::selectWith',537 'longDescription' =>null,538 'tags' =>[539 new ParamTag('select',['Laminas\Db\Sql\Select']),540 new ReturnTag([541 'datatype'=>'ResultSet',542 ]),543 ],544 ]545 ),546 ],547 [548 'name' =>'findOneBy',549 'parameters'=>[550 ParameterGenerator::fromArray([551 'name' =>'criteria',552 'defaultvalue'=>[],553 'type' =>'array',554 ]),555 ParameterGenerator::fromArray([556 'name' =>'order',557 'defaultvalue'=>null,558 ]),559 ],560 'flags' =>MethodGenerator::FLAG_PUBLIC,561 'body' =>'return current($this->findBy($criteria,$order,1));',562 'docblock' =>DocBlockGenerator::fromArray(563 [564 'shortDescription'=>'Find one by criteria',565 'longDescription' =>null,566 'tags' =>[567 new ParamTag('criteria',['array'],'Search criteria'),568 new ReturnTag(['array|boolean'],''),569 ],570 ]571 ),572 ],573 [574 'name' =>'findOneEntityBy',575 'parameters'=>[576 ParameterGenerator::fromArray([577 'name' =>'criteria',578 'defaultvalue'=>[],579 'type' =>'array',580 ]),581 ParameterGenerator::fromArray([582 'name' =>'order',583 'defaultvalue'=>null,584 ]),585 ],586 'flags' =>MethodGenerator::FLAG_PUBLIC,587 'body' =>'return current($this->findBy($criteria,$order,1,null,true));',588 'docblock' =>DocBlockGenerator::fromArray(589 [590 'shortDescription'=>'Find Entity one by criteria',591 'longDescription' =>null,592 'tags' =>[593 new ParamTag('criteria',['array'],'Search criteria'),594 new ReturnTag(['boolean|Entity'],''),595 ],596 ]597 ),598 ],599 ],600 ];601 }602 public function generate()603 {604 $class = ClassGenerator::fromArray($this->getClassArrayRepresentation());605 $class->addUse($this->useTableGatewayClass)606 ->addUse('Laminas\Db\TableGateway\Feature')607 ->addUse('Laminas\Db\Sql\Expression')608 ->addUse($this->data['_namespace'] . '\Entity\Entity')609 ->addUse('Laminas\Db\Adapter\Adapter')610 ->addUse('Laminas\Db\ResultSet\ResultSet');611 $this->defineFileInfo($class);612 $fileGenerator = $this->getFileGenerator();613 return $fileGenerator614 ->setClass($class)615 ->generate();616 }617 /**618 * @param string $tableGatewayClass...

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$tag = new Tag;2$tag->fromArray($data);3$tag->save();4$user = new User;5$user->fromArray($data);6$user->save();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$tag = new Tag();2$tag->fromArray(array("name" => "test", "id" => 1));3$tag = new Tag();4$tag->fromArray(array("name" => "test", "id" => 1));5$tag = new Tag();6$tag->fromArray(array("name" => "test", "id" => 1));7$tag = new Tag();8$tag->fromArray(array("name" => "test", "id" => 1));9$tag = new Tag();10$tag->fromArray(array("name" => "test", "id" => 1));11$tag = new Tag();12$tag->fromArray(array("name" => "test", "id" => 1));13$tag = new Tag();14require_once 'Tag.php';15$tag g new Tag();16echo $tag->name;romArray(array("name" => "test", "id" => 1));17echo $tag->description;18require_once 'Tag.php';19echo $tag->name;20echo $tag->url;21echo $tag->description;22require_once 'Tag.php';23$tag = new Tag();24echo $tag->name;25echo $tag->url;26echo $tag->description;27require_once 'Tag.php';28$tag = new Tag();29echo $tag->name;30echo $tag->url;31echo $tag->description;32require_once 'Tag.php';33$tag = new Tag();34echo $tag->name;35echo $tag->url;

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$tagArray = array("name"=>"myTag",2"attributes"=>array("id"=>"myId","class"=>"myClass"),3"content"=>"myContent");4$tag = new Tag();5$tag->fromArray($tagArray);6echo $tag->toHTML();7$tagArray = array("name"=>"myTag",8"attributes"=>array("id"=>"myId","class"=>"myClass"),9"content"=>"myContent");10$tag = new Tag();11$tag->fromArray($tagArray);12echo $tag->toHTML();13$tagArray = array("name"=>"myTag",14"attributes"=>array("id"=>"myId","class"=>"myClass"),15"content"=>"myContent");16$tag = new Tag();17$tag->fromArray($tagArray);18echo $tag->toHTML();19$tagArray = array("name"=>"myTag",20"attributes"=>array("id"=>"myId","class"=>"myClass"),21"content"=>"myContent");22$tag = new Tag();23$tag->fromArray($tagArray);24echo $tag->toHTML();25$tagArray = array("name"=>"myTag",26"attributes"=>array("id"=>"myId","class"=>"myClass"),27"content"=>"myContent");28$tag = new Tag();29$tag->fromArray($tagArray);30echo $tag->toHTML();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$tagArray = array("nam"=>"myTag",2"attributes"=>array("id"=>"myId","class"=>"myClass",3$tag = new Tag();4$tag->fromArray($tagArray);5echo $tag->toHTML();6Array = array("name"=>"myTag",7"attributes"=>array("id"=>"myId","class"=>"myClass"),8"content"=>"myContent");9$tag = new Tag();10$tag->fromArray($tagArray);11echo $tag->toHTML();12$tagArray = array("name"=>"myTag",13"attributes"=>array("id"=>"myId","class"=>"myClass"),14"content"=>"myContent");15$tag = new Tag();16$tag->fromArray($tagArray);17echo $tag->toHTML();18$tagArray = array("name"=>"myTag",19"attributes"=>array("id"=>"myId","class"=>"myClass"),20"content"=>"myContent");21$tag = new Tag();22$tag->fromArray($tagArray);23echo $tag->toHTML();24$tagArray = array("name"=>"myTag",25"attributes"=>array("id"=>"myId","class"=>"myClass"),26"content"=>"myContent");27$tag = new Tag();28$tag->fromArray($tagArray);29echo $tag->toHTML();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1require_once 'Tag.php';2$tag = new Tag();3echo $tag->name;4echo $tag->url;5echo $tag->description;6require_once 'Tag.php';7$tag = new Tag();8echo $tag->name;9echo $tag->url;10echo $tag->description;11require_once 'Tag.php';12$tag = new Tag();13echo $tag->name;14echo $tag->url;15echo $tag->description;16require_once 'Tag.php';17$tag = new Tag();18echo $tag->name;19echo $tag->url;20echo $tag->description;21require_once 'Tag.php';22$tag = new Tag();23echo $tag->name;24echo $tag->url;

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cucumber Common Library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger fromArray code on LambdaTest Cloud Grid

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 Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful