@@ -553,4 +553,44 @@ public function test_set_step_without_total_steps(): void {
553553 $ this ->assertEquals (5 , $ this ->getStep ());
554554 $ this ->assertEquals (0 , $ this ->getLocalProgress ());
555555 }
556+
557+ public function test_to_array (): void {
558+ $ this ->setOverallUniqueName ('test_to_array_ ' .$ this ->testId );
559+ $ this ->setTotalSteps (10 );
560+ $ this ->setStep (5 );
561+ $ this ->setStatusMessage ('Halfway there ' );
562+ $ this ->setMetadata (['foo ' => 'bar ' ]);
563+
564+ $ array = $ this ->toArray ();
565+
566+ $ this ->assertEquals (50.0 , $ array ['progress ' ]);
567+ $ this ->assertEquals (50.0 , $ array ['overall_progress ' ]);
568+ $ this ->assertFalse ($ array ['is_complete ' ]);
569+ $ this ->assertFalse ($ array ['is_overall_complete ' ]);
570+ $ this ->assertNull ($ array ['estimated_time_remaining ' ]);
571+ $ this ->assertEquals ('Halfway there ' , $ array ['message ' ]);
572+ $ this ->assertEquals (['foo ' => 'bar ' ], $ array ['metadata ' ]);
573+ $ this ->assertEquals (10 , $ array ['total_steps ' ]);
574+ $ this ->assertEquals (5 , $ array ['current_step ' ]);
575+ }
576+
577+ public function test_to_array_without_unique_name (): void {
578+ $ this ->progress = 50.0 ;
579+ $ this ->totalSteps = 10 ;
580+ $ this ->currentStep = 5 ;
581+ $ this ->statusMessage = 'Halfway there ' ;
582+ $ this ->metadata = ['foo ' => 'bar ' ];
583+
584+ $ this ->assertEquals ([
585+ 'progress ' => 50.0 ,
586+ 'overall_progress ' => null ,
587+ 'is_complete ' => false ,
588+ 'is_overall_complete ' => null ,
589+ 'estimated_time_remaining ' => null ,
590+ 'message ' => 'Halfway there ' ,
591+ 'metadata ' => ['foo ' => 'bar ' ],
592+ 'total_steps ' => 10 ,
593+ 'current_step ' => 5 ,
594+ ], $ this ->toArray ());
595+ }
556596}
0 commit comments