File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ You can also mount a static facade for the Dom object.
6666PHPHtmlParser\StaticDom::mount();
6767
6868Dom::load('tests/big.hmtl');
69- $objects Dom::find('.content-border');
69+ $objects = Dom::find('.content-border');
7070
7171```
7272
Original file line number Diff line number Diff line change @@ -133,9 +133,21 @@ public function offsetGet($offset)
133133 return isset ($ this ->collection [$ offset ]) ? $ this ->collection [$ offset ] : null ;
134134 }
135135
136+ /**
137+ * Returns this collection as an array.
138+ *
139+ * @return array
140+ */
141+ public function toArray ()
142+ {
143+ return $ this ->collection ;
144+ }
145+
136146 /**
137147 * Similar to jQuery "each" method. Calls the callback with each
138148 * Node in this collection.
149+ *
150+ * @param callback $callback
139151 */
140152 public function each ($ callback )
141153 {
Original file line number Diff line number Diff line change @@ -42,4 +42,23 @@ public function testCallMagic()
4242 $ selector = new Selector ('div * a ' );
4343 $ this ->assertEquals ($ child3 ->id (), $ selector ->find ($ root )->id ());
4444 }
45+
46+ public function testToArray ()
47+ {
48+ $ root = new HtmlNode (new Tag ('root ' ));
49+ $ parent = new HtmlNode (new Tag ('div ' ));
50+ $ child1 = new HtmlNode (new Tag ('a ' ));
51+ $ child2 = new HtmlNode (new Tag ('p ' ));
52+ $ child3 = new HtmlNode (new Tag ('a ' ));
53+ $ root ->addChild ($ parent );
54+ $ parent ->addChild ($ child1 );
55+ $ parent ->addChild ($ child2 );
56+ $ child2 ->addChild ($ child3 );
57+
58+ $ selector = new Selector ('a ' );
59+ $ collection = $ selector ->find ($ root );
60+ $ array = $ collection ->toArray ();
61+ $ lastA = end ($ array );
62+ $ this ->assertEquals ($ child3 ->id (), $ lastA ->id ());
63+ }
4564}
You can’t perform that action at this time.
0 commit comments