| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- /**
- * CakePHP : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://cakephp.org CakePHP Project
- * @since 3.1.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Shell\Helper;
- use Cake\Console\ConsoleIo;
- use Cake\Shell\Helper\ProgressHelper;
- use Cake\TestSuite\Stub\ConsoleOutput;
- use Cake\TestSuite\TestCase;
- /**
- * ProgressHelper test.
- */
- class ProgressHelperTest extends TestCase
- {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp()
- {
- parent::setUp();
- $this->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());
- }
- }
|