stub = new ConsoleOutput(); $this->io = new ConsoleIo($this->stub); $this->helper = new ProgressHelper($this->io); } /** * Test that a callback is required. * * @expectedException \RuntimeException */ public function testOutputFailure() { $this->helper->output(['not a callback']); } /** * Test a callback that never reaches 100 fails. * * @return void */ public function testOutputSuccess() { $this->helper->output([function ($progress) { $progress->increment(20); }]); $expected = [ '', '==============> 20%', '', '=============================> 40%', '', '============================================> 60%', '', '===========================================================> 80%', '', '==========================================================================> 100%', ]; $this->assertEquals($expected, $this->stub->messages()); } /** * Test using the helper manually. * * @return void */ public function testIncrementAndRender() { $this->helper->init(); $this->helper->increment(20); $this->helper->draw(); $this->helper->increment(40); $this->helper->draw(); $this->helper->increment(40); $this->helper->draw(); $expected = [ '', '==============> 20%', '', '============================================> 60%', '', '==========================================================================> 100%', ]; $this->assertEquals($expected, $this->stub->messages()); } /** * Test negative numbers * * @return void */ public function testIncrementWithNegatives() { $this->helper->init(); $this->helper->increment(40); $this->helper->draw(); $this->helper->increment(-60); $this->helper->draw(); $this->helper->increment(80); $this->helper->draw(); $expected = [ '', '=============================> 40%', '', ' 0%', '', '===========================================================> 80%', ]; $this->assertEquals($expected, $this->stub->messages()); } }