From d865fb0134a4a77df68d533b8b08a587feee5cda Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Tue, 6 Apr 2010 09:13:43 -0500 Subject: [PATCH] Zend_Text converted to namespace Zend\Text, including tests --- src/Exception.php | 9 +- src/Figlet/Exception.php | 9 +- src/{ => Figlet}/Figlet.php | 58 +++--- src/MultiByte.php | 9 +- src/Table/Column.php | 50 +++-- src/Table/Decorator/Ascii.php | 9 +- .../{Interface.php => DecoratorInterface.php} | 7 +- src/Table/Decorator/Unicode.php | 9 +- src/Table/Exception.php | 11 +- src/Table/Row.php | 37 ++-- src/{ => Table}/Table.php | 86 ++++---- test/Figlet/GenerateDummies.sh | 0 test/FigletTest.php | 86 ++++---- test/MultiByteTest.php | 68 +++--- test/TableTest.php | 195 +++++++++--------- 15 files changed, 360 insertions(+), 283 deletions(-) rename src/{ => Figlet}/Figlet.php (95%) rename src/Table/Decorator/{Interface.php => DecoratorInterface.php} (96%) rename src/{ => Table}/Table.php (84%) mode change 100755 => 100644 test/Figlet/GenerateDummies.sh diff --git a/src/Exception.php b/src/Exception.php index 82e522e..2d68d41 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -19,15 +19,20 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text; + /** * Exception class for Zend_Text * - * @uses Zend_Exception + * @uses \Zend\Exception * @category Zend * @package Zend_Text * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Exception extends Zend_Exception +class Exception extends \Zend\Exception { } diff --git a/src/Figlet/Exception.php b/src/Figlet/Exception.php index f654b6f..b4fc160 100644 --- a/src/Figlet/Exception.php +++ b/src/Figlet/Exception.php @@ -19,15 +19,20 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Figlet; + /** * Exception class for Zend_Figlet * - * @uses Zend_Text_Exception + * @uses \Zend\Text\Exception * @category Zend * @package Zend_Text_Figlet * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Figlet_Exception extends Zend_Text_Exception +class Exception extends \Zend\Text\Exception { } diff --git a/src/Figlet.php b/src/Figlet/Figlet.php similarity index 95% rename from src/Figlet.php rename to src/Figlet/Figlet.php index 6a2a182..243ea7c 100644 --- a/src/Figlet.php +++ b/src/Figlet/Figlet.php @@ -19,17 +19,23 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Figlet; +use Zend\Config; + /** * Zend_Text_Figlet is a PHP implementation of FIGlet * * @uses InvalidArgumentException - * @uses Zend_Text_Figlet_Exception + * @uses \Zend\Text\Figlet\Exception * @category Zend * @package Zend_Text_Figlet * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Figlet +class Figlet { /** * Smush2 layout modes @@ -273,28 +279,28 @@ class Zend_Text_Figlet * the $options variable, which can either be an array or an instance of * Zend_Config. * - * @param array|Zend_Config $options Options for the output + * @param array|\Zend\Config\Config $options Options for the output */ public function __construct($options = null) { // Set options if (is_array($options)) { $this->setOptions($options); - } else if ($options instanceof Zend_Config) { + } else if ($options instanceof Config\Config) { $this->setConfig($options); } // If no font was defined, load default font if (!$this->_fontLoaded) { - $this->_loadFont(dirname(__FILE__) . '/Figlet/zend-framework.flf'); + $this->_loadFont(__DIR__ . '/zend-framework.flf'); } } /** * Set options from array * - * @param array $options Configuration for Zend_Text_Figlet - * @return Zend_Text_Figlet + * @param array $options Configuration for \Zend\Text\Figlet\Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setOptions(array $options) { @@ -314,10 +320,10 @@ public function setOptions(array $options) /** * Set options from config object * - * @param Zend_Config $config Configuration for Zend_Text_Figlet - * @return Zend_Text_Figlet + * @param Zend_Config $config Configuration for \Zend\Text\Figlet\Figlet + * @return \Zend\Text\Figlet\Figlet */ - public function setConfig(Zend_Config $config) + public function setConfig(Config\Config $config) { return $this->setOptions($config->toArray()); } @@ -326,7 +332,7 @@ public function setConfig(Zend_Config $config) * Set a font to use * * @param string $font Path to the font - * @return Zend_Text_Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setFont($font) { @@ -338,7 +344,7 @@ public function setFont($font) * Set handling of paragraphs * * @param boolean $handleParagraphs Wether to handle paragraphs or not - * @return Zend_Text_Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setHandleParagraphs($handleParagraphs) { @@ -351,7 +357,7 @@ public function setHandleParagraphs($handleParagraphs) * for right aligned. * * @param integer $justification Justification of the output text - * @return Zend_Text_Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setJustification($justification) { @@ -364,7 +370,7 @@ public function setJustification($justification) * * @param integer $outputWidth Output with which should be used for word * wrapping and justification - * @return Zend_Text_Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setOutputWidth($outputWidth) { @@ -378,7 +384,7 @@ public function setOutputWidth($outputWidth) * use Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT. * * @param integer $rightToLeft Right-to-left mode - * @return Zend_Text_Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setRightToLeft($rightToLeft) { @@ -392,7 +398,7 @@ public function setRightToLeft($rightToLeft) * Use one of the constants of Zend_Text_Figlet::SM_*, you may combine them. * * @param integer $smushMode Smush mode to use for generating text - * @return Zend_Text_Figlet + * @return \Zend\Text\Figlet\Figlet */ public function setSmushMode($smushMode) { @@ -423,13 +429,13 @@ public function setSmushMode($smushMode) * @param string $text Text to convert to a figlet text * @param string $encoding Encoding of the input string * @throws InvalidArgumentException When $text is not a string - * @throws Zend_Text_Figlet_Exception When $text it not properly encoded + * @throws \Zend\Text\Figlet\Exception When $text it not properly encoded * @return string */ public function render($text, $encoding = 'UTF-8') { if (!is_string($text)) { - throw new InvalidArgumentException('$text must be a string'); + throw new \InvalidArgumentException('$text must be a string'); } if ($encoding !== 'UTF-8') { @@ -449,7 +455,7 @@ public function render($text, $encoding = 'UTF-8') $textLength = @iconv_strlen($text, 'UTF-8'); if ($textLength === false) { - throw new Zend_Text_Figlet_Exception('$text is not encoded with ' . $encoding); + throw new Exception('$text is not encoded with ' . $encoding); } for ($charNum = 0; $charNum < $textLength; $charNum++) { @@ -960,22 +966,22 @@ protected function _smushem($leftChar, $rightChar) * Load the specified font * * @param string $fontFile Font file to load - * @throws Zend_Text_Figlet_Exception When font file was not found - * @throws Zend_Text_Figlet_Exception When GZIP library is required but not found - * @throws Zend_Text_Figlet_Exception When font file is not readable + * @throws \Zend\Text\Figlet\Exception When font file was not found + * @throws \Zend\Text\Figlet\Exception When GZIP library is required but not found + * @throws \Zend\Text\Figlet\Exception When font file is not readable * @return void */ protected function _loadFont($fontFile) { // Check if the font file exists if (!file_exists($fontFile)) { - throw new Zend_Text_Figlet_Exception($fontFile . ': Font file not found'); + throw new Exception($fontFile . ': Font file not found'); } // Check if gzip support is required if (substr($fontFile, -3) === '.gz') { if (!function_exists('gzcompress')) { - throw new Zend_Text_Figlet_Exception('GZIP library is required for ' + throw new Exception('GZIP library is required for ' . 'gzip compressed font files'); } @@ -988,7 +994,7 @@ protected function _loadFont($fontFile) // Try to open the file $fp = fopen($fontFile, 'rb'); if ($fp === false) { - throw new Zend_Text_Figlet_Exception($fontFile . ': Could not open file'); + throw new Exception($fontFile . ': Could not open file'); } // If the file is not compressed, lock the stream @@ -1011,7 +1017,7 @@ protected function _loadFont($fontFile) $this->_fontSmush); if ($magic !== self::FONTFILE_MAGIC_NUMBER || $numsRead < 5) { - throw new Zend_Text_Figlet_Exception($fontFile . ': Not a FIGlet 2 font file'); + throw new Exception($fontFile . ': Not a FIGlet 2 font file'); } // Set default right to left diff --git a/src/MultiByte.php b/src/MultiByte.php index 9cd36bf..4283c09 100644 --- a/src/MultiByte.php +++ b/src/MultiByte.php @@ -19,6 +19,11 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text; + /** * Zend_Text_MultiByte contains multibyte safe string methods * @@ -27,7 +32,7 @@ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_MultiByte +class MultiByte { /** * Word wrap @@ -111,7 +116,7 @@ public static function wordWrap($string, $width = 75, $break = "\n", $cut = fals * @param string $charset * @return string */ - public static function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT, $charset = 'UTF-8') + public static function strPad($input, $padLength, $padString = ' ', $padType = \STR\PAD\RIGHT, $charset = 'UTF-8') { $return = ''; $lengthOfPadding = $padLength - iconv_strlen($input, $charset); diff --git a/src/Table/Column.php b/src/Table/Column.php index 1259bf1..1ab8065 100644 --- a/src/Table/Column.php +++ b/src/Table/Column.php @@ -19,18 +19,24 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table; +use Zend\Text; + /** * Column class for Zend_Text_Table_Row * - * @uses Zend_Text_MultiByte - * @uses Zend_Text_Table - * @uses Zend_Text_Table_Exception + * @uses \Zend\Text\MultiByte + * @uses \Zend\Text\Table\Table + * @uses \Zend\Text\Table\Exception * @category Zend * @package Zend_Text_Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Table_Column +class Column { /** * Aligns for columns @@ -99,22 +105,22 @@ public function __construct($content = null, $align = null, $colSpan = null, $ch * * @param string $content Content of the column * @param string $charset The charset of the content - * @throws Zend_Text_Table_Exception When $content is not a string - * @return Zend_Text_Table_Column + * @throws \Zend\Text\Table\Exception When $content is not a string + * @return \Zend\Text\Table\Column */ public function setContent($content, $charset = null) { if (is_string($content) === false) { - throw new Zend_Text_Table_Exception('$content must be a string'); + throw new Exception('$content must be a string'); } if ($charset === null) { - $inputCharset = Zend_Text_Table::getInputCharset(); + $inputCharset = Table::getInputCharset(); } else { $inputCharset = strtolower($charset); } - $outputCharset = Zend_Text_Table::getOutputCharset(); + $outputCharset = Table::getOutputCharset(); if ($inputCharset !== $outputCharset) { if (PHP_OS !== 'AIX') { @@ -133,13 +139,13 @@ public function setContent($content, $charset = null) * Set the align * * @param string $align Align of the column - * @throws Zend_Text_Table_Exception When supplied align is invalid - * @return Zend_Text_Table_Column + * @throws \Zend\Text\Table\Exception When supplied align is invalid + * @return \Zend\Text\Table\Column */ public function setAlign($align) { if (in_array($align, $this->_allowedAligns) === false) { - throw new Zend_Text_Table_Exception('Invalid align supplied'); + throw new Exception('Invalid align supplied'); } $this->_align = $align; @@ -151,13 +157,13 @@ public function setAlign($align) * Set the colspan * * @param int $colSpan - * @throws Zend_Text_Table_Exception When $colSpan is smaller than 1 - * @return Zend_Text_Table_Column + * @throws \Zend\Text\Table\Exception When $colSpan is smaller than 1 + * @return \Zend\Text\Table\Column */ public function setColSpan($colSpan) { if (is_int($colSpan) === false or $colSpan < 1) { - throw new Zend_Text_Table_Exception('$colSpan must be an integer and greater than 0'); + throw new Exception('$colSpan must be an integer and greater than 0'); } $this->_colSpan = $colSpan; @@ -180,20 +186,20 @@ public function getColSpan() * * @param integer $columnWidth The width of the column * @param integer $padding The padding for the column - * @throws Zend_Text_Table_Exception When $columnWidth is lower than 1 - * @throws Zend_Text_Table_Exception When padding is greater than columnWidth + * @throws \Zend\Text\Table\Exception When $columnWidth is lower than 1 + * @throws \Zend\Text\Table\Exception When padding is greater than columnWidth * @return string */ public function render($columnWidth, $padding = 0) { if (is_int($columnWidth) === false or $columnWidth < 1) { - throw new Zend_Text_Table_Exception('$columnWidth must be an integer and greater than 0'); + throw new Exception('$columnWidth must be an integer and greater than 0'); } $columnWidth -= ($padding * 2); if ($columnWidth < 1) { - throw new Zend_Text_Table_Exception('Padding (' . $padding . ') is greater than column width'); + throw new Exception('Padding (' . $padding . ') is greater than column width'); } switch ($this->_align) { @@ -214,13 +220,13 @@ public function render($columnWidth, $padding = 0) break; } - $outputCharset = Zend_Text_Table::getOutputCharset(); - $lines = explode("\n", Zend_Text_MultiByte::wordWrap($this->_content, $columnWidth, "\n", true, $outputCharset)); + $outputCharset = Table::getOutputCharset(); + $lines = explode("\n", Text\MultiByte::wordWrap($this->_content, $columnWidth, "\n", true, $outputCharset)); $paddedLines = array(); foreach ($lines AS $line) { $paddedLines[] = str_repeat(' ', $padding) - . Zend_Text_MultiByte::strPad($line, $columnWidth, ' ', $padMode, $outputCharset) + . Text\MultiByte::strPad($line, $columnWidth, ' ', $padMode, $outputCharset) . str_repeat(' ', $padding); } diff --git a/src/Table/Decorator/Ascii.php b/src/Table/Decorator/Ascii.php index ea627bd..557c5ce 100644 --- a/src/Table/Decorator/Ascii.php +++ b/src/Table/Decorator/Ascii.php @@ -19,16 +19,21 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table\Decorator; + /** * ASCII Decorator for Zend_Text_Table * - * @uses Zend_Text_Table_Decorator_Interface + * @uses \Zend\Text\Table\Decorator\DecoratorInterface * @category Zend * @package Zend_Text_Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Table_Decorator_Ascii implements Zend_Text_Table_Decorator_Interface +class Ascii implements DecoratorInterface { /** * Defined by Zend_Text_Table_Decorator_Interface diff --git a/src/Table/Decorator/Interface.php b/src/Table/Decorator/DecoratorInterface.php similarity index 96% rename from src/Table/Decorator/Interface.php rename to src/Table/Decorator/DecoratorInterface.php index 9bfe28c..35f0b12 100644 --- a/src/Table/Decorator/Interface.php +++ b/src/Table/Decorator/DecoratorInterface.php @@ -19,6 +19,11 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table\Decorator; + /** * Interface for Zend_Text_Table decorators * @@ -27,7 +32,7 @@ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -interface Zend_Text_Table_Decorator_Interface +interface DecoratorInterface { /** * Get a single character for the top left corner diff --git a/src/Table/Decorator/Unicode.php b/src/Table/Decorator/Unicode.php index ef5da73..e3b3cbe 100644 --- a/src/Table/Decorator/Unicode.php +++ b/src/Table/Decorator/Unicode.php @@ -19,16 +19,21 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table\Decorator; + /** * Unicode Decorator for Zend_Text_Table * - * @uses Zend_Text_Table_Decorator_Interface + * @uses \Zend\Text\Table\Decorator\DecoratorInterface * @category Zend * @package Zend_Text_Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Table_Decorator_Unicode implements Zend_Text_Table_Decorator_Interface +class Unicode implements DecoratorInterface { /** * Defined by Zend_Text_Table_Decorator_Interface diff --git a/src/Table/Exception.php b/src/Table/Exception.php index 8959320..2af9be5 100644 --- a/src/Table/Exception.php +++ b/src/Table/Exception.php @@ -19,16 +19,21 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table; + /** * Exception class for Zend_Text_Table * - * @uses Zend_Text_Exception + * @uses \Zend\Text\Exception * @category Zend * @package Zend_Text_Table - * @uses Zend_Text_Exception + * @uses \Zend\Text\Exception * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Table_Exception extends Zend_Text_Exception +class Exception extends \Zend\Text\Exception { } diff --git a/src/Table/Row.php b/src/Table/Row.php index cb22dcf..5237a5a 100644 --- a/src/Table/Row.php +++ b/src/Table/Row.php @@ -19,17 +19,22 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table; + /** * Row class for Zend_Text_Table * - * @uses Zend_Text_Table_Column - * @uses Zend_Text_Table_Exception + * @uses \Zend\Text\Table\Column + * @uses \Zend\Text\Table\Exception * @category Zend * @package Zend_Text_Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Table_Row +class Row { /** * List of all columns @@ -50,7 +55,7 @@ class Zend_Text_Table_Row * * @param string $content * @param array $options - * @return Zend_Text_Table_Row + * @return \Zend\Text\Table\Row */ public function createColumn($content, array $options = null) { @@ -62,7 +67,7 @@ public function createColumn($content, array $options = null) extract($options, EXTR_IF_EXISTS); } - $column = new Zend_Text_Table_Column($content, $align, $colSpan, $encoding); + $column = new Column($content, $align, $colSpan, $encoding); $this->appendColumn($column); @@ -72,10 +77,10 @@ public function createColumn($content, array $options = null) /** * Append a column to the row * - * @param Zend_Text_Table_Column $column The column to append to the row - * @return Zend_Text_Table_Row + * @param \Zend\Text\Table\Column $column The column to append to the row + * @return \Zend\Text\Table\Row */ - public function appendColumn(Zend_Text_Table_Column $column) + public function appendColumn(Column $column) { $this->_columns[] = $column; @@ -88,7 +93,7 @@ public function appendColumn(Zend_Text_Table_Column $column) * Returns null, when the index is out of range * * @param integer $index - * @return Zend_Text_Table_Column|null + * @return \Zend\Text\Table\Column|null */ public function getColumn($index) { @@ -112,13 +117,13 @@ public function getColumns() /** * Get the widths of all columns, which were rendered last * - * @throws Zend_Text_Table_Exception When no columns were rendered yet + * @throws \Zend\Text\Table\Exception When no columns were rendered yet * @return integer */ public function getColumnWidths() { if ($this->_columnWidths === null) { - throw new Zend_Text_Table_Exception('No columns were rendered yet'); + throw new Exception('No columns were rendered yet'); } return $this->_columnWidths; @@ -128,13 +133,13 @@ public function getColumnWidths() * Render the row * * @param array $columnWidths Width of all columns - * @param Zend_Text_Table_Decorator_Interface $decorator Decorator for the row borders + * @param \Zend\Text\Table\Decorator\DecoratorInterface $decorator Decorator for the row borders * @param integer $padding Padding for the columns - * @throws Zend_Text_Table_Exception When there are too many columns + * @throws \Zend\Text\Table\Exception When there are too many columns * @return string */ public function render(array $columnWidths, - Zend_Text_Table_Decorator_Interface $decorator, + Decorator\DecoratorInterface $decorator, $padding = 0) { // Prepare an array to store all column widths @@ -143,7 +148,7 @@ public function render(array $columnWidths, // If there is no single column, create a column which spans over the // entire row if (count($this->_columns) === 0) { - $this->appendColumn(new Zend_Text_Table_Column(null, null, count($columnWidths))); + $this->appendColumn(new Column(null, null, count($columnWidths))); } // First we have to render all columns, to get the maximum height @@ -156,7 +161,7 @@ public function render(array $columnWidths, // Verify if there are enough column widths defined if (($colNum + $colSpan) > count($columnWidths)) { - throw new Zend_Text_Table_Exception('Too many columns'); + throw new Exception('Too many columns'); } // Calculate the column width diff --git a/src/Table.php b/src/Table/Table.php similarity index 84% rename from src/Table.php rename to src/Table/Table.php index ce9c399..1ff7c7b 100644 --- a/src/Table.php +++ b/src/Table/Table.php @@ -19,19 +19,25 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace Zend\Text\Table; +use Zend\Config; + /** * Zend_Text_Table enables developers to create tables out of characters * - * @uses Zend_Loader_PluginLoader - * @uses Zend_Text_Table_Exception - * @uses Zend_Text_Table_Column - * @uses Zend_Text_Table_Row + * @uses \Zend\Loader\PluginLoader\PluginLoader + * @uses \Zend\Text\Table\Exception + * @uses \Zend\Text\Table\Column + * @uses \Zend\Text\Table\Row * @category Zend * @package Zend_Text_Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Text_Table +class Table { /** * Auto seperator settings @@ -44,7 +50,7 @@ class Zend_Text_Table /** * Decorator used for the table borders * - * @var Zend_Text_Table_Decorator_Interface + * @var \Zend\Text\Table\Decorator\DecoratorInterface */ protected $_decorator = null; @@ -119,22 +125,22 @@ class Zend_Text_Table * Create a basic table object * * @param array $columnsWidths List of all column widths - * @param Zend_Config|array $options Configuration options - * @throws Zend_Text_Table_Exception When no columns widths were set + * @param \Zend\Config\Config|array $options Configuration options + * @throws \Zend\Text\Table\Exception When no columns widths were set */ public function __construct($options = null) { // Set options if (is_array($options)) { $this->setOptions($options); - } else if ($options instanceof Zend_Config) { + } else if ($options instanceof Config\Config) { $this->setConfig($options); } // Check if column widths were set // @todo When column widths were not set, assume auto-sizing if ($this->_columnWidths === null) { - throw new Zend_Text_Table_Exception('You must define the column widths'); + throw new Exception('You must define the column widths'); } // If no decorator was given, use default unicode decorator @@ -150,8 +156,8 @@ public function __construct($options = null) /** * Set options from array * - * @param array $options Configuration for Zend_Text_Table - * @return Zend_Text_Table + * @param array $options Configuration for \Zend\Text\Table\Table + * @return \Zend\Text\Table\Table */ public function setOptions(array $options) { @@ -172,10 +178,10 @@ public function setOptions(array $options) /** * Set options from config object * - * @param Zend_Config $config Configuration for Zend_Text_Table - * @return Zend_Text_Table + * @param Zend_Config $config Configuration for \Zend\Text\Table\Table + * @return \Zend\Text\Table\Table */ - public function setConfig(Zend_Config $config) + public function setConfig(Config\Config $config) { return $this->setOptions($config->toArray()); } @@ -184,19 +190,19 @@ public function setConfig(Zend_Config $config) * Set column widths * * @param array $columnWidths Widths of all columns - * @throws Zend_Text_Table_Exception When no columns were supplied - * @throws Zend_Text_Table_Exception When a column has an invalid width - * @return Zend_Text_Table + * @throws \Zend\Text\Table\Exception When no columns were supplied + * @throws \Zend\Text\Table\Exception When a column has an invalid width + * @return \Zend\Text\Table\Table */ public function setColumnWidths(array $columnWidths) { if (count($columnWidths) === 0) { - throw new Zend_Text_Table_Exception('You must supply at least one column'); + throw new Exception('You must supply at least one column'); } foreach ($columnWidths as $columnNum => $columnWidth) { if (is_int($columnWidth) === false or $columnWidth < 1) { - throw new Zend_Text_Table_Exception('Column ' . $columnNum . ' has an invalid' + throw new Exception('Column ' . $columnNum . ' has an invalid' . ' column width'); } } @@ -210,7 +216,7 @@ public function setColumnWidths(array $columnWidths) * Set auto separation mode * * @param integer $autoSeparate Auto separation mode - * @return Zend_Text_Table + * @return \Zend\Text\Table\Table */ public function setAutoSeparate($autoSeparate) { @@ -221,12 +227,12 @@ public function setAutoSeparate($autoSeparate) /** * Set decorator * - * @param Zend_Text_Table_Decorator_Interface|string $decorator Decorator to use - * @return Zend_Text_Table + * @param \Zend\Text\Table\Decorator\DecoratorInterface|string $decorator Decorator to use + * @return \Zend\Text\Table\Table */ public function setDecorator($decorator) { - if ($decorator instanceof Zend_Text_Table_Decorator_Interface) { + if ($decorator instanceof Decorator\DecoratorInterface) { $this->_decorator = $decorator; } else { $classname = $this->getPluginLoader()->load($decorator); @@ -240,7 +246,7 @@ public function setDecorator($decorator) * Set the column padding * * @param integer $padding The padding for the columns - * @return Zend_Text_Table + * @return \Zend\Text\Table\Table */ public function setPadding($padding) { @@ -251,14 +257,14 @@ public function setPadding($padding) /** * Get the plugin loader for decorators * - * @return Zend_Loader_PluginLoader + * @return \Zend\Loader\PluginLoader\PluginLoader */ public function getPluginLoader() { if ($this->_pluginLoader === null) { - $prefix = 'Zend_Text_Table_Decorator_'; + $prefix = 'Zend\Text\Table\Decorator\\'; $pathPrefix = 'Zend/Text/Table/Decorator/'; - $this->_pluginLoader = new Zend_Loader_PluginLoader(array($prefix => $pathPrefix)); + $this->_pluginLoader = new \Zend\Loader\PluginLoader\PluginLoader(array($prefix => $pathPrefix)); } return $this->_pluginLoader; @@ -269,7 +275,7 @@ public function getPluginLoader() * * @param integer $columnNum * @param string $align - * @return Zend_Text_Table + * @return \Zend\Text\Table\Table */ public function setDefaultColumnAlign($columnNum, $align) { @@ -321,24 +327,24 @@ public static function getOutputCharset() /** * Append a row to the table * - * @param array|Zend_Text_Table_Row $row The row to append to the table + * @param array|\Zend\Text\Table\Row $row The row to append to the table * @throws Zend_Text_Table_Exception When $row is neither an array nor Zend_Zext_Table_Row - * @throws Zend_Text_Table_Exception When a row contains too many columns - * @return Zend_Text_Table + * @throws \Zend\Text\Table\Exception When a row contains too many columns + * @return \Zend\Text\Table\Table */ public function appendRow($row) { - if (!is_array($row) && !($row instanceof Zend_Text_Table_Row)) { - throw new Zend_Text_Table_Exception('$row must be an array or instance of Zend_Text_Table_Row'); + if (!is_array($row) && !($row instanceof Row)) { + throw new Exception('$row must be an array or instance of Zend_Text_Table_Row'); } if (is_array($row)) { if (count($row) > count($this->_columnWidths)) { - throw new Zend_Text_Table_Exception('Row contains too many columns'); + throw new Exception('Row contains too many columns'); } $data = $row; - $row = new Zend_Text_Table_Row(); + $row = new Row(); $colNum = 0; foreach ($data as $columnData) { if (isset($this->_defaultColumnAligns[$colNum])) { @@ -347,7 +353,7 @@ public function appendRow($row) $align = null; } - $row->appendColumn(new Zend_Text_Table_Column($columnData, $align)); + $row->appendColumn(new Column($columnData, $align)); $colNum++; } } @@ -360,14 +366,14 @@ public function appendRow($row) /** * Render the table * - * @throws Zend_Text_Table_Exception When no rows were added to the table + * @throws \Zend\Text\Table\Exception When no rows were added to the table * @return string */ public function render() { // There should be at least one row if (count($this->_rows) === 0) { - throw new Zend_Text_Table_Exception('No rows were added to the table yet'); + throw new Exception('No rows were added to the table yet'); } // Initiate the result variable @@ -518,7 +524,7 @@ public function __toString() { try { return $this->render(); - } catch (Exception $e) { + } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } diff --git a/test/Figlet/GenerateDummies.sh b/test/Figlet/GenerateDummies.sh old mode 100755 new mode 100644 diff --git a/test/FigletTest.php b/test/FigletTest.php index c1e034c..70b4879 100644 --- a/test/FigletTest.php +++ b/test/FigletTest.php @@ -20,6 +20,12 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace ZendTest\Text; +use Zend\Text\Figlet; + // Call Zend_Text_FigletTest::main() if this source file is executed directly. if (!defined("PHPUnit_MAIN_METHOD")) { define("PHPUnit_MAIN_METHOD", "Zend_Text_FigletTest::main"); @@ -45,7 +51,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Text */ -class Zend_Text_FigletTest extends PHPUnit_Framework_TestCase +class FigletTest extends \PHPUnit_Framework_TestCase { /** * Runs the test methods of this class. @@ -54,69 +60,69 @@ class Zend_Text_FigletTest extends PHPUnit_Framework_TestCase */ public static function main() { - $suite = new PHPUnit_Framework_TestSuite("Zend_Text_FigletTest"); - $result = PHPUnit_TextUI_TestRunner::run($suite); + $suite = new \PHPUnit_Framework_TestSuite("Zend_Text_FigletTest"); + $result = \PHPUnit_TextUI_TestRunner::run($suite); } public function testStandardAlignLeft() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet'); } public function testStandardAlignCenter() { - $figlet = new Zend_Text_Figlet(array('justification' => Zend_Text_Figlet::JUSTIFICATION_CENTER)); + $figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_CENTER)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignCenter.figlet'); } public function testStandardAlignRight() { - $figlet = new Zend_Text_Figlet(array('justification' => Zend_Text_Figlet::JUSTIFICATION_RIGHT)); + $figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_RIGHT)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignRight.figlet'); } public function testStandardRightToLeftAlignLeft() { - $figlet = new Zend_Text_Figlet(array('justification' => Zend_Text_Figlet::JUSTIFICATION_LEFT, - 'rightToLeft' => Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT)); + $figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_LEFT, + 'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignLeft.figlet'); } public function testStandardRightToLeftAlignCenter() { - $figlet = new Zend_Text_Figlet(array('justification' => Zend_Text_Figlet::JUSTIFICATION_CENTER, - 'rightToLeft' => Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT)); + $figlet = new Figlet\Figlet(array('justification' => Figlet\Figlet::JUSTIFICATION_CENTER, + 'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignCenter.figlet'); } public function testStandardRightToLeftAlignRight() { - $figlet = new Zend_Text_Figlet(array('rightToLeft' => Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT)); + $figlet = new Figlet\Figlet(array('rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignRight.figlet'); } public function testWrongParameter() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); try { $figlet->render(1); $this->fail('An expected InvalidArgumentException has not been raised'); - } catch (InvalidArgumentException $expected) { + } catch (\InvalidArgumentException $expected) { $this->assertContains('$text must be a string', $expected->getMessage()); } } public function testCorrectEncodingUTF8() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $this->_equalAgainstFile($figlet->render('Ömläüt'), 'CorrectEncoding.figlet'); } @@ -127,7 +133,7 @@ public function testCorrectEncodingISO885915() $this->markTestSkipped('Test case cannot run on AIX'); } - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $isoText = iconv('UTF-8', 'ISO-8859-15', 'Ömläüt'); $this->_equalAgainstFile($figlet->render($isoText, 'ISO-8859-15'), 'CorrectEncoding.figlet'); @@ -139,7 +145,7 @@ public function testCorrectEncodingISO885915() public function testIncorrectEncoding() { $this->markTestSkipped('Test case not reproducible on all setups'); - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); if (PHP_OS == 'AIX') { $isoText = iconv('UTF-8', 'ISO-8859-15', 'Ömläüt'); @@ -153,9 +159,9 @@ public function testIncorrectEncoding() public function testNonExistentFont() { try { - $figlet = new Zend_Text_Figlet(array('font' => dirname(__FILE__) . '/Figlet/NonExistentFont.flf')); + $figlet = new Figlet\Figlet(array('font' => dirname(__FILE__) . '/Figlet/NonExistentFont.flf')); $this->fail('An expected Zend_Text_Figlet_Exception has not been raised'); - } catch (Zend_Text_Figlet_Exception $expected) { + } catch (Figlet\Exception $expected) { $this->assertContains('Font file not found', $expected->getMessage()); } } @@ -163,123 +169,123 @@ public function testNonExistentFont() public function testInvalidFont() { try { - $figlet = new Zend_Text_Figlet(array('font' => dirname(__FILE__) . '/Figlet/InvalidFont.flf')); + $figlet = new Figlet\Figlet(array('font' => dirname(__FILE__) . '/Figlet/InvalidFont.flf')); $this->fail('An expected Zend_Text_Figlet_Exception has not been raised'); - } catch (Zend_Text_Figlet_Exception $expected) { + } catch (Figlet\Exception $expected) { $this->assertContains('Not a FIGlet 2 font file', $expected->getMessage()); } } public function testGzippedFont() { - $figlet = new Zend_Text_Figlet(array('font' => dirname(__FILE__) . '/Figlet/GzippedFont.gz')); + $figlet = new Figlet\Figlet(array('font' => dirname(__FILE__) . '/Figlet/GzippedFont.gz')); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet'); } public function testConfig() { - $config = new Zend_Config(array('justification' => Zend_Text_Figlet::JUSTIFICATION_RIGHT)); - $figlet = new Zend_Text_Figlet($config); + $config = new \Zend\Config\Config(array('justification' => Figlet\Figlet::JUSTIFICATION_RIGHT)); + $figlet = new Figlet\Figlet($config); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignRight.figlet'); } public function testOutputWidth() { - $figlet = new Zend_Text_Figlet(array('outputWidth' => 50, - 'justification' => Zend_Text_Figlet::JUSTIFICATION_RIGHT)); + $figlet = new Figlet\Figlet(array('outputWidth' => 50, + 'justification' => Figlet\Figlet::JUSTIFICATION_RIGHT)); $this->_equalAgainstFile($figlet->render('Dummy'), 'OutputWidth50AlignRight.figlet'); } public function testSmushModeRemoved() { - $figlet = new Zend_Text_Figlet(array('smushMode' => -1)); + $figlet = new Figlet\Figlet(array('smushMode' => -1)); $this->_equalAgainstFile($figlet->render('Dummy'), 'NoSmush.figlet'); } public function testSmushModeRemovedRightToLeft() { - $figlet = new Zend_Text_Figlet(array('smushMode' => -1, - 'rightToLeft' => Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT)); + $figlet = new Figlet\Figlet(array('smushMode' => -1, + 'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT)); $this->_equalAgainstFile($figlet->render('Dummy'), 'NoSmushRightToLeft.figlet'); } public function testSmushModeInvalid() { - $figlet = new Zend_Text_Figlet(array('smushMode' => -5)); + $figlet = new Figlet\Figlet(array('smushMode' => -5)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet'); } public function testSmushModeTooSmall() { - $figlet = new Zend_Text_Figlet(array('smushMode' => -2)); + $figlet = new Figlet\Figlet(array('smushMode' => -2)); $this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet'); } public function testSmushModeDefault() { - $figlet = new Zend_Text_Figlet(array('smushMode' => 0)); + $figlet = new Figlet\Figlet(array('smushMode' => 0)); $this->_equalAgainstFile($figlet->render('Dummy'), 'SmushDefault.figlet'); } public function testSmushModeForced() { - $figlet = new Zend_Text_Figlet(array('smushMode' => 5)); + $figlet = new Figlet\Figlet(array('smushMode' => 5)); $this->_equalAgainstFile($figlet->render('Dummy'), 'SmushForced.figlet'); } public function testWordWrapLeftToRight() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $this->_equalAgainstFile($figlet->render('Dummy Dummy Dummy'), 'WordWrapLeftToRight.figlet'); } public function testWordWrapRightToLeft() { - $figlet = new Zend_Text_Figlet(array('rightToLeft' => Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT)); + $figlet = new Figlet\Figlet(array('rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT)); $this->_equalAgainstFile($figlet->render('Dummy Dummy Dummy'), 'WordWrapRightToLeft.figlet'); } public function testCharWrapLeftToRight() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $this->_equalAgainstFile($figlet->render('DummyDumDummy'), 'CharWrapLeftToRight.figlet'); } public function testCharWrapRightToLeft() { - $figlet = new Zend_Text_Figlet(array('rightToLeft' => Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT)); + $figlet = new Figlet\Figlet(array('rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT)); $this->_equalAgainstFile($figlet->render('DummyDumDummy'), 'CharWrapRightToLeft.figlet'); } public function testParagraphOff() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $this->_equalAgainstFile($figlet->render("Dum\nDum\n\nDum\n"), 'ParagraphOff.figlet'); } public function testParagraphOn() { - $figlet = new Zend_Text_Figlet(array('handleParagraphs' => true)); + $figlet = new Figlet\Figlet(array('handleParagraphs' => true)); $this->_equalAgainstFile($figlet->render("Dum\nDum\n\nDum\n"), 'ParagraphOn.figlet'); } public function testEmptyString() { - $figlet = new Zend_Text_Figlet(); + $figlet = new Figlet\Figlet(); $this->assertEquals('', $figlet->render('')); } @@ -294,5 +300,5 @@ protected function _equalAgainstFile($output, $file) // Call Zend_Text_FigletTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Text_FigletTest::main") { - Zend_Text_FigletTest::main(); + \Zend_Text_FigletTest::main(); } diff --git a/test/MultiByteTest.php b/test/MultiByteTest.php index e64fd0b..f2e323a 100644 --- a/test/MultiByteTest.php +++ b/test/MultiByteTest.php @@ -20,6 +20,12 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace ZendTest\Text; +use Zend\Text; + // Call Zend_Text_MultiByteTest::main() if this source file is executed directly. if (!defined("PHPUnit_MAIN_METHOD")) { define("PHPUnit_MAIN_METHOD", "Zend_Text_MultiByteTest::main"); @@ -41,7 +47,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Text */ -class Zend_Text_MultiByteTest extends PHPUnit_Framework_TestCase +class MultiByteTest extends \PHPUnit_Framework_TestCase { /** * Runs the test methods of this class. @@ -50,8 +56,8 @@ class Zend_Text_MultiByteTest extends PHPUnit_Framework_TestCase */ public static function main() { - $suite = new PHPUnit_Framework_TestSuite("Zend_Text_MultiByteTest"); - $result = PHPUnit_TextUI_TestRunner::run($suite); + $suite = new \PHPUnit_Framework_TestSuite("Zend_Text_MultiByteTest"); + $result = \PHPUnit_TextUI_TestRunner::run($suite); } /** @@ -59,19 +65,19 @@ public static function main() */ public function testWordWrapCutSingleLine() { - $line = Zend_Text_MultiByte::wordWrap('äbüöcß', 2, ' ', true); + $line = Text\MultiByte::wordWrap('äbüöcß', 2, ' ', true); $this->assertEquals('äb üö cß', $line); } public function testWordWrapCutMultiLine() { - $line = Zend_Text_MultiByte::wordWrap('äbüöc ß äbüöcß', 2, ' ', true); + $line = Text\MultiByte::wordWrap('äbüöc ß äbüöcß', 2, ' ', true); $this->assertEquals('äb üö c ß äb üö cß', $line); } public function testWordWrapCutMultiLineShortWords() { - $line = Zend_Text_MultiByte::wordWrap('Ä very long wöööööööööööörd.', 8, "\n", true); + $line = Text\MultiByte::wordWrap('Ä very long wöööööööööööörd.', 8, "\n", true); $this->assertEquals("Ä very\nlong\nwööööööö\nööööörd.", $line); } @@ -80,49 +86,49 @@ public function testWordWrapCutMultiLineShortWords() */ public function testWordWrapCutBeginningSingleSpace() { - $line = Zend_Text_MultiByte::wordWrap(' äüöäöü', 3, ' ', true); + $line = Text\MultiByte::wordWrap(' äüöäöü', 3, ' ', true); $this->assertEquals(' äüö äöü', $line); } public function testWordWrapCutEndingSingleSpace() { - $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true); + $line = Text\MultiByte::wordWrap('äüöäöü ', 3, ' ', true); $this->assertEquals('äüö äöü ', $line); } public function testWordWrapCutEndingTwoSpaces() { - $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true); + $line = Text\MultiByte::wordWrap('äüöäöü ', 3, ' ', true); $this->assertEquals('äüö äöü ', $line); } public function testWordWrapCutEndingThreeSpaces() { - $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true); + $line = Text\MultiByte::wordWrap('äüöäöü ', 3, ' ', true); $this->assertEquals('äüö äöü ', $line); } public function testWordWrapCutEndingTwoBreaks() { - $line = Zend_Text_MultiByte::wordWrap('äüöäöü--', 3, '-', true); + $line = Text\MultiByte::wordWrap('äüöäöü--', 3, '-', true); $this->assertEquals('äüö-äöü--', $line); } public function testWordWrapCutTab() { - $line = Zend_Text_MultiByte::wordWrap("äbü\töcß", 3, ' ', true); + $line = Text\MultiByte::wordWrap("äbü\töcß", 3, ' ', true); $this->assertEquals("äbü \töc ß", $line); } public function testWordWrapCutNewlineWithSpace() { - $line = Zend_Text_MultiByte::wordWrap("äbü\nößt", 3, ' ', true); + $line = Text\MultiByte::wordWrap("äbü\nößt", 3, ' ', true); $this->assertEquals("äbü \nöß t", $line); } public function testWordWrapCutNewlineWithNewline() { - $line = Zend_Text_MultiByte::wordWrap("äbü\nößte", 3, "\n", true); + $line = Text\MultiByte::wordWrap("äbü\nößte", 3, "\n", true); $this->assertEquals("äbü\nößt\ne", $line); } @@ -131,31 +137,31 @@ public function testWordWrapCutNewlineWithNewline() */ public function testWordWrapCutBreakBefore() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foofoofoo', 8, '-', true); + $line = Text\MultiByte::wordWrap('foobar-foofoofoo', 8, '-', true); $this->assertEquals('foobar-foofoofo-o', $line); } public function testWordWrapCutBreakWith() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 6, '-', true); + $line = Text\MultiByte::wordWrap('foobar-foobar', 6, '-', true); $this->assertEquals('foobar-foobar', $line); } public function testWordWrapCutBreakWithin() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 7, '-', true); + $line = Text\MultiByte::wordWrap('foobar-foobar', 7, '-', true); $this->assertEquals('foobar-foobar', $line); } public function testWordWrapCutBreakWithinEnd() { - $line = Zend_Text_MultiByte::wordWrap('foobar-', 7, '-', true); + $line = Text\MultiByte::wordWrap('foobar-', 7, '-', true); $this->assertEquals('foobar-', $line); } public function testWordWrapCutBreakAfter() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 5, '-', true); + $line = Text\MultiByte::wordWrap('foobar-foobar', 5, '-', true); $this->assertEquals('fooba-r-fooba-r', $line); } @@ -164,19 +170,19 @@ public function testWordWrapCutBreakAfter() */ public function testWordWrapNoCutSingleLine() { - $line = Zend_Text_MultiByte::wordWrap('äbüöcß', 2, ' ', false); + $line = Text\MultiByte::wordWrap('äbüöcß', 2, ' ', false); $this->assertEquals('äbüöcß', $line); } public function testWordWrapNoCutMultiLine() { - $line = Zend_Text_MultiByte::wordWrap('äbüöc ß äbüöcß', 2, "\n", false); + $line = Text\MultiByte::wordWrap('äbüöc ß äbüöcß', 2, "\n", false); $this->assertEquals("äbüöc\nß\näbüöcß", $line); } public function testWordWrapNoCutMultiWord() { - $line = Zend_Text_MultiByte::wordWrap('äöü äöü äöü', 5, "\n", false); + $line = Text\MultiByte::wordWrap('äöü äöü äöü', 5, "\n", false); $this->assertEquals("äöü\näöü\näöü", $line); } @@ -185,31 +191,31 @@ public function testWordWrapNoCutMultiWord() */ public function testWordWrapNoCutBreakBefore() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foofoofoo', 8, '-', false); + $line = Text\MultiByte::wordWrap('foobar-foofoofoo', 8, '-', false); $this->assertEquals('foobar-foofoofoo', $line); } public function testWordWrapNoCutBreakWith() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 6, '-', false); + $line = Text\MultiByte::wordWrap('foobar-foobar', 6, '-', false); $this->assertEquals('foobar-foobar', $line); } public function testWordWrapNoCutBreakWithin() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 7, '-', false); + $line = Text\MultiByte::wordWrap('foobar-foobar', 7, '-', false); $this->assertEquals('foobar-foobar', $line); } public function testWordWrapNoCutBreakWithinEnd() { - $line = Zend_Text_MultiByte::wordWrap('foobar-', 7, '-', false); + $line = Text\MultiByte::wordWrap('foobar-', 7, '-', false); $this->assertEquals('foobar-', $line); } public function testWordWrapNoCutBreakAfter() { - $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 5, '-', false); + $line = Text\MultiByte::wordWrap('foobar-foobar', 5, '-', false); $this->assertEquals('foobar-foobar', $line); } @@ -218,24 +224,24 @@ public function testWordWrapNoCutBreakAfter() */ public function testLeftPad() { - $text = Zend_Text_MultiByte::strPad('äää', 5, 'ö', STR_PAD_LEFT); + $text = Text\MultiByte::strPad('äää', 5, 'ö', STR_PAD_LEFT); $this->assertEquals('ööäää', $text); } public function testCenterPad() { - $text = Zend_Text_MultiByte::strPad('äää', 6, 'ö', STR_PAD_BOTH); + $text = Text\MultiByte::strPad('äää', 6, 'ö', STR_PAD_BOTH); $this->assertEquals('öäääöö', $text); } public function testRightPad() { - $text = Zend_Text_MultiByte::strPad('äääöö', 5, 'ö', STR_PAD_RIGHT); + $text = Text\MultiByte::strPad('äääöö', 5, 'ö', STR_PAD_RIGHT); $this->assertEquals('äääöö', $text); } } // Call Zend_Text_MultiByteTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Text_MultiByteTest::main") { - Zend_Text_MultiByteTest::main(); + \Zend_Text_MultiByteTest::main(); } diff --git a/test/TableTest.php b/test/TableTest.php index 08e0b52..bef1426 100644 --- a/test/TableTest.php +++ b/test/TableTest.php @@ -20,6 +20,13 @@ * @version $Id$ */ +/** + * @namespace + */ +namespace ZendTest\Text; +use Zend\Text\Table; +use Zend\Text\Table\Decorator; + // Call Zend_Text_FigletTest::main() if this source file is executed directly. if (!defined("PHPUnit_MAIN_METHOD")) { define("PHPUnit_MAIN_METHOD", "Zend_Text_TableTest::main"); @@ -38,7 +45,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Text */ -class Zend_Text_TableTest extends PHPUnit_Framework_TestCase +class TableTest extends \PHPUnit_Framework_TestCase { /** * Runs the test methods of this class. @@ -47,54 +54,54 @@ class Zend_Text_TableTest extends PHPUnit_Framework_TestCase */ public static function main() { - $suite = new PHPUnit_Framework_TestSuite("Zend_Text_TableTest"); - $result = PHPUnit_TextUI_TestRunner::run($suite); + $suite = new \PHPUnit_Framework_TestSuite("Zend_Text_TableTest"); + $result = \PHPUnit_TextUI_TestRunner::run($suite); } public function tearDown() { - Zend_Text_Table::setInputCharset('utf-8'); - Zend_Text_Table::setOutputCharset('utf-8'); + Table\Table::setInputCharset('utf-8'); + Table\Table::setOutputCharset('utf-8'); } public function testColumnAlignLeft() { - $column = new Zend_Text_Table_Column("foobar\nfoo"); + $column = new Table\Column("foobar\nfoo"); $this->assertEquals($column->render(10), "foobar \nfoo "); } public function testColumnPadding() { - $column = new Zend_Text_Table_Column("foobar\nfoo"); + $column = new Table\Column("foobar\nfoo"); $this->assertEquals($column->render(10, 1), " foobar \n foo "); } public function testColumnWordwrap() { - $column = new Zend_Text_Table_Column("foobar"); + $column = new Table\Column("foobar"); $this->assertEquals($column->render(3), "foo\nbar"); } public function testColumnUnicodeWordwrap() { - $column = new Zend_Text_Table_Column("Ömläüt"); + $column = new Table\Column("Ömläüt"); $this->assertEquals($column->render(3), "Öml\näüt"); } public function testColumnAlignCenter() { - $column = new Zend_Text_Table_Column("foobar\nfoo", Zend_Text_Table_Column::ALIGN_CENTER); + $column = new Table\Column("foobar\nfoo", Table\Column::ALIGN_CENTER); $this->assertEquals($column->render(10), " foobar \n foo "); } public function testColumnAlignRight() { - $column = new Zend_Text_Table_Column("foobar\nfoo", Zend_Text_Table_Column::ALIGN_RIGHT); + $column = new Table\Column("foobar\nfoo", Table\Column::ALIGN_RIGHT); $this->assertEquals($column->render(10), " foobar\n foo"); } @@ -108,7 +115,7 @@ public function testColumnForcedEncoding() $iso885915 = iconv('utf-8', 'iso-8859-15', 'Ömläüt'); - $column = new Zend_Text_Table_Column($iso885915, null, null, 'iso-8859-15'); + $column = new Table\Column($iso885915, null, null, 'iso-8859-15'); $this->assertEquals($column->render(6), 'Ömläüt'); } @@ -122,8 +129,8 @@ public function testColumnDefaultInputEncoding() $iso885915 = iconv('utf-8', 'iso-8859-15', 'Ömläüt'); - Zend_Text_Table::setInputCharset('iso-8859-15'); - $column = new Zend_Text_Table_Column($iso885915); + Table\Table::setInputCharset('iso-8859-15'); + $column = new Table\Column($iso885915); $this->assertEquals($column->render(6), 'Ömläüt'); } @@ -137,8 +144,8 @@ public function testColumnDefaultOutputEncoding() $iso885915 = iconv('utf-8', 'iso-8859-15', 'Ömläüt'); - Zend_Text_Table::setOutputCharset('iso-8859-15'); - $column = new Zend_Text_Table_Column('Ömläüt'); + Table\Table::setOutputCharset('iso-8859-15'); + $column = new Table\Column('Ömläüt'); $this->assertEquals($column->render(6), $iso885915); } @@ -146,9 +153,9 @@ public function testColumnDefaultOutputEncoding() public function testColumnSetContentInvalidArgument() { try { - $column = new Zend_Text_Table_Column(1); + $column = new Table\Column(1); $this->fail('An expected InvalidArgumentException has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('$content must be a string', $expected->getMessage()); } } @@ -156,9 +163,9 @@ public function testColumnSetContentInvalidArgument() public function testColumnSetAlignInvalidArgument() { try { - $column = new Zend_Text_Table_Column(null, false); + $column = new Table\Column(null, false); $this->fail('An expected InvalidArgumentException has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('Invalid align supplied', $expected->getMessage()); } } @@ -166,9 +173,9 @@ public function testColumnSetAlignInvalidArgument() public function testColumnSetColSpanInvalidArgument() { try { - $column = new Zend_Text_Table_Column(null, null, 0); + $column = new Table\Column(null, null, 0); $this->fail('An expected InvalidArgumentException has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('$colSpan must be an integer and greater than 0', $expected->getMessage()); } } @@ -176,92 +183,92 @@ public function testColumnSetColSpanInvalidArgument() public function testColumnRenderInvalidArgument() { try { - $column = new Zend_Text_Table_Column(); + $column = new Table\Column(); $column->render(0); $this->fail('An expected InvalidArgumentException has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('$columnWidth must be an integer and greater than 0', $expected->getMessage()); } } public function testUnicodeStringPadding() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); - $row->appendColumn(new Zend_Text_Table_Column('Eté')); - $row->appendColumn(new Zend_Text_Table_Column('Ete')); + $row->appendColumn(new Table\Column('Eté')); + $row->appendColumn(new Table\Column('Ete')); $this->assertEquals($row->render(array(10, 10), $decorator), "│Eté │Ete │\n"); } public function testRowColumnsWithColSpan() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); - $row->appendColumn(new Zend_Text_Table_Column('foobar', null, 2)); + $row->appendColumn(new Table\Column('foobar')); + $row->appendColumn(new Table\Column('foobar', null, 2)); $this->assertEquals($row->render(array(10, 10, 10), $decorator), "│foobar │foobar │\n"); } public function testRowWithNoColumns() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $this->assertEquals($row->render(array(10, 10, 10), $decorator), "│ │\n"); } public function testRowNotEnoughColumnWidths() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column()); - $row->appendColumn(new Zend_Text_Table_Column()); + $row = new Table\Row(); + $row->appendColumn(new Table\Column()); + $row->appendColumn(new Table\Column()); try { $row->render(array(10), $decorator); $this->fail('An expected Zend_Text_Table_Exception has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('Too many columns', $expected->getMessage()); } } public function testRowGetColumnWidthsBeforeRendering() { - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); try { $row->getColumnWidths(); $this->fail('An expected Zend_Text_Table_Exception has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('No columns were rendered yet', $expected->getMessage()); } } public function testRowAutoInsertColumns() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar')); $this->assertEquals($row->render(array(10, 10, 10), $decorator), "│foobar │ │\n"); } public function testRowMultiLine() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column("foo\nbar")); - $row->appendColumn(new Zend_Text_Table_Column("foobar")); + $row = new Table\Row(); + $row->appendColumn(new Table\Column("foo\nbar")); + $row->appendColumn(new Table\Column("foobar")); $this->assertEquals($row->render(array(10, 10), $decorator), "│foo │foobar │\n│bar │ │\n"); } @@ -269,9 +276,9 @@ public function testRowMultiLine() public function testTableConstructInvalidColumnWidths() { try { - $table = new Zend_Text_Table(array('columnWidths' => array())); + $table = new Table\Table(array('columnWidths' => array())); $this->fail('An expected Zend_Text_Table_Exception has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('You must supply at least one column', $expected->getMessage()); } } @@ -279,18 +286,18 @@ public function testTableConstructInvalidColumnWidths() public function testTableConstructInvalidColumnWidthsItem() { try { - $table = new Zend_Text_Table(array('columnWidths' => array('foo'))); + $table = new Table\Table(array('columnWidths' => array('foo'))); $this->fail('An expected Zend_Text_Table_Exception has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('Column 0 has an invalid column width', $expected->getMessage()); } } public function testTableDecoratorLoaderSimple() { - $table = new Zend_Text_Table(array('columnWidths' => array(10), 'decorator' => 'ascii')); + $table = new Table\Table(array('columnWidths' => array(10), 'decorator' => 'ascii')); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foobar'); $table->appendRow($row); @@ -299,11 +306,11 @@ public function testTableDecoratorLoaderSimple() public function testTableDecoratorEncodingDefault() { - Zend_Text_Table::setOutputCharset('iso-8859-15'); + Table\Table::setOutputCharset('iso-8859-15'); - $table = new Zend_Text_Table(array('columnWidths' => array(10))); + $table = new Table\Table(array('columnWidths' => array(10))); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foobar'); $table->appendRow($row); @@ -312,9 +319,9 @@ public function testTableDecoratorEncodingDefault() public function testTableDecoratorLoaderAdvanced() { - $table = new Zend_Text_Table(array('columnWidths' => array(10), 'decorator' => new Zend_Text_Table_Decorator_Ascii())); + $table = new Table\Table(array('columnWidths' => array(10), 'decorator' => new Decorator\Ascii())); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foobar'); $table->appendRow($row); @@ -323,9 +330,9 @@ public function testTableDecoratorLoaderAdvanced() public function testTableSimpleRow() { - $table = new Zend_Text_Table(array('columnWidths' => array(10))); + $table = new Table\Table(array('columnWidths' => array(10))); - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foobar'); $table->appendRow($row); @@ -334,9 +341,9 @@ public function testTableSimpleRow() public function testDefaultColumnAlign() { - $table = new Zend_Text_Table(array('columnWidths' => array(10))); + $table = new Table\Table(array('columnWidths' => array(10))); - $table->setDefaultColumnAlign(0, Zend_Text_Table_Column::ALIGN_CENTER); + $table->setDefaultColumnAlign(0, Table\Column::ALIGN_CENTER); $table->appendRow(array('foobar')); @@ -345,7 +352,7 @@ public function testDefaultColumnAlign() public function testRowGetColumns() { - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foo') ->createColumn('bar'); @@ -354,15 +361,15 @@ public function testRowGetColumns() public function testRowGetColumn() { - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foo'); - $this->assertTrue($row->getColumn(0) instanceof Zend_Text_Table_Column); + $this->assertTrue($row->getColumn(0) instanceof Table\Column); } public function testRowGetInvalidColumn() { - $row = new Zend_Text_Table_Row(); + $row = new Table\Row(); $row->createColumn('foo'); $this->assertEquals(null, $row->getColumn(1)); @@ -370,27 +377,27 @@ public function testRowGetInvalidColumn() public function testTableWithoutRows() { - $table = new Zend_Text_Table(array('columnWidths' => array(10))); + $table = new Table\Table(array('columnWidths' => array(10))); try { $table->render(); $this->fail('An expected Zend_Text_Table_Exception has not been raised'); - } catch (Zend_Text_Table_Exception $expected) { + } catch (Table\Exception $expected) { $this->assertContains('No rows were added to the table yet', $expected->getMessage()); } } public function testTableColSpanWithMultipleRows() { - $table = new Zend_Text_Table(array('columnWidths' => array(10, 10))); + $table = new Table\Table(array('columnWidths' => array(10, 10))); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar')); + $row->appendColumn(new Table\Column('foobar')); $table->appendRow($row); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar', null, 2)); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar', null, 2)); $table->appendRow($row); $this->assertEquals($table->render(), "┌──────────┬──────────┐\n" @@ -402,26 +409,26 @@ public function testTableColSpanWithMultipleRows() public function testTableComplex() { - $table = new Zend_Text_Table(array('columnWidths' => array(10, 10, 10))); + $table = new Table\Table(array('columnWidths' => array(10, 10, 10))); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); - $row->appendColumn(new Zend_Text_Table_Column('foobar', null, 2)); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar')); + $row->appendColumn(new Table\Column('foobar', null, 2)); $table->appendRow($row); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); - $row->appendColumn(new Zend_Text_Table_Column('foobar', null, 2)); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar')); + $row->appendColumn(new Table\Column('foobar', null, 2)); $table->appendRow($row); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar', null, 3)); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar', null, 3)); $table->appendRow($row); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar')); + $row->appendColumn(new Table\Column('foobar')); + $row->appendColumn(new Table\Column('foobar')); $table->appendRow($row); $this->assertEquals($table->render(), "┌──────────┬─────────────────────┐\n" @@ -437,10 +444,10 @@ public function testTableComplex() public function testTableMagicToString() { - $table = new Zend_Text_Table(array('columnWidths' => array(10))); + $table = new Table\Table(array('columnWidths' => array(10))); - $row = new Zend_Text_Table_Row(); - $row->appendColumn(new Zend_Text_Table_Column('foobar')); + $row = new Table\Row(); + $row->appendColumn(new Table\Column('foobar')); $table->appendRow($row); $this->assertEquals((string) $table, "┌──────────┐\n│foobar │\n└──────────┘\n"); @@ -448,7 +455,7 @@ public function testTableMagicToString() public function testDecoratorUnicode() { - $decorator = new Zend_Text_Table_Decorator_Unicode(); + $decorator = new Decorator\Unicode(); $chars = $decorator->getBottomLeft() . $decorator->getBottomRight() @@ -467,7 +474,7 @@ public function testDecoratorUnicode() public function testDecoratorAscii() { - $decorator = new Zend_Text_Table_Decorator_Ascii(); + $decorator = new Decorator\Ascii(); $chars = $decorator->getBottomLeft() . $decorator->getBottomRight() @@ -487,5 +494,5 @@ public function testDecoratorAscii() // Call Zend_Text_TableTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Text_TableTest::main") { - Zend_Text_TableTest::main(); + \Zend_Text_TableTest::main(); }