/**
  * Tests for any exceptions due to invalid calls.
  */
 public function test_exceptions()
 {
     $progress = new core_backup_mock_progress();
     // Check errors when empty.
     try {
         $progress->progress();
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~without start_progress~', $e->getMessage()));
     }
     try {
         $progress->end_progress();
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~without start_progress~', $e->getMessage()));
     }
     try {
         $progress->get_current_description();
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~Not inside progress~', $e->getMessage()));
     }
     try {
         $progress->start_progress('', 1, 7);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~must be 1~', $e->getMessage()));
     }
     // Check invalid start (-2).
     try {
         $progress->start_progress('hello', -2);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~cannot be negative~', $e->getMessage()));
     }
     // Indeterminate when value expected.
     $progress->start_progress('hello', 10);
     try {
         $progress->progress(core_backup_progress::INDETERMINATE);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~expecting value~', $e->getMessage()));
     }
     // Value when indeterminate expected.
     $progress->start_progress('hello');
     try {
         $progress->progress(4);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~expecting INDETERMINATE~', $e->getMessage()));
     }
     // Illegal values.
     $progress->start_progress('hello', 10);
     try {
         $progress->progress(-2);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~out of range~', $e->getMessage()));
     }
     try {
         $progress->progress(11);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~out of range~', $e->getMessage()));
     }
     // You are allowed two with the same value...
     $progress->progress(4);
     $progress->step_time();
     $progress->progress(4);
     $progress->step_time();
     // ...but not to go backwards.
     try {
         $progress->progress(3);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~backwards~', $e->getMessage()));
     }
     // When you go forward, you can't go further than there is room.
     try {
         $progress->start_progress('', 1, 7);
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertEquals(1, preg_match('~would exceed max~', $e->getMessage()));
     }
     // Clear the time limit, otherwise phpunit complains.
     set_time_limit(0);
 }