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

Commit

Permalink
[#4606] CS and logic flow fixes
Browse files Browse the repository at this point in the history
- `s/\t/    /g`
- Reflow logic in Console\DefaultRenderingStrategy to make it easier to
  read, and to re-use common values
  • Loading branch information
weierophinney committed Jun 28, 2013
1 parent 2d6dfa2 commit e0afc0d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
7 changes: 3 additions & 4 deletions library/Zend/Console/Adapter/AbstractAdapter.php
Expand Up @@ -53,11 +53,10 @@ abstract class AbstractAdapter implements AdapterInterface
*/
public function write($text, $color = null, $bgColor = null)
{
//Encode text to match console encoding
$text = $this->encodeText($text);

//Encode text to match console encoding
$text = $this->encodeText($text);

if ($color !== null || $bgColor !== null) {
if ($color !== null || $bgColor !== null) {
echo $this->colorize($text, $color, $bgColor);
} else {
echo $text;
Expand Down
12 changes: 4 additions & 8 deletions library/Zend/Mvc/View/Console/DefaultRenderingStrategy.php
Expand Up @@ -66,15 +66,11 @@ public function render(MvcEvent $e)
$console = $sm->get('console');

// Append console response to response object
if (is_callable(array($console,'encodeText'))) {
$response->setContent(
call_user_func(array($console,'encodeText'), $response->getContent() . $responseText)
);
} else {
$response->setContent(
$response->getContent() . $responseText
);
$content = $response->getContent() . $responseText;
if (is_callable(array($console, 'encodeText'))) {
$content = $console->encodeText($content);
}
$response->setContent($content);

// Pass on console-specific options
if ($response instanceof ConsoleResponse
Expand Down
40 changes: 20 additions & 20 deletions tests/ZendTest/Console/Adapter/AbstractAdapterTest.php
Expand Up @@ -123,25 +123,25 @@ public function testReadCharWithMaskInsensitiveCase()

public function testEncodeText()
{
//Utf8 string
$text = '\u00E9\u00E9\u00E9';

//Console UTF8 - Text utf8
$this->adapter->setTestUtf8(true);
$encodedText = $this->adapter->encodeText($text);
$this->assertEquals($text,$encodedText);

//Console UTF8 - Text not utf8
$encodedText = $this->adapter->encodeText(utf8_decode($text));
$this->assertEquals($text,$encodedText);

//Console not UTF8 - Text utf8
$this->adapter->setTestUtf8(false);
$encodedText = $this->adapter->encodeText($text);
$this->assertEquals(utf8_decode($text),$encodedText);

//Console not UTF8 - Text not utf8
$encodedText = $this->adapter->encodeText(utf8_decode($text));
$this->assertEquals(utf8_decode($text),$encodedText);
//Utf8 string
$text = '\u00E9\u00E9\u00E9';

//Console UTF8 - Text utf8
$this->adapter->setTestUtf8(true);
$encodedText = $this->adapter->encodeText($text);
$this->assertEquals($text,$encodedText);

//Console UTF8 - Text not utf8
$encodedText = $this->adapter->encodeText(utf8_decode($text));
$this->assertEquals($text,$encodedText);

//Console not UTF8 - Text utf8
$this->adapter->setTestUtf8(false);
$encodedText = $this->adapter->encodeText($text);
$this->assertEquals(utf8_decode($text),$encodedText);

//Console not UTF8 - Text not utf8
$encodedText = $this->adapter->encodeText(utf8_decode($text));
$this->assertEquals(utf8_decode($text),$encodedText);
}
}
12 changes: 6 additions & 6 deletions tests/ZendTest/Mvc/View/Console/DefaultRenderingStrategyTest.php
Expand Up @@ -68,14 +68,14 @@ public function testCanDetachListenersFromEventManager()

public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult()
{
//Register console service
$sm = new ServiceManager();
$sm->setService('console', new ConsoleAdapter());
//Register console service
$sm = new ServiceManager();
$sm->setService('console', new ConsoleAdapter());

$mockApplication = new MockApplication;
$mockApplication->setServiceManager($sm);
$mockApplication = new MockApplication;
$mockApplication->setServiceManager($sm);

$event = new MvcEvent();
$event = new MvcEvent();
$event->setApplication($mockApplication);

$model = new Model\ViewModel(array('content' => 'Page not found'));
Expand Down

0 comments on commit e0afc0d

Please sign in to comment.