/**
  * Tests the progress with one time per iteration.
  */
 public function testProgressWithOneItemPerIteration()
 {
     for ($i = 0; $i <= 100; ++$i) {
         LoopTracker::track('One Item per Iteration Loop Tracker PHPUnit Test', 100);
     }
     // There should be only one finish message.
     $this->assertEquals(1, LoopTracker::getDebugNumFinishMessages(), 'There needs to be only one finish message.');
 }
Example #2
0
 /**
  * Test the progress of the loop counter with multiple items per iteration.
  */
 public function testProgressWithMultipleItemsPerIteration()
 {
     $this->assertEquals(0, LoopTracker::getDebugNumFinishMessages(), "At the beginning of a test, the 'finish\n                                                                            messages number' must be 0.");
     for ($i = 0; $i <= 100; $i += 5) {
         LoopTracker::track('Multiple Items per Iteration Loop Tracker PHPUnit Test', 100, 5);
     }
     // There should be only one finish message.
     $this->assertEquals(1, LoopTracker::getDebugNumFinishMessages(), 'There needs to be only one finish message.');
     $this->assertEquals(100, LoopTracker::getDebugPercentOutputAtTheEnd(), 'There must be 100 percent at the end.');
 }
Example #3
0
 /**
  * This method handles the output in the console.
  *
  * @param $process_name
  * @param $total_num_items
  */
 public static function track($process_name, $total_num_items, $num_items_per_iteration = 1)
 {
     // If the process name changes, an new process tracking begins.
     if ($process_name !== self::$process_name) {
         self::set_new_tracking_process($process_name, $total_num_items, $num_items_per_iteration);
     } else {
         /*
          * It's assumed that a loop starts incrementing the counter "after"
          * the first loop. Like the for-loop starts incrementing after the
          * first execution. F.e.:
          * for ($i = 0; $i <= 100; $i += 5) {
          * "5" is here after the first execution.
          */
         self::increaseIteration();
         // time status
         self::$elapsed_seconds = time() - self::$process_start_timestamp;
         $one_percent_total = $total_num_items / 100;
         $percent_current_output = self::$num_iteration / $one_percent_total;
         self::outputStatusMessage($total_num_items, $percent_current_output);
         /*
          * Send the "finish" message to standard out.
          */
         if (self::$num_iteration >= self::$total_num_items) {
             self::outputFinishMessage();
             static::$debug__num_finish_messages++;
             static::$debug__percent_output_at_the_end = $percent_current_output;
         }
     }
 }