<?php

include "Manticorp/ProgressUpdater.php";
set_time_limit(600);
$options = array('filename' => __DIR__ . DIRECTORY_SEPARATOR . 'progress.json', 'autoCalc' => True, 'totalStages' => 4);
$pu = new Manticorp\ProgressUpdater($options);
$stageOptions = array('name' => 'Foo 1', 'message' => 'Some Message', 'totalItems' => 100);
$pu->nextStage($stageOptions);
for ($i = 0; $i <= $stageOptions['totalItems']; $i++) {
    usleep(50 * 1000);
    $pu->incrementStageItems(1, true);
}
$stageOptions = array('name' => 'Foo 2', 'message' => 'Another Message', 'totalItems' => 50);
$pu->nextStage($stageOptions);
for ($i = 0; $i <= $stageOptions['totalItems']; $i++) {
    usleep(50 * 1000);
    $pu->incrementStageItems(1, true);
}
$stageOptions = array('name' => 'Spam 1', 'message' => 'This is eggs (check out the messages)', 'totalItems' => 200);
$pu->nextStage($stageOptions);
for ($i = 0; $i <= $stageOptions['totalItems']; $i++) {
    usleep(50 * 1000);
    $pu->setStageMessage("Processing Item {$i}");
    $pu->incrementStageItems(1, true);
}
$stageOptions = array('name' => 'Banana', 'message' => 'Peel', 'totalItems' => 150);
$pu->nextStage($stageOptions);
for ($i = 0; $i <= $stageOptions['totalItems']; $i++) {
    usleep(50 * 1000);
    $pu->incrementStageItems(1, true);
}
<?php

include "Manticorp/ProgressUpdater.php";
set_time_limit(600);
$options = array('filename' => __DIR__ . DIRECTORY_SEPARATOR . 'progress.json', 'autoCalc' => True, 'totalStages' => 1);
$pu = new Manticorp\ProgressUpdater($options);
$stageOptions = array('name' => 'This AJAX process takes a long time', 'message' => 'But this will keep the user updated on it\'s actual progress!', 'totalItems' => 100);
$pu->nextStage($stageOptions);
for ($i = 0; $i <= 100; $i++) {
    usleep(100 * 1000);
    $pu->incrementStageItems(1, True);
}
$pu->totallyComplete();
 /**
  * @test
  * @depends testObjectCreated
  * @depends testMagicSetters
  * @covers ::__call
  */
 public function testCreatesProgressFile()
 {
     // Arrange
     $options = array('lineBreak' => "\n", 'filename' => __DIR__ . DIRECTORY_SEPARATOR . 'testFilenameSetting1.txt', 'totalStages' => 1, 'autocalc' => True);
     $pu = new \Manticorp\ProgressUpdater($options);
     $pu->nextStage();
     $status = json_encode($pu->getStatusArray());
     $this->assertFileExists($options['filename']);
     $this->assertJsonStringEqualsJsonFile($options['filename'], $status);
     unlink($options['filename']);
 }