Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into feat…
Browse files Browse the repository at this point in the history
…ure/console
  • Loading branch information
Thinkscape committed Jul 15, 2012
6 parents d3038f6 + a8bc04a + 9e53124 + aa8a772 + 1dacd62 + b1d673b commit 875f572
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Adapter/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function setWidth($width = null)
// Try to determine the width through stty
if (preg_match('#\d+ (\d+)#', @shell_exec('stty size'), $match) === 1) {
$this->_width = (int) $match[1];
} else if (preg_match('#columns = (\d+);#', @shell_exec('stty'), $match) === 1) {
} elseif (preg_match('#columns = (\d+);#', @shell_exec('stty'), $match) === 1) {
$this->_width = (int) $match[1];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
* @category Zend
* @package Zend_ProgressBar
*/
class InvalidArgumentException extends Exception\InvalidArgumentException implements
class InvalidArgumentException extends Exception\InvalidArgumentException implements
ExceptionInterface
{}
2 changes: 1 addition & 1 deletion src/Adapter/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
* @category Zend
* @package Zend_ProgressBar
*/
class RuntimeException extends Exception\RuntimeException implements
class RuntimeException extends Exception\RuntimeException implements
ExceptionInterface
{}
2 changes: 1 addition & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
* @category Zend
* @package Zend_ProgressBar
*/
class InvalidArgumentException extends \InvalidArgumentException implements
class InvalidArgumentException extends \InvalidArgumentException implements
ExceptionInterface
{}
26 changes: 16 additions & 10 deletions test/Adapter/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public function testTextElementCustomLength()
$this->assertContains('foobar [', $adapter->getLastOutput());
}

public function testSetOutputStreamOpen() {
public function testSetOutputStreamOpen()
{
$adapter = new Adapter\Console();
$adapter->setOutputStream('zendprogressbaradapterconsole://test1');
$this->assertArrayHasKey('test1', MockupStream::$tests);
Expand All @@ -225,12 +226,13 @@ public function testSetOutputStreamOpen() {
public function testSetOutputStreamOpenFail()
{
$adapter = new Adapter\Console();

$this->setExpectedException('Zend\ProgressBar\Adapter\Exception\RuntimeException', 'Unable to open stream');
$adapter->setOutputStream(null);
}

public function testSetOutputStreamReplaceStream() {
public function testSetOutputStreamReplaceStream()
{
$adapter = new Adapter\Console();
$adapter->setOutputStream('zendprogressbaradapterconsole://test2');
$this->assertArrayHasKey('test2', MockupStream::$tests);
Expand All @@ -239,28 +241,32 @@ public function testSetOutputStreamReplaceStream() {
$this->assertArrayNotHasKey('test2', MockupStream::$tests);
}

public function testgetOutputStream() {
public function testgetOutputStream()
{
$adapter = new Adapter\Console();
$adapter->setOutputStream('zendprogressbaradapterconsole://test4');
$resource = $adapter->getOutputStream();
fwrite($resource, 'Hello Word!');
$this->assertEquals('Hello Word!', MockupStream::$tests['test4']);
}

public function testgetOutputStreamReturnigStdout() {
public function testgetOutputStreamReturnigStdout()
{
$adapter = new Adapter\Console();
$resource = $adapter->getOutputStream();
$this->assertTrue(is_resource($resource));
}

public function testFinishEol() {
public function testFinishEol()
{
$adapter = new Adapter\Console();
$adapter->setOutputStream('zendprogressbaradapterconsole://test5');
$adapter->finish();
$this->assertEquals(PHP_EOL, MockupStream::$tests['test5']);
}

public function testFinishNone() {
public function testFinishNone()
{
$adapter = new Adapter\Console();
$adapter->setOutputStream('zendprogressbaradapterconsole://test7');
$adapter->setFinishAction(Adapter\Console::FINISH_ACTION_NONE);
Expand All @@ -271,23 +277,23 @@ public function testFinishNone() {
public function testSetBarLeftChar()
{
$adapter = new Adapter\Console();

$this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException','Character may not be empty');
$adapter->setBarLeftChar(null);
}

public function testSetBarRightChar()
{
$adapter = new Adapter\Console();

$this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException','Character may not be empty');
$adapter->setBarRightChar(null);
}

public function testSetInvalidFinishAction()
{
$adapter = new Adapter\Console();

$this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException','Invalid finish action specified');
$adapter->setFinishAction('CUSTOM_FINISH_ACTION');
}
Expand Down
15 changes: 8 additions & 7 deletions test/Adapter/MockupStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MockupStream

public static $tests = array();

function stream_open($path, $mode, $options, &$opened_path)
public function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->test = $url["host"];
Expand All @@ -34,14 +34,14 @@ function stream_open($path, $mode, $options, &$opened_path)
return true;
}

function stream_read($count)
public function stream_read($count)
{
$ret = substr(self::$tests[$this->test], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}

function stream_write($data)
public function stream_write($data)
{
$left = substr(self::$tests[$this->test], 0, $this->position);
$right = substr(self::$tests[$this->test], $this->position + strlen($data));
Expand All @@ -50,17 +50,17 @@ function stream_write($data)
return strlen($data);
}

function stream_tell()
public function stream_tell()
{
return $this->position;
}

function stream_eof()
public function stream_eof()
{
return $this->position >= strlen(self::$tests[$this->test]);
}

function stream_seek($offset, $whence)
public function stream_seek($offset, $whence)
{
switch ($whence) {
case SEEK_SET:
Expand Down Expand Up @@ -95,7 +95,8 @@ function stream_seek($offset, $whence)
}
}

public function __destruct() {
public function __destruct()
{
unset(self::$tests[$this->test]);
}
}
2 changes: 1 addition & 1 deletion test/ProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class ProgressBarTest extends \PHPUnit_Framework_TestCase
{

public function testGreaterMin()
{
$this->setExpectedException('Zend\ProgressBar\Exception\OutOfRangeException', '$max must be greater than $min');
Expand Down

0 comments on commit 875f572

Please sign in to comment.