@@ -569,4 +569,42 @@ public function test_element_assertions(): void {
569569 ->assertElementExistsByTestId ( 'test-item ' )
570570 ->assertQuerySelectorMissing ( '.non-existent-class ' );
571571 }
572+
573+ public function test_it_can_get_the_nearest_previous_sibling (): void {
574+ $ html = new HTML (self ::TEST_CONTENT );
575+ $ previous = $ html ->filter ('#test-id ' )->previous_sibling ();
576+ $ this ->assertInstanceOf (HTML ::class, $ previous );
577+ $ this ->assertEquals ('div ' , $ previous ->nodeName ());
578+ $ this ->assertEquals ('test-class ' , $ previous ->attr ('class ' ));
579+ $ this ->assertEquals ('Example Div By Class ' , $ previous ->text ());
580+ }
581+
582+ public function test_it_can_get_the_nearest_next_sibling (): void {
583+ $ html = new HTML (self ::TEST_CONTENT );
584+ $ next = $ html ->filter ('#test-id ' )->next_sibling ();
585+ $ this ->assertInstanceOf (HTML ::class, $ next );
586+ $ this ->assertEquals ('ul ' , $ next ->nodeName ());
587+ }
588+
589+ public function test_it_returns_empty_crawler_for_missing_next_sibling (): void {
590+ $ html = new HTML (self ::TEST_CONTENT );
591+ $ next = $ html ->filter ('ul ' )->next_sibling ();
592+ $ this ->assertInstanceOf (HTML ::class, $ next );
593+ $ this ->assertEquals (0 , $ next ->count ());
594+ }
595+
596+ public function test_it_can_get_the_nearest_previous_filtered_sibling (): void {
597+ $ html = new HTML (self ::TEST_CONTENT );
598+ $ previous = $ html ->filter ('#test-id ' )->previous_sibling ('section ' );
599+ $ this ->assertInstanceOf (HTML ::class, $ previous );
600+ $ this ->assertEquals ('section ' , $ previous ->nodeName ());
601+ }
602+
603+ public function test_it_can_get_the_nearest_next_filtered_sibling (): void {
604+ $ html = new HTML (self ::TEST_CONTENT );
605+ $ next = $ html ->filter ('section ' )->next_sibling ('ul ' );
606+ $ this ->assertInstanceOf (HTML ::class, $ next );
607+ $ this ->assertEquals ('ul ' , $ next ->nodeName ());
608+ }
609+
572610}
0 commit comments