From a2f69b3f960592373589ad595e7965bed475e3c5 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Sun, 3 Jun 2018 09:18:36 -0600 Subject: [PATCH] adding grumphp, php-cs-fixer, fixing style, narrowing namespace --- .gitignore | 3 +- .php_cs | 22 +++ .travis.yml | 13 +- composer.json | 19 ++- grumphp.yml.dist | 17 ++ phpstan.neon | 3 + phpunit.xml.dist | 5 + require-checker-config.json | 10 ++ src/Zend/Translate.php | 15 +- src/Zend/Translate/Adapter.php | 71 ++++---- src/Zend/Translate/Adapter/Array.php | 4 +- src/Zend/Translate/Adapter/Csv.php | 14 +- src/Zend/Translate/Adapter/Gettext.php | 15 +- src/Zend/Translate/Adapter/Ini.php | 4 +- src/Zend/Translate/Adapter/Qt.php | 49 +++--- src/Zend/Translate/Adapter/Tbx.php | 47 +++--- src/Zend/Translate/Adapter/Tmx.php | 31 ++-- src/Zend/Translate/Adapter/Xliff.php | 75 +++++---- src/Zend/Translate/Adapter/XmlTm.php | 33 ++-- src/Zend/Translate/Plural.php | 10 +- tests/Zend/Translate/Adapter/ArrayTest.php | 32 ++-- tests/Zend/Translate/Adapter/CsvTest.php | 6 +- tests/Zend/Translate/Adapter/GettextTest.php | 18 +- tests/Zend/Translate/Adapter/IniTest.php | 6 +- tests/Zend/Translate/Adapter/QtTest.php | 12 +- tests/Zend/Translate/Adapter/TbxTest.php | 12 +- tests/Zend/Translate/Adapter/TmxTest.php | 10 +- tests/Zend/Translate/Adapter/XliffTest.php | 12 +- tests/Zend/Translate/Adapter/XmlTmTest.php | 10 +- .../Zend/Translate/Adapter/_files/failed.php | 2 +- .../en_GB/LC_OTHER/translation-en_US.php | 10 +- .../_files/testarray/ja/translation-ja.php | 10 +- .../Adapter/_files/translation_en.php | 10 +- tests/Zend/TranslateTest.php | 154 ++++++++++-------- 34 files changed, 441 insertions(+), 323 deletions(-) create mode 100644 .php_cs create mode 100644 grumphp.yml.dist create mode 100644 require-checker-config.json diff --git a/.gitignore b/.gitignore index 428888a..9cb6d1a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /composer.lock /clover.xml /tests/Zend/_files/zend_cache* -/tests/Zend/Translate/Adapter/_files/zend_cache* \ No newline at end of file +/tests/Zend/Translate/Adapter/_files/zend_cache* +.php_cs.cache \ No newline at end of file diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..acac6b1 --- /dev/null +++ b/.php_cs @@ -0,0 +1,22 @@ +exclude('vendor') + ->files() + ->in(__DIR__) +; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + '@PHPUnit60Migration:risky' => true, + 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true], + 'single_quote' => true, + 'array_syntax' => ['syntax' => 'long'], + 'concat_space' => ['spacing' => 'one'], + 'psr0' => true + ]) + ->setUsingCache(true) + ->setFinder($finder); +; diff --git a/.travis.yml b/.travis.yml index 5e02ac6..2a8ddce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,11 @@ jobs: allow_failures: - php: nightly include: + - stage: style check + php: 7.1 + env: TMPDIR=/tmp USE_XDEBUG=false + script: + - composer style-check - stage: phpstan analysis php: 7.1 env: TMPDIR=/tmp USE_XDEBUG=false @@ -41,8 +46,14 @@ jobs: - composer phpstan - stage: test with coverage php: 7.1 - env: TMPDIR=/tmp USE_XDEBUG=true + env: TMPDIR=/tmp USE_XDEBUG=true CC_TEST_REPORTER_ID=9e6fb3c2f914008fe81124e4454a3d68f4af30a68bd783a356e50c157afd8559 + before_script: + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build script: - composer test-with-coverage after_success: - bash <(curl -s https://codecov.io/bash) -f ./clover.xml + after_script: + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT \ No newline at end of file diff --git a/composer.json b/composer.json index f97609b..26420f9 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,11 @@ }, "autoload": { "psr-0": { - "Zend_": "src/" - } + "Zend_Translate_": "src/" + }, + "classmap": [ + "src/Zend/Translate.php" + ] }, "autoload-dev": { "psr-0": { @@ -32,7 +35,10 @@ }, "require-dev": { "phpunit/phpunit": "^6.0", - "phpstan/phpstan": "^0.9.2" + "phpstan/phpstan": "^0.9.2", + "friendsofphp/php-cs-fixer": "^2.11", + "maglnet/composer-require-checker": "^0.1.6 | ^0.2.1", + "phpro/grumphp": "^0.14.0" }, "include-path": [ "src/" @@ -41,9 +47,10 @@ "exclude": ["/tests"] }, "scripts": { - "test": "phpunit ./tests", - "test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests", - "phpstan": "phpstan analyze -l4 -c phpstan.neon --no-progress ./src --ansi" + "test": "phpunit", + "test-with-coverage": "phpunit --coverage-clover=clover.xml", + "phpstan": "phpstan analyze -l4 -c phpstan.neon --no-progress ./ --ansi", + "style-check": "php-cs-fixer fix --dry-run -vv" }, "suggest": { "ext-xml": "Many of the translation adapters require this extension" diff --git a/grumphp.yml.dist b/grumphp.yml.dist new file mode 100644 index 0000000..c635c1e --- /dev/null +++ b/grumphp.yml.dist @@ -0,0 +1,17 @@ +# grumphp.yml +parameters: + tasks: + composer: + strict: true + composer_require_checker: + config_file: require-checker-config.json + phpcsfixer2: + allow_risky: true + config: .php_cs + phpstan: + level: 4 + configuration: phpstan.neon + phpunit: + metadata: + priority: 100 + always_execute: true diff --git a/phpstan.neon b/phpstan.neon index b14d2c6..01ccc62 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,7 @@ parameters: + excludes_analyse: + - %rootDir%/../../../vendor/* + - %rootDir%/../../../tests/* ignoreErrors: - '#Variable \$number might not be defined\.#' - '#Variable \$plocale might not be defined\.#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 078072b..2204d13 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,11 @@ backupGlobals="true" stderr="true" colors="true"> + + + ./tests + + ./src diff --git a/require-checker-config.json b/require-checker-config.json new file mode 100644 index 0000000..d7a9d4e --- /dev/null +++ b/require-checker-config.json @@ -0,0 +1,10 @@ +{ + "symbol-whitelist" : [ + "null", "true", "false", + "static", "self", "parent", + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", + "xml_parser_create", "xml_set_object", "xml_parser_set_option", "XML_OPTION_CASE_FOLDING", + "xml_set_element_handler", "xml_set_character_data_handler", "xml_parse", "xml_error_string", "xml_get_error_code", + "xml_get_current_line_number", "xml_parser_free" + ] +} diff --git a/src/Zend/Translate.php b/src/Zend/Translate.php index 50b5232..136ba39 100644 --- a/src/Zend/Translate.php +++ b/src/Zend/Translate.php @@ -25,7 +25,8 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate { +class Zend_Translate +{ /** * Adapter names constants */ @@ -61,7 +62,7 @@ public function __construct($options = array()) { if ($options instanceof Zend_Config) { $options = $options->toArray(); - } else if (func_num_args() > 1) { + } elseif (func_num_args() > 1) { $args = func_get_args(); $options = array(); $options['adapter'] = array_shift($args); @@ -77,7 +78,7 @@ public function __construct($options = array()) $opt = array_shift($args); $options = array_merge($opt, $options); } - } else if (!is_array($options)) { + } elseif (!is_array($options)) { $options = array('adapter' => $options); } @@ -96,7 +97,7 @@ public function setAdapter($options = array()) { if ($options instanceof Zend_Config) { $options = $options->toArray(); - } else if (func_num_args() > 1) { + } elseif (func_num_args() > 1) { $args = func_get_args(); $options = array(); $options['adapter'] = array_shift($args); @@ -112,11 +113,11 @@ public function setAdapter($options = array()) $opt = array_shift($args); $options = array_merge($opt, $options); } - } else if (!is_array($options)) { + } elseif (!is_array($options)) { $options = array('adapter' => $options); } - if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($options['adapter']). '.php')) { + if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($options['adapter']) . '.php')) { $options['adapter'] = 'Zend_Translate_Adapter_' . ucfirst($options['adapter']); } @@ -132,7 +133,7 @@ public function setAdapter($options = array()) unset($options['adapter']); $this->_adapter = new $adapter($options); if (!$this->_adapter instanceof Zend_Translate_Adapter) { - throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter"); + throw new Zend_Translate_Exception('Adapter ' . $adapter . ' does not extend Zend_Translate_Adapter'); } } diff --git a/src/Zend/Translate/Adapter.php b/src/Zend/Translate/Adapter.php index 7b7c2d8..5c8f192 100644 --- a/src/Zend/Translate/Adapter.php +++ b/src/Zend/Translate/Adapter.php @@ -29,7 +29,8 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -abstract class Zend_Translate_Adapter { +abstract class Zend_Translate_Adapter +{ /** * Shows if locale detection is in automatic level * @var boolean @@ -46,7 +47,7 @@ abstract class Zend_Translate_Adapter { * Internal cache for all adapters * @var Zend_Cache_Core|null */ - protected static $_cache = null; + protected static $_cache = null; /** * Internal value to remember if cache supports tags @@ -65,7 +66,7 @@ abstract class Zend_Translate_Adapter { * Scans for the locale within the name of the file * @constant integer */ - const LOCALE_FILENAME = 'filename'; + const LOCALE_FILENAME = 'filename'; /** * Array with all options, each adapter can have own additional options @@ -119,7 +120,7 @@ public function __construct($options = array()) { if ($options instanceof Zend_Config) { $options = $options->toArray(); - } else if (func_num_args() > 1) { + } elseif (func_num_args() > 1) { $args = func_get_args(); $options = array(); $options['content'] = array_shift($args); @@ -132,7 +133,7 @@ public function __construct($options = array()) $opt = array_shift($args); $options = array_merge($opt, $options); } - } else if (!is_array($options)) { + } elseif (!is_array($options)) { $options = array('content' => $options); } @@ -142,14 +143,14 @@ public function __construct($options = array()) } if (isset(self::$_cache)) { - $id = 'Zend_Translate_' . $this->toString() . '_Options'; + $id = 'Zend_Translate_' . $this->toString() . '_Options'; $result = self::$_cache->load($id); if ($result) { $this->_options = $result; } } - if (empty($options['locale']) || ($options['locale'] === "auto")) { + if (empty($options['locale']) || ($options['locale'] === 'auto')) { $this->_automatic = true; } else { $this->_automatic = false; @@ -188,8 +189,8 @@ public function addTranslation($options = array()) { if ($options instanceof Zend_Config) { $options = $options->toArray(); - } else if (func_num_args() > 1) { - $args = func_get_args(); + } elseif (func_num_args() > 1) { + $args = func_get_args(); $options = array(); $options['content'] = array_shift($args); @@ -201,7 +202,7 @@ public function addTranslation($options = array()) $opt = array_shift($args); $options = array_merge($opt, $options); } - } else if (!is_array($options)) { + } elseif (!is_array($options)) { $options = array('content' => $options); } @@ -230,14 +231,15 @@ public function addTranslation($options = array()) throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e); } - $options = $options + $this->_options; + $options = $options + $this->_options; if (is_string($options['content']) and is_dir($options['content'])) { $options['content'] = realpath($options['content']); - $prev = ''; - $iterator = new RecursiveIteratorIterator( + $prev = ''; + $iterator = new RecursiveIteratorIterator( new RecursiveRegexIterator( new RecursiveDirectoryIterator($options['content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME), - '/^(?!.*(\.svn|\.cvs)).*$/', RecursiveRegexIterator::MATCH + '/^(?!.*(\.svn|\.cvs)).*$/', + RecursiveRegexIterator::MATCH ), RecursiveIteratorIterator::SELF_FIRST ); @@ -251,7 +253,7 @@ public function addTranslation($options = array()) // ignore files matching the given regex from option 'ignore' and all files below continue 2; } - } else if (strpos($directory, DIRECTORY_SEPARATOR . $ignore) !== false) { + } elseif (strpos($directory, DIRECTORY_SEPARATOR . $ignore) !== false) { // ignore files matching first characters from option 'ignore' and all files below continue 2; } @@ -269,7 +271,7 @@ public function addTranslation($options = array()) $options['locale'] = $file; $prev = (string) $options['locale']; } - } else if ($info->isFile()) { + } elseif ($info->isFile()) { // filename as locale if ($options['scan'] === self::LOCALE_FILENAME) { $filename = explode('.', $file); @@ -280,18 +282,18 @@ public function addTranslation($options = array()) } else { $parts = explode('.', $file); $parts2 = array(); - foreach($parts as $token) { + foreach ($parts as $token) { $parts2 += explode('_', $token); } $parts = array_merge($parts, $parts2); $parts2 = array(); - foreach($parts as $token) { + foreach ($parts as $token) { $parts2 += explode('-', $token); } $parts = array_merge($parts, $parts2); $parts = array_unique($parts); $prev = ''; - foreach($parts as $token) { + foreach ($parts as $token) { if (Zend_Locale::isLocale($token, true, false)) { if (strlen($prev) <= strlen($token)) { $options['locale'] = $token; @@ -337,7 +339,7 @@ public function setOptions(array $options = array()) foreach ($options as $key => $option) { if ($key == 'locale') { $locale = $option; - } else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or + } elseif ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or !isset($this->_options[$key])) { if (($key == 'log') && !($option instanceof Zend_Log)) { throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log'); @@ -349,7 +351,7 @@ public function setOptions(array $options = array()) } $this->_options[$key] = $option; - $change = true; + $change = true; } } @@ -408,7 +410,7 @@ public function getLocale() */ public function setLocale($locale) { - if (($locale === "auto") or ($locale === null)) { + if (($locale === 'auto') or ($locale === null)) { $this->_automatic = true; } else { $this->_automatic = false; @@ -468,9 +470,9 @@ public function setLocale($locale) */ public function getList() { - $list = array_keys($this->_translate); + $list = array_keys($this->_translate); $result = null; - foreach($list as $value) { + foreach ($list as $value) { if (!empty($this->_translate[$value])) { $result[$value] = $value; } @@ -573,8 +575,8 @@ private function _addTranslationData($options = array()) { if ($options instanceof Zend_Config) { $options = $options->toArray(); - } else if (func_num_args() > 1) { - $args = func_get_args(); + } elseif (func_num_args() > 1) { + $args = func_get_args(); $options['content'] = array_shift($args); if (!empty($args)) { @@ -616,7 +618,7 @@ private function _addTranslationData($options = array()) $read = true; $temp = array(); if (isset(self::$_cache)) { - $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString(); + $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString(); $temp = self::$_cache->load($id); if ($temp) { $read = false; @@ -640,7 +642,7 @@ private function _addTranslationData($options = array()) } $keys = array_keys($temp); - foreach($keys as $key) { + foreach ($keys as $key) { if (!isset($this->_translate[$key])) { $this->_translate[$key] = array(); } @@ -651,10 +653,10 @@ private function _addTranslationData($options = array()) } if ($this->_automatic === true) { - $find = new Zend_Locale($options['locale']); + $find = new Zend_Locale($options['locale']); $browser = $find->getEnvironment() + $find->getBrowser(); arsort($browser); - foreach($browser as $language => $quality) { + foreach ($browser as $language => $quality) { if (isset($this->_translate[$language])) { $this->_options['locale'] = $language; break; @@ -750,7 +752,7 @@ public function translate($messageId, $locale = null) $this->_routed = array(); return $this->_translate[$locale][$plural[0]][$rule]; } - } else if (strlen($locale) != 2) { + } elseif (strlen($locale) != 2) { // faster than creating a new locale and separate the leading part $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); @@ -815,7 +817,8 @@ public function plural($singular, $plural, $number, $locale = null) * @param string $message Message to log * @param String $locale Locale to log */ - protected function _log($message, $locale) { + protected function _log($message, $locale) + { if ($this->_options['logUntranslated']) { $message = str_replace('%message%', $message, $this->_options['logMessage']); $message = str_replace('%locale%', $locale, $message); @@ -877,7 +880,7 @@ public function isTranslated($messageId, $original = false, $locale = null) if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) { // return original translation return true; - } else if ((strlen($locale) != 2) and ($original === false)) { + } elseif ((strlen($locale) != 2) and ($original === false)) { // faster than creating a new locale and separate the leading part $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); @@ -969,7 +972,7 @@ private static function _getTagSupportForCache() { $backend = self::$_cache->getBackend(); if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) { - $cacheOptions = $backend->getCapabilities(); + $cacheOptions = $backend->getCapabilities(); self::$_cacheTags = $cacheOptions['tags']; } else { self::$_cacheTags = false; diff --git a/src/Zend/Translate/Adapter/Array.php b/src/Zend/Translate/Adapter/Array.php index 512c027..599dce6 100644 --- a/src/Zend/Translate/Adapter/Array.php +++ b/src/Zend/Translate/Adapter/Array.php @@ -50,7 +50,7 @@ protected function _loadTranslationData($data, $locale, array $options = array() } } if (!is_array($data)) { - throw new Zend_Translate_Exception("Error including array or file '".$data."'"); + throw new Zend_Translate_Exception("Error including array or file '" . $data . "'"); } if (!isset($this->_data[$locale])) { @@ -68,6 +68,6 @@ protected function _loadTranslationData($data, $locale, array $options = array() */ public function toString() { - return "Array"; + return 'Array'; } } diff --git a/src/Zend/Translate/Adapter/Csv.php b/src/Zend/Translate/Adapter/Csv.php index ddd238b..11642f8 100644 --- a/src/Zend/Translate/Adapter/Csv.php +++ b/src/Zend/Translate/Adapter/Csv.php @@ -28,7 +28,7 @@ */ class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter { - private $_data = array(); + private $_data = array(); /** * @var resource @@ -42,13 +42,13 @@ class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter */ public function __construct($options = array()) { - $this->_options['delimiter'] = ";"; + $this->_options['delimiter'] = ';'; $this->_options['length'] = 0; $this->_options['enclosure'] = '"'; if ($options instanceof Zend_Config) { $options = $options->toArray(); - } else if (func_num_args() > 1) { + } elseif (func_num_args() > 1) { $args = func_get_args(); $options = array(); $options['content'] = array_shift($args); @@ -61,7 +61,7 @@ public function __construct($options = array()) $opt = array_shift($args); $options = array_merge($opt, $options); } - } else if (!is_array($options)) { + } elseif (!is_array($options)) { $options = array('content' => $options); } @@ -86,7 +86,7 @@ protected function _loadTranslationData($filename, $locale, array $options = arr throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.'); } - while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) { + while (($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) { if (substr($data[0], 0, 1) === '#') { continue; } @@ -98,7 +98,7 @@ protected function _loadTranslationData($filename, $locale, array $options = arr if (count($data) == 2) { $this->_data[$locale][$data[0]] = $data[1]; } else { - $singular = array_shift($data); + $singular = array_shift($data); $this->_data[$locale][$singular] = $data; } } @@ -113,6 +113,6 @@ protected function _loadTranslationData($filename, $locale, array $options = arr */ public function toString() { - return "Csv"; + return 'Csv'; } } diff --git a/src/Zend/Translate/Adapter/Gettext.php b/src/Zend/Translate/Adapter/Gettext.php index dd914b5..9059075 100644 --- a/src/Zend/Translate/Adapter/Gettext.php +++ b/src/Zend/Translate/Adapter/Gettext.php @@ -25,7 +25,8 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter { +class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter +{ // Internal variables private $_bigEndian = false; private $_file = false; @@ -71,9 +72,9 @@ protected function _loadTranslationData($filename, $locale, array $options = arr // get Endian $input = $this->_readMOData(1); - if (strtolower(substr(dechex($input[1]), -8)) == "950412de") { + if (strtolower(substr(dechex($input[1]), -8)) == '950412de') { $this->_bigEndian = false; - } else if (strtolower(substr(dechex($input[1]), -8)) == "de120495") { + } elseif (strtolower(substr(dechex($input[1]), -8)) == 'de120495') { $this->_bigEndian = true; } else { @fclose($this->_file); @@ -87,11 +88,11 @@ protected function _loadTranslationData($filename, $locale, array $options = arr $total = $input[1]; // number of original strings - $input = $this->_readMOData(1); + $input = $this->_readMOData(1); $OOffset = $input[1]; // number of translation strings - $input = $this->_readMOData(1); + $input = $this->_readMOData(1); $TOffset = $input[1]; // fill the original table @@ -100,7 +101,7 @@ protected function _loadTranslationData($filename, $locale, array $options = arr fseek($this->_file, $TOffset); $transtemp = $this->_readMOData(2 * $total); - for($count = 0; $count < $total; ++$count) { + for ($count = 0; $count < $total; ++$count) { if ($origtemp[$count * 2 + 1] != 0) { fseek($this->_file, $origtemp[$count * 2 + 2]); $original = @fread($this->_file, $origtemp[$count * 2 + 1]); @@ -155,6 +156,6 @@ public function getAdapterInfo() */ public function toString() { - return "Gettext"; + return 'Gettext'; } } diff --git a/src/Zend/Translate/Adapter/Ini.php b/src/Zend/Translate/Adapter/Ini.php index c40e634..494e433 100644 --- a/src/Zend/Translate/Adapter/Ini.php +++ b/src/Zend/Translate/Adapter/Ini.php @@ -43,7 +43,7 @@ protected function _loadTranslationData($data, $locale, array $options = array() { $this->_data = array(); if (!file_exists($data)) { - throw new Zend_Translate_Exception("Ini file '".$data."' not found"); + throw new Zend_Translate_Exception("Ini file '" . $data . "' not found"); } $inidata = parse_ini_file($data, false); @@ -62,6 +62,6 @@ protected function _loadTranslationData($data, $locale, array $options = array() */ public function toString() { - return "Ini"; + return 'Ini'; } } diff --git a/src/Zend/Translate/Adapter/Qt.php b/src/Zend/Translate/Adapter/Qt.php index e393801..9165172 100644 --- a/src/Zend/Translate/Adapter/Qt.php +++ b/src/Zend/Translate/Adapter/Qt.php @@ -26,18 +26,19 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter { +class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter +{ // Internal variables - private $_file = false; - private $_cleared = array(); - private $_transunit = null; - private $_source = null; - private $_target = null; - private $_scontent = null; - private $_tcontent = null; - private $_stag = false; - private $_ttag = true; - private $_data = array(); + private $_file = false; + private $_cleared = array(); + private $_transunit = null; + private $_source = null; + private $_target = null; + private $_scontent = null; + private $_tcontent = null; + private $_stag = false; + private $_ttag = true; + private $_data = array(); /** * Load translation data (QT file reader) @@ -58,12 +59,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr $this->_target = $locale; - $encoding = $this->_findEncoding($filename); + $encoding = $this->_findEncoding($filename); $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($this->_file, "_startElement", "_endElement"); - xml_set_character_data_handler($this->_file, "_contentElement"); + xml_set_element_handler($this->_file, '_startElement', '_endElement'); + xml_set_character_data_handler($this->_file, '_contentElement'); try { Zend_Xml_Security::scanFile($filename); @@ -74,10 +75,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr } if (!xml_parse($this->_file, file_get_contents($filename))) { - $ex = sprintf('XML error: %s at line %d of file %s', + $ex = sprintf( + 'XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), - $filename); + $filename + ); xml_parser_free($this->_file); throw new Zend_Translate_Exception($ex); } @@ -87,11 +90,11 @@ protected function _loadTranslationData($filename, $locale, array $options = arr private function _startElement($file, $name, $attrib) { - switch(strtolower($name)) { + switch (strtolower($name)) { case 'message': - $this->_source = null; - $this->_stag = false; - $this->_ttag = false; + $this->_source = null; + $this->_stag = false; + $this->_ttag = false; $this->_scontent = null; $this->_tcontent = null; break; @@ -140,8 +143,8 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { $file = file_get_contents($filename, null, null, 0, 100); - if (strpos($file, "encoding") !== false) { - $encoding = substr($file, strpos($file, "encoding") + 9); + if (strpos($file, 'encoding') !== false) { + $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); return $encoding; } @@ -155,6 +158,6 @@ private function _findEncoding($filename) */ public function toString() { - return "Qt"; + return 'Qt'; } } diff --git a/src/Zend/Translate/Adapter/Tbx.php b/src/Zend/Translate/Adapter/Tbx.php index 2320bea..46627fd 100644 --- a/src/Zend/Translate/Adapter/Tbx.php +++ b/src/Zend/Translate/Adapter/Tbx.php @@ -26,15 +26,16 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter { +class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter +{ // Internal variables - private $_file = false; - private $_cleared = array(); - private $_langset = null; - private $_termentry = null; - private $_content = null; - private $_term = null; - private $_data = array(); + private $_file = false; + private $_cleared = array(); + private $_langset = null; + private $_termentry = null; + private $_content = null; + private $_term = null; + private $_data = array(); /** * Load translation data (TBX file reader) @@ -53,12 +54,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.'); } - $encoding = $this->_findEncoding($filename); + $encoding = $this->_findEncoding($filename); $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($this->_file, "_startElement", "_endElement"); - xml_set_character_data_handler($this->_file, "_contentElement"); + xml_set_element_handler($this->_file, '_startElement', '_endElement'); + xml_set_character_data_handler($this->_file, '_contentElement'); try { Zend_Xml_Security::scanFile($filename); @@ -69,10 +70,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr } if (!xml_parse($this->_file, file_get_contents($filename))) { - $ex = sprintf('XML error: %s at line %d of file %s', + $ex = sprintf( + 'XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), - $filename); + $filename + ); xml_parser_free($this->_file); throw new Zend_Translate_Exception($ex); } @@ -83,13 +86,13 @@ protected function _loadTranslationData($filename, $locale, array $options = arr private function _startElement($file, $name, $attrib) { if ($this->_term !== null) { - $this->_content .= "<".$name; - foreach($attrib as $key => $value) { + $this->_content .= '<' . $name; + foreach ($attrib as $key => $value) { $this->_content .= " $key=\"$value\""; } - $this->_content .= ">"; + $this->_content .= '>'; } else { - switch(strtolower($name)) { + switch (strtolower($name)) { case 'termentry': $this->_termentry = null; break; @@ -113,8 +116,8 @@ private function _startElement($file, $name, $attrib) private function _endElement($file, $name) { - if (($this->_term !== null) and ($name != "term")) { - $this->_content .= ""; + if (($this->_term !== null) and ($name != 'term')) { + $this->_content .= ''; } else { switch (strtolower($name)) { case 'langset': @@ -145,8 +148,8 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { $file = file_get_contents($filename, null, null, 0, 100); - if (strpos($file, "encoding") !== false) { - $encoding = substr($file, strpos($file, "encoding") + 9); + if (strpos($file, 'encoding') !== false) { + $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); return $encoding; } @@ -160,6 +163,6 @@ private function _findEncoding($filename) */ public function toString() { - return "Tbx"; + return 'Tbx'; } } diff --git a/src/Zend/Translate/Adapter/Tmx.php b/src/Zend/Translate/Adapter/Tmx.php index 5f71d15..e3c274f 100644 --- a/src/Zend/Translate/Adapter/Tmx.php +++ b/src/Zend/Translate/Adapter/Tmx.php @@ -26,7 +26,8 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter { +class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter +{ // Internal variables private $_file = false; private $_useId = true; @@ -58,12 +59,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr $this->_useId = (boolean) $options['useId']; } - $encoding = $this->_findEncoding($filename); + $encoding = $this->_findEncoding($filename); $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($this->_file, "_startElement", "_endElement"); - xml_set_character_data_handler($this->_file, "_contentElement"); + xml_set_element_handler($this->_file, '_startElement', '_endElement'); + xml_set_character_data_handler($this->_file, '_contentElement'); try { Zend_Xml_Security::scanFile($filename); @@ -74,10 +75,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr } if (!xml_parse($this->_file, file_get_contents($filename))) { - $ex = sprintf('XML error: %s at line %d of file %s', + $ex = sprintf( + 'XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), - $filename); + $filename + ); xml_parser_free($this->_file); throw new Zend_Translate_Exception($ex); } @@ -95,13 +98,13 @@ protected function _loadTranslationData($filename, $locale, array $options = arr protected function _startElement($file, $name, $attrib) { if ($this->_seg !== null) { - $this->_content .= "<".$name; - foreach($attrib as $key => $value) { + $this->_content .= '<' . $name; + foreach ($attrib as $key => $value) { $this->_content .= " $key=\"$value\""; } - $this->_content .= ">"; + $this->_content .= '>'; } else { - switch(strtolower($name)) { + switch (strtolower($name)) { case 'header': if (empty($this->_useId) && isset($attrib['srclang'])) { if (Zend_Locale::isLocale($attrib['srclang'])) { @@ -165,7 +168,7 @@ protected function _startElement($file, $name, $attrib) protected function _endElement($file, $name) { if (($this->_seg !== null) and ($name !== 'seg')) { - $this->_content .= ""; + $this->_content .= ''; } else { switch (strtolower($name)) { case 'tu': @@ -213,8 +216,8 @@ protected function _contentElement($file, $data) protected function _findEncoding($filename) { $file = file_get_contents($filename, null, null, 0, 100); - if (strpos($file, "encoding") !== false) { - $encoding = substr($file, strpos($file, "encoding") + 9); + if (strpos($file, 'encoding') !== false) { + $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); return $encoding; } @@ -228,6 +231,6 @@ protected function _findEncoding($filename) */ public function toString() { - return "Tmx"; + return 'Tmx'; } } diff --git a/src/Zend/Translate/Adapter/Xliff.php b/src/Zend/Translate/Adapter/Xliff.php index be3ef41..f4f70da 100644 --- a/src/Zend/Translate/Adapter/Xliff.php +++ b/src/Zend/Translate/Adapter/Xliff.php @@ -26,20 +26,21 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter { +class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter +{ // Internal variables - private $_file = false; - private $_useId = true; - private $_cleared = array(); - private $_transunit = null; - private $_source = null; - private $_target = null; - private $_langId = null; - private $_scontent = null; - private $_tcontent = null; - private $_stag = false; - private $_ttag = false; - private $_data = array(); + private $_file = false; + private $_useId = true; + private $_cleared = array(); + private $_transunit = null; + private $_source = null; + private $_target = null; + private $_langId = null; + private $_scontent = null; + private $_tcontent = null; + private $_stag = false; + private $_ttag = false; + private $_data = array(); /** * Load translation data (XLIFF file reader) @@ -69,8 +70,8 @@ protected function _loadTranslationData($filename, $locale, array $options = arr $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($this->_file, "_startElement", "_endElement"); - xml_set_character_data_handler($this->_file, "_contentElement"); + xml_set_element_handler($this->_file, '_startElement', '_endElement'); + xml_set_character_data_handler($this->_file, '_contentElement'); try { Zend_Xml_Security::scanFile($filename); @@ -81,10 +82,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr } if (!xml_parse($this->_file, file_get_contents($filename))) { - $ex = sprintf('XML error: %s at line %d of file %s', + $ex = sprintf( + 'XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), - $filename); + $filename + ); xml_parser_free($this->_file); throw new Zend_Translate_Exception($ex); } @@ -95,19 +98,19 @@ protected function _loadTranslationData($filename, $locale, array $options = arr private function _startElement($file, $name, $attrib) { if ($this->_stag === true) { - $this->_scontent .= "<".$name; - foreach($attrib as $key => $value) { + $this->_scontent .= '<' . $name; + foreach ($attrib as $key => $value) { $this->_scontent .= " $key=\"$value\""; } - $this->_scontent .= ">"; - } else if ($this->_ttag === true) { - $this->_tcontent .= "<".$name; - foreach($attrib as $key => $value) { + $this->_scontent .= '>'; + } elseif ($this->_ttag === true) { + $this->_tcontent .= '<' . $name; + foreach ($attrib as $key => $value) { $this->_tcontent .= " $key=\"$value\""; } - $this->_tcontent .= ">"; + $this->_tcontent .= '>'; } else { - switch(strtolower($name)) { + switch (strtolower($name)) { case 'file': $this->_source = $attrib['source-language']; if (isset($attrib['target-language'])) { @@ -125,20 +128,20 @@ private function _startElement($file, $name, $attrib) break; case 'trans-unit': $this->_transunit = true; - $this->_langId = $attrib['id']; + $this->_langId = $attrib['id']; break; case 'source': if ($this->_transunit === true) { $this->_scontent = null; - $this->_stag = true; - $this->_ttag = false; + $this->_stag = true; + $this->_ttag = false; } break; case 'target': if ($this->_transunit === true) { $this->_tcontent = null; - $this->_ttag = true; - $this->_stag = false; + $this->_ttag = true; + $this->_stag = false; } break; default: @@ -150,9 +153,9 @@ private function _startElement($file, $name, $attrib) private function _endElement($file, $name) { if (($this->_stag === true) and ($name !== 'source')) { - $this->_scontent .= ""; - } else if (($this->_ttag === true) and ($name !== 'target')) { - $this->_tcontent .= ""; + $this->_scontent .= ''; + } elseif (($this->_ttag === true) and ($name !== 'target')) { + $this->_tcontent .= ''; } else { switch (strtolower($name)) { case 'trans-unit': @@ -209,8 +212,8 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { $file = file_get_contents($filename, null, null, 0, 100); - if (strpos($file, "encoding") !== false) { - $encoding = substr($file, strpos($file, "encoding") + 9); + if (strpos($file, 'encoding') !== false) { + $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); return $encoding; } @@ -224,6 +227,6 @@ private function _findEncoding($filename) */ public function toString() { - return "Xliff"; + return 'Xliff'; } } diff --git a/src/Zend/Translate/Adapter/XmlTm.php b/src/Zend/Translate/Adapter/XmlTm.php index 58ea462..850c2c6 100644 --- a/src/Zend/Translate/Adapter/XmlTm.php +++ b/src/Zend/Translate/Adapter/XmlTm.php @@ -26,14 +26,15 @@ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter { +class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter +{ // Internal variables - private $_file = false; - private $_cleared = array(); - private $_lang = null; - private $_content = null; - private $_tag = null; - private $_data = array(); + private $_file = false; + private $_cleared = array(); + private $_lang = null; + private $_content = null; + private $_tag = null; + private $_data = array(); /** * Load translation data (XMLTM file reader) @@ -57,8 +58,8 @@ protected function _loadTranslationData($filename, $locale, array $options = arr $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($this->_file, "_startElement", "_endElement"); - xml_set_character_data_handler($this->_file, "_contentElement"); + xml_set_element_handler($this->_file, '_startElement', '_endElement'); + xml_set_character_data_handler($this->_file, '_contentElement'); try { Zend_Xml_Security::scanFile($filename); @@ -69,10 +70,12 @@ protected function _loadTranslationData($filename, $locale, array $options = arr } if (!xml_parse($this->_file, file_get_contents($filename))) { - $ex = sprintf('XML error: %s at line %d of file %s', + $ex = sprintf( + 'XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), - $filename); + $filename + ); xml_parser_free($this->_file); throw new Zend_Translate_Exception($ex); } @@ -82,7 +85,7 @@ protected function _loadTranslationData($filename, $locale, array $options = arr private function _startElement($file, $name, $attrib) { - switch(strtolower($name)) { + switch (strtolower($name)) { case 'tm:tu': $this->_tag = $attrib['id']; $this->_content = null; @@ -119,8 +122,8 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { $file = file_get_contents($filename, null, null, 0, 100); - if (strpos($file, "encoding") !== false) { - $encoding = substr($file, strpos($file, "encoding") + 9); + if (strpos($file, 'encoding') !== false) { + $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); return $encoding; } @@ -134,6 +137,6 @@ private function _findEncoding($filename) */ public function toString() { - return "XmlTm"; + return 'XmlTm'; } } diff --git a/src/Zend/Translate/Plural.php b/src/Zend/Translate/Plural.php index d595b30..3c2665c 100644 --- a/src/Zend/Translate/Plural.php +++ b/src/Zend/Translate/Plural.php @@ -45,9 +45,9 @@ class Zend_Translate_Plural */ public static function getPlural($number, $locale) { - if ($locale == "pt_BR") { + if ($locale == 'pt_BR') { // temporary set a locale for brasilian - $locale = "xbr"; + $locale = 'xbr'; } if (strlen($locale) > 3) { @@ -64,7 +64,7 @@ public static function getPlural($number, $locale) return $return; } - switch($locale) { + switch ($locale) { case 'az': case 'bo': case 'dz': @@ -205,9 +205,9 @@ public static function getPlural($number, $locale) */ public static function setPlural($rule, $locale) { - if ($locale == "pt_BR") { + if ($locale == 'pt_BR') { // temporary set a locale for brasilian - $locale = "xbr"; + $locale = 'xbr'; } if (strlen($locale) > 3) { diff --git a/tests/Zend/Translate/Adapter/ArrayTest.php b/tests/Zend/Translate/Adapter/ArrayTest.php index 3ededd5..b5a9986 100644 --- a/tests/Zend/Translate/Adapter/ArrayTest.php +++ b/tests/Zend/Translate/Adapter/ArrayTest.php @@ -117,7 +117,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.php', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -176,7 +176,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -238,7 +238,7 @@ public function testDisablingNotices() public function testGettingAllMessageIds() { $adapter = new Zend_Translate_Adapter_Array(dirname(__FILE__) . '/_files/translation_en.php', 'en'); - $this->assertEquals(6, count($adapter->getMessageIds())); + $this->assertCount(6, $adapter->getMessageIds()); $test = $adapter->getMessageIds(); $this->assertEquals('Message 1', $test[0]); } @@ -246,7 +246,7 @@ public function testGettingAllMessageIds() public function testGettingMessages() { $adapter = new Zend_Translate_Adapter_Array(dirname(__FILE__) . '/_files/translation_en.php', 'en'); - $this->assertEquals(6, count($adapter->getMessages())); + $this->assertCount(6, $adapter->getMessages()); $test = $adapter->getMessages(); $this->assertEquals('Message 1 (en)', $test['Message 1']); } @@ -254,16 +254,19 @@ public function testGettingMessages() public function testGettingAllMessages() { $adapter = new Zend_Translate_Adapter_Array(dirname(__FILE__) . '/_files/translation_en.php', 'en'); - $this->assertEquals(1, count($adapter->getMessages('all'))); + $this->assertCount(1, $adapter->getMessages('all')); $test = $adapter->getMessages('all'); $this->assertEquals('Message 1 (en)', $test['en']['Message 1']); } public function testCaching() { - $cache = Zend_Cache::factory('Core', 'File', - array('lifetime' => 120, 'automatic_serialization' => true), - array('cache_dir' => dirname(__FILE__) . '/_files/')); + $cache = Zend_Cache::factory( + 'Core', + 'File', + array('lifetime' => 120, 'automatic_serialization' => true), + array('cache_dir' => dirname(__FILE__) . '/_files/') + ); $this->assertFalse(Zend_Translate_Adapter_Array::hasCache()); Zend_Translate_Adapter_Array::setCache($cache); @@ -272,7 +275,7 @@ public function testCaching() $adapter = new Zend_Translate_Adapter_Array(dirname(__FILE__) . '/_files/translation_en.php', 'en'); $cache = Zend_Translate_Adapter_Array::getCache(); $this->assertTrue($cache instanceof Zend_Cache_Core); - unset ($adapter); + unset($adapter); $adapter = new Zend_Translate_Adapter_Array(dirname(__FILE__) . '/_files/translation_en.php', 'en'); $cache = Zend_Translate_Adapter_Array::getCache(); @@ -291,9 +294,12 @@ public function testCaching() public function testLoadingFilesIntoCacheAfterwards() { - $cache = Zend_Cache::factory('Core', 'File', - array('lifetime' => 120, 'automatic_serialization' => true), - array('cache_dir' => dirname(__FILE__) . '/_files/')); + $cache = Zend_Cache::factory( + 'Core', + 'File', + array('lifetime' => 120, 'automatic_serialization' => true), + array('cache_dir' => dirname(__FILE__) . '/_files/') + ); $this->assertFalse(Zend_Translate_Adapter_Array::hasCache()); Zend_Translate_Adapter_Array::setCache($cache); @@ -305,7 +311,7 @@ public function testLoadingFilesIntoCacheAfterwards() $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.php', 'ru', array('reload' => true)); $test = $adapter->getMessages('all'); - $this->assertEquals(6, count($test['ru'])); + $this->assertCount(6, $test['ru']); } /** diff --git a/tests/Zend/Translate/Adapter/CsvTest.php b/tests/Zend/Translate/Adapter/CsvTest.php index 34f0b45..a75f5b9 100644 --- a/tests/Zend/Translate/Adapter/CsvTest.php +++ b/tests/Zend/Translate/Adapter/CsvTest.php @@ -45,7 +45,7 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Csv(dirname(__FILE__) . '/_files/nofile.csv', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Error opening translation file', $e->getMessage()); } @@ -92,7 +92,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.csv', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -153,7 +153,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } diff --git a/tests/Zend/Translate/Adapter/GettextTest.php b/tests/Zend/Translate/Adapter/GettextTest.php index 33ddcf1..225cf0b 100644 --- a/tests/Zend/Translate/Adapter/GettextTest.php +++ b/tests/Zend/Translate/Adapter/GettextTest.php @@ -38,7 +38,7 @@ class Zend_Translate_Adapter_GettextTest extends PHPUnit\Framework\TestCase */ public static function main() { - $suite = new PHPUnit\Framework\TestSuite("Zend_Translate_Adapter_GettextTest"); + $suite = new PHPUnit\Framework\TestSuite('Zend_Translate_Adapter_GettextTest'); $result = PHPUnit\TextUI\TestRunner::run($suite); Zend_Translate_Adapter_Gettext::removeCache(); } @@ -57,14 +57,14 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Gettext(dirname(__FILE__) . '/_files/nofile.mo', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Error opening translation file', $e->getMessage()); } try { $adapter = new Zend_Translate_Adapter_Gettext(dirname(__FILE__) . '/_files/failed.mo', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('is not a gettext file', $e->getMessage()); } @@ -107,7 +107,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en2.mo', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -165,7 +165,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -226,7 +226,7 @@ public function testOtherEncoding() $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_otherencoding.mo', 'ru'); // Original message is in KOI8-R.. as unit tests are done in UTF8 we have to convert // the returned KOI8-R string into UTF-8 - $translation = iconv("KOI8-R", "UTF-8", $adapter->translate('Message 2', 'ru')); + $translation = iconv('KOI8-R', 'UTF-8', $adapter->translate('Message 2', 'ru')); $this->assertEquals('Сообщение 2 (ru)', $translation); $this->assertEquals('Message 5', $adapter->translate('Message 5')); $this->assertEquals('Message 5', $adapter->translate('Message 5', 'ru_RU')); @@ -254,7 +254,8 @@ public function testMissingAdapterInfo() public function testPluralToPlural() { $adapter = new Zend_Translate_Adapter_Gettext( - dirname(__FILE__) . '/_files/translation_plural_fr.mo', 'fr' + dirname(__FILE__) . '/_files/translation_plural_fr.mo', + 'fr' ); $this->assertEquals( @@ -277,7 +278,8 @@ public function testPluralToPlural() public function testPluralToSingular() { $adapter = new Zend_Translate_Adapter_Gettext( - dirname(__FILE__) . '/_files/translation_plural_tr.mo', 'tr' + dirname(__FILE__) . '/_files/translation_plural_tr.mo', + 'tr' ); $this->assertEquals( diff --git a/tests/Zend/Translate/Adapter/IniTest.php b/tests/Zend/Translate/Adapter/IniTest.php index 04eb29d..fb03c30 100644 --- a/tests/Zend/Translate/Adapter/IniTest.php +++ b/tests/Zend/Translate/Adapter/IniTest.php @@ -38,7 +38,7 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Ini(dirname(__FILE__) . '/_files/nofile.ini', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('not found', $e->getMessage()); } @@ -89,7 +89,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.ini', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('The given Language', $e->getMessage()); } @@ -147,7 +147,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('The given Language', $e->getMessage()); } diff --git a/tests/Zend/Translate/Adapter/QtTest.php b/tests/Zend/Translate/Adapter/QtTest.php index c1b1e9d..524fc84 100644 --- a/tests/Zend/Translate/Adapter/QtTest.php +++ b/tests/Zend/Translate/Adapter/QtTest.php @@ -38,14 +38,14 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Qt(dirname(__FILE__) . '/_files/nofile.ts', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('is not readable', $e->getMessage()); } try { $adapter = new Zend_Translate_Adapter_Qt(dirname(__FILE__) . '/_files/failed.ts', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Mismatched tag at line', $e->getMessage()); } @@ -58,7 +58,7 @@ public function testErrorOnCreateIncludesFilename() { try { $adapter = new Zend_Translate_Adapter_Qt(dirname(__FILE__) . '/_files/nofile.ts', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('nofile.ts', $e->getMessage()); } @@ -101,7 +101,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.ts', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -159,7 +159,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -198,8 +198,6 @@ public function testOptionLocaleFilename() public function testIsoEncoding() { - - $adapter = new Zend_Translate_Adapter_Qt(dirname(__FILE__) . '/_files/translation_en3.ts', 'fr'); $this->assertEquals('Message 1 (en)', $adapter->translate('Message 1')); $this->assertEquals('Message 1 (en)', $adapter->_('Message 1')); diff --git a/tests/Zend/Translate/Adapter/TbxTest.php b/tests/Zend/Translate/Adapter/TbxTest.php index c77879e..59a60ee 100644 --- a/tests/Zend/Translate/Adapter/TbxTest.php +++ b/tests/Zend/Translate/Adapter/TbxTest.php @@ -38,14 +38,14 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Tbx(dirname(__FILE__) . '/_files/nofile.tbx', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('is not readable', $e->getMessage()); } try { $adapter = new Zend_Translate_Adapter_Tbx(dirname(__FILE__) . '/_files/failed.tbx', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Mismatched tag at line', $e->getMessage()); } @@ -58,7 +58,7 @@ public function testErrorOnCreateIncludesFilename() { try { $adapter = new Zend_Translate_Adapter_Tbx(dirname(__FILE__) . '/_files/nofile.tbx', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('nofile.tbx', $e->getMessage()); } @@ -100,7 +100,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.tbx', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -158,7 +158,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -177,7 +177,7 @@ public function testList() $this->assertEquals(array('en' => 'en', 'de' => 'de', 'fr' => 'fr'), $adapter->getList()); $this->assertTrue($adapter->isAvailable('fr')); $locale = new Zend_Locale('en'); - $this->assertTrue( $adapter->isAvailable($locale)); + $this->assertTrue($adapter->isAvailable($locale)); $this->assertFalse($adapter->isAvailable('sr')); } diff --git a/tests/Zend/Translate/Adapter/TmxTest.php b/tests/Zend/Translate/Adapter/TmxTest.php index 7d3e2be..e44d33f 100644 --- a/tests/Zend/Translate/Adapter/TmxTest.php +++ b/tests/Zend/Translate/Adapter/TmxTest.php @@ -38,14 +38,14 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Tmx(dirname(__FILE__) . '/_files/nofile.tmx', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('is not readable', $e->getMessage()); } try { $adapter = new Zend_Translate_Adapter_Tmx(dirname(__FILE__) . '/_files/failed.tmx', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Mismatched tag at line', $e->getMessage()); } @@ -58,7 +58,7 @@ public function testErrorOnCreateIncludesFilename() { try { $adapter = new Zend_Translate_Adapter_Tmx(dirname(__FILE__) . '/_files/nofile.tmx', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('nofile.tmx', $e->getMessage()); } @@ -101,7 +101,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.tmx', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -159,7 +159,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } diff --git a/tests/Zend/Translate/Adapter/XliffTest.php b/tests/Zend/Translate/Adapter/XliffTest.php index 71a79e3..4fb2743 100644 --- a/tests/Zend/Translate/Adapter/XliffTest.php +++ b/tests/Zend/Translate/Adapter/XliffTest.php @@ -38,14 +38,14 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_Xliff(dirname(__FILE__) . '/_files/nofile.xliff', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('is not readable', $e->getMessage()); } try { $adapter = new Zend_Translate_Adapter_Xliff(dirname(__FILE__) . '/_files/failed.xliff', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Mismatched tag at line', $e->getMessage()); } @@ -58,7 +58,7 @@ public function testErrorOnCreateIncludesFilename() { try { $adapter = new Zend_Translate_Adapter_Xliff(dirname(__FILE__) . '/_files/nofile.xliff', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('nofile.xliff', $e->getMessage()); } @@ -101,7 +101,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.xliff', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -159,7 +159,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -179,7 +179,7 @@ public function testList() $this->assertTrue($adapter->isAvailable('de')); $locale = new Zend_Locale('en'); $this->assertTrue($adapter->isAvailable($locale)); - $this->assertFalse($adapter->isAvailable('sr' )); + $this->assertFalse($adapter->isAvailable('sr')); } public function testOptionLocaleDirectory() diff --git a/tests/Zend/Translate/Adapter/XmlTmTest.php b/tests/Zend/Translate/Adapter/XmlTmTest.php index 42736fe..2a03ecf 100644 --- a/tests/Zend/Translate/Adapter/XmlTmTest.php +++ b/tests/Zend/Translate/Adapter/XmlTmTest.php @@ -38,14 +38,14 @@ public function testCreate() try { $adapter = new Zend_Translate_Adapter_XmlTm(dirname(__FILE__) . '/_files/nofile.xmltm', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('is not readable', $e->getMessage()); } try { $adapter = new Zend_Translate_Adapter_XmlTm(dirname(__FILE__) . '/_files/failed.xmltm', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('Mismatched tag at line', $e->getMessage()); } @@ -58,7 +58,7 @@ public function testErrorOnCreateIncludesFilename() { try { $adapter = new Zend_Translate_Adapter_XmlTm(dirname(__FILE__) . '/_files/nofile.xmltm', 'en'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('nofile.xmltm', $e->getMessage()); } @@ -101,7 +101,7 @@ public function testLoadTranslationData() try { $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.xmltm', 'xx'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } @@ -159,7 +159,7 @@ public function testLocale() try { $adapter->setLocale('nolocale'); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { $this->assertContains('does not exist', $e->getMessage()); } diff --git a/tests/Zend/Translate/Adapter/_files/failed.php b/tests/Zend/Translate/Adapter/_files/failed.php index 0bac53d..5d52e44 100644 --- a/tests/Zend/Translate/Adapter/_files/failed.php +++ b/tests/Zend/Translate/Adapter/_files/failed.php @@ -20,4 +20,4 @@ * @version $Id$ */ -return "noarray"; +return 'noarray'; diff --git a/tests/Zend/Translate/Adapter/_files/testarray/en_GB/LC_OTHER/translation-en_US.php b/tests/Zend/Translate/Adapter/_files/testarray/en_GB/LC_OTHER/translation-en_US.php index db9a038..8e38ba7 100644 --- a/tests/Zend/Translate/Adapter/_files/testarray/en_GB/LC_OTHER/translation-en_US.php +++ b/tests/Zend/Translate/Adapter/_files/testarray/en_GB/LC_OTHER/translation-en_US.php @@ -21,10 +21,10 @@ */ return array( - 'Message 1' => 'Message 1 (en)', - 'Message 2' => 'Message 2 (en)', - 'Message 3' => 'Message 3 (en)', - 'Message 4' => 'Message 4 (en)', + 'Message 1' => 'Message 1 (en)', + 'Message 2' => 'Message 2 (en)', + 'Message 3' => 'Message 3 (en)', + 'Message 4' => 'Message 4 (en)', 'Cooking furniture' => 'Küchen Möbel (en)', - 'Küchen Möbel' => 'Cooking furniture (en)' + 'Küchen Möbel' => 'Cooking furniture (en)' ); diff --git a/tests/Zend/Translate/Adapter/_files/testarray/ja/translation-ja.php b/tests/Zend/Translate/Adapter/_files/testarray/ja/translation-ja.php index 7510157..d5124a8 100644 --- a/tests/Zend/Translate/Adapter/_files/testarray/ja/translation-ja.php +++ b/tests/Zend/Translate/Adapter/_files/testarray/ja/translation-ja.php @@ -21,10 +21,10 @@ */ return array( - 'Message 1' => 'Message 1 (ja)', - 'Message 2' => 'Message 2 (ja)', - 'Message 3' => 'Message 3 (ja)', - 'Message 4' => 'Message 4 (ja)', + 'Message 1' => 'Message 1 (ja)', + 'Message 2' => 'Message 2 (ja)', + 'Message 3' => 'Message 3 (ja)', + 'Message 4' => 'Message 4 (ja)', 'Cooking furniture' => 'Küchen Möbel (ja)', - 'Küchen Möbel' => 'Cooking furniture (ja)' + 'Küchen Möbel' => 'Cooking furniture (ja)' ); diff --git a/tests/Zend/Translate/Adapter/_files/translation_en.php b/tests/Zend/Translate/Adapter/_files/translation_en.php index db9a038..8e38ba7 100644 --- a/tests/Zend/Translate/Adapter/_files/translation_en.php +++ b/tests/Zend/Translate/Adapter/_files/translation_en.php @@ -21,10 +21,10 @@ */ return array( - 'Message 1' => 'Message 1 (en)', - 'Message 2' => 'Message 2 (en)', - 'Message 3' => 'Message 3 (en)', - 'Message 4' => 'Message 4 (en)', + 'Message 1' => 'Message 1 (en)', + 'Message 2' => 'Message 2 (en)', + 'Message 3' => 'Message 3 (en)', + 'Message 4' => 'Message 4 (en)', 'Cooking furniture' => 'Küchen Möbel (en)', - 'Küchen Möbel' => 'Cooking furniture (en)' + 'Küchen Möbel' => 'Cooking furniture (en)' ); diff --git a/tests/Zend/TranslateTest.php b/tests/Zend/TranslateTest.php index 0f83ecd..20e13b1 100644 --- a/tests/Zend/TranslateTest.php +++ b/tests/Zend/TranslateTest.php @@ -56,47 +56,47 @@ public function testLocaleInitialization() public function testDefaultLocale() { - $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'message1')); + $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'message1')); $defaultLocale = new Zend_Locale(); $this->assertEquals($defaultLocale->toString(), $lang->getLocale()); } public function testGetAdapter() { - $lang = new Zend_Translate(Zend_Translate::AN_ARRAY , array('1' => '1'), 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('1' => '1'), 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Array); - $lang = new Zend_Translate(Zend_Translate::AN_GETTEXT , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_GETTEXT, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Gettext); - $lang = new Zend_Translate(Zend_Translate::AN_TMX , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.tmx', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_TMX, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.tmx', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Tmx); - $lang = new Zend_Translate(Zend_Translate::AN_CSV , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.csv', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.csv', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Csv); - $lang = new Zend_Translate(Zend_Translate::AN_XLIFF , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.xliff', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_XLIFF, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.xliff', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Xliff); - $lang = new Zend_Translate('Qt' , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en2.ts', 'en'); + $lang = new Zend_Translate('Qt', dirname(__FILE__) . '/Translate/Adapter/_files/translation_en2.ts', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Qt); - $lang = new Zend_Translate('XmlTm' , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.xmltm', 'en'); + $lang = new Zend_Translate('XmlTm', dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.xmltm', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_XmlTm); - $lang = new Zend_Translate('Tbx' , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.tbx', 'en'); + $lang = new Zend_Translate('Tbx', dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.tbx', 'en'); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Tbx); } public function testSetAdapter() { - $lang = new Zend_Translate(Zend_Translate::AN_GETTEXT , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_GETTEXT, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en'); $lang->setAdapter(Zend_Translate::AN_ARRAY, array('de' => 'de')); $this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Array); try { $lang->xxxFunction(); - $this->fail("exception expected"); + $this->fail('exception expected'); } catch (Zend_Translate_Exception $e) { // success } @@ -110,10 +110,10 @@ public function testAddTranslation() $lang->addTranslation(array('msg2' => 'Message 2'), 'en'); $this->assertEquals('Message 2', $lang->_('msg2')); - $this->assertEquals('msg3', $lang->_('msg3')); + $this->assertEquals('msg3', $lang->_('msg3')); $lang->addTranslation(array('msg3' => 'Message 3'), 'en', array('clear' => true)); - $this->assertEquals('msg2', $lang->_('msg2')); + $this->assertEquals('msg2', $lang->_('msg2')); $this->assertEquals('Message 3', $lang->_('msg3')); } @@ -153,7 +153,7 @@ public function testGetLanguageList() { $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1'), 'en'); $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'ru'); - $this->assertEquals(2, count($lang->getList())); + $this->assertCount(2, $lang->getList()); $this->assertTrue(in_array('en', $lang->getList())); $this->assertTrue(in_array('ru', $lang->getList())); } @@ -162,8 +162,8 @@ public function testIsAvailable() { $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1'), 'en'); $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'ru'); - $this->assertTrue( $lang->isAvailable('en')); - $this->assertTrue( $lang->isAvailable('ru')); + $this->assertTrue($lang->isAvailable('en')); + $this->assertTrue($lang->isAvailable('ru')); $this->assertFalse($lang->isAvailable('fr')); } @@ -171,29 +171,29 @@ public function testTranslate() { $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1 (en)'), 'en'); $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'ru'); - $this->assertEquals('Message 1 (en)', $lang->_('msg1', 'en' )); - $this->assertEquals('Message 1 (ru)', $lang->_('msg1' )); - $this->assertEquals('msg2', $lang->_('msg2', 'en' )); - $this->assertEquals('msg2', $lang->_('msg2' )); + $this->assertEquals('Message 1 (en)', $lang->_('msg1', 'en')); + $this->assertEquals('Message 1 (ru)', $lang->_('msg1')); + $this->assertEquals('msg2', $lang->_('msg2', 'en')); + $this->assertEquals('msg2', $lang->_('msg2')); $this->assertEquals('Message 1 (en)', $lang->translate('msg1', 'en')); - $this->assertEquals('Message 1 (ru)', $lang->translate('msg1' )); - $this->assertEquals('msg2', $lang->translate('msg2', 'en')); - $this->assertEquals('msg2', $lang->translate('msg2' )); + $this->assertEquals('Message 1 (ru)', $lang->translate('msg1')); + $this->assertEquals('msg2', $lang->translate('msg2', 'en')); + $this->assertEquals('msg2', $lang->translate('msg2')); } public function testIsTranslated() { $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1 (en)'), 'en_US'); - $this->assertTrue( $lang->isTranslated('msg1' )); - $this->assertFalse($lang->isTranslated('msg2' )); + $this->assertTrue($lang->isTranslated('msg1')); + $this->assertFalse($lang->isTranslated('msg2')); $this->assertFalse($lang->isTranslated('msg1', false, 'en')); - $this->assertFalse($lang->isTranslated('msg1', true, 'en')); + $this->assertFalse($lang->isTranslated('msg1', true, 'en')); $this->assertFalse($lang->isTranslated('msg1', false, 'ru')); } public function testWithOption() { - $lang = new Zend_Translate(Zend_Translate::AN_CSV , dirname(__FILE__) . '/Translate/Adapter/_files/translation_otherdelimiter.csv', 'en', array('delimiter' => ',')); + $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files/translation_otherdelimiter.csv', 'en', array('delimiter' => ',')); $this->assertEquals('Message 1 (en)', $lang->translate('Message 1')); $this->assertEquals('Message 4 (en)', $lang->translate('Message 4,')); $this->assertEquals('Message 5, (en)', $lang->translate('Message 5')); @@ -215,17 +215,19 @@ public function testFileSearch() public function testTestingCacheHandling() { - - $cache = Zend_Cache::factory('Core', 'File', - array('lifetime' => 120, 'automatic_serialization' => true), - array('cache_dir' => dirname(__FILE__) . '/_files/')); + $cache = Zend_Cache::factory( + 'Core', + 'File', + array('lifetime' => 120, 'automatic_serialization' => true), + array('cache_dir' => dirname(__FILE__) . '/_files/') + ); Zend_Translate::setCache($cache); $cache = Zend_Translate::getCache(); $this->assertTrue($cache instanceof Zend_Cache_Core); $this->assertTrue(Zend_Translate::hasCache()); - $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1 (en)'), 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1 (en)'), 'en'); $adapter = $lang->getAdapter(); $this->assertTrue($adapter instanceof Zend_Translate_Adapter_Array); $adaptercache = $adapter->getCache(); @@ -249,7 +251,6 @@ public function testExceptionWhenNoAdapterClassWasSet() public function testZF3679() { - $locale = new Zend_Locale('de_AT'); Zend_Registry::set('Zend_Locale', $locale); @@ -308,7 +309,7 @@ public function testLogUntranslatedMessage() public function testSettingUnknownLocaleWithTriggeredError() { - $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files', 'en', array('delimiter' => ',')); + $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files', 'en', array('delimiter' => ',')); $this->_errorOccured = false; set_error_handler(array($this, 'errorHandlerIgnore')); $lang->setLocale('ru'); @@ -365,9 +366,12 @@ public function testSettingUnknownLocaleWritingToSelfDefinedLog() */ public function testGetOptionsFromCache() { - $cache = Zend_Cache::factory('Core', 'File', - array('lifetime' => 120, 'automatic_serialization' => true), - array('cache_dir' => dirname(__FILE__) . '/_files/')); + $cache = Zend_Cache::factory( + 'Core', + 'File', + array('lifetime' => 120, 'automatic_serialization' => true), + array('cache_dir' => dirname(__FILE__) . '/_files/') + ); Zend_Translate::setCache($cache); $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files', 'en', array('delimiter' => ',')); @@ -443,12 +447,14 @@ public function testGettingAllMessages() $this->assertEquals(array('msg1' => 'Message 1 (ru)'), $lang->getMessages()); $this->assertEquals( array('msg1' => 'Message 1', 'msg2' => 'Message 2'), - $lang->getMessages('en')); + $lang->getMessages('en') + ); $this->assertEquals( array( 'en' => array('msg1' => 'Message 1', 'msg2' => 'Message 2'), 'ru' => array('msg1' => 'Message 1 (ru)')), - $lang->getMessages('all')); + $lang->getMessages('all') + ); } /** @@ -463,7 +469,8 @@ public function testGettingPlurals() 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), - 'plural' => ''), 'en' + 'plural' => ''), + 'en' ); $this->assertEquals('plural_0 (en)', $lang->translate(array('singular', 'plural', 1))); @@ -485,7 +492,8 @@ public function testGettingPluralsFromLoweredLocale() 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), - 'plural' => ''), 'en' + 'plural' => ''), + 'en' ); $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'en_US'); $lang->setLocale('en_US'); @@ -506,7 +514,8 @@ public function testGettingPluralsFromUnknownLocale() 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), - 'plural' => ''), 'en' + 'plural' => ''), + 'en' ); $this->assertEquals('singular', $lang->translate(array('singular', 'plural', 1), 'ru')); @@ -517,7 +526,7 @@ public function testGettingPluralsFromUnknownLocale() public function testPluralsWithGettext() { - $lang = new Zend_Translate(Zend_Translate::AN_GETTEXT , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_GETTEXT, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en'); $this->assertEquals('Message 5 (en) Plural 0', $lang->translate(array('Message 5', 'Message 5 Plural', 1))); $this->assertEquals('Message 5 (en) Plural 0', $lang->plural('Message 5', 'Message 5 Plural', 1)); @@ -527,7 +536,7 @@ public function testPluralsWithGettext() public function testPluralsWithCsv() { - $lang = new Zend_Translate(Zend_Translate::AN_CSV , dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.csv', 'en'); + $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.csv', 'en'); $this->assertEquals('Message 6 (en) Plural 0', $lang->translate(array('Message 6', 'Message 6 Plural1', 1))); $this->assertEquals('Message 6 (en) Plural 0', $lang->plural('Message 6', 'Message 6 Plural1', 1)); @@ -585,8 +594,8 @@ public function testDontLogUntranslatedMessageWithIsTranslated() public function testMultiFolderScan() { $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, dirname(__FILE__) . '/Translate/Adapter/_files/testarray', 'en_GB', array('scan' => Zend_Translate::LOCALE_DIRECTORY)); - $this->assertEquals('Message 1 (ja)', $lang->_('Message 1', 'ja' )); - $this->assertEquals('Message 1 (en)', $lang->_('Message 1' )); + $this->assertEquals('Message 1 (ja)', $lang->_('Message 1', 'ja')); + $this->assertEquals('Message 1 (en)', $lang->_('Message 1')); } /** @@ -632,7 +641,8 @@ public function testGettingPluralsUsingOwnRule() 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), - 'plural' => ''), 'en' + 'plural' => ''), + 'en' ); $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'en_US'); $lang->setLocale('en_US'); @@ -656,7 +666,8 @@ public function testAddingAdapterToSourceUsingOwnRule() 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), - 'plural' => ''), 'en' + 'plural' => ''), + 'en' ); $this->assertFalse($translate->isTranslated('Message 1')); @@ -684,8 +695,8 @@ public function testIgnoreMultipleDirectories() dirname(__FILE__) . '/Translate/Adapter/_files/testarray/', 'auto', array( - 'scan' => Zend_Translate::LOCALE_FILENAME, - 'ignore' => array('.', 'ignoreme', 'LC_TEST'), + 'scan' => Zend_Translate::LOCALE_FILENAME, + 'ignore' => array('.', 'ignoreme', 'LC_TEST'), 'disableNotices' => true, ) ); @@ -700,8 +711,8 @@ public function testIgnoreMultipleDirectories() dirname(__FILE__) . '/Translate/Adapter/_files/testarray/', 'auto', array( - 'scan' => Zend_Translate::LOCALE_FILENAME, - 'ignore' => array('.', 'regex_1' => '/de_DE/', 'regex' => '/translation-ja/'), + 'scan' => Zend_Translate::LOCALE_FILENAME, + 'ignore' => array('.', 'regex_1' => '/de_DE/', 'regex' => '/translation-ja/'), 'disableNotices' => true, ) ); @@ -752,12 +763,12 @@ public function testCircleReroutingForTranslations() { $translate = new Zend_Translate( array( - 'adapter' => Zend_Translate::AN_ARRAY, - 'content' => dirname(__FILE__) . '/Translate/Adapter/_files/testarray/', - 'locale' => 'auto', - 'scan' => Zend_Translate::LOCALE_FILENAME, - 'ignore' => array('.', 'ignoreme', 'LC_TEST'), - 'route' => array('ja' => 'en_US', 'en_US' => 'ja'), + 'adapter' => Zend_Translate::AN_ARRAY, + 'content' => dirname(__FILE__) . '/Translate/Adapter/_files/testarray/', + 'locale' => 'auto', + 'scan' => Zend_Translate::LOCALE_FILENAME, + 'ignore' => array('.', 'ignoreme', 'LC_TEST'), + 'route' => array('ja' => 'en_US', 'en_US' => 'ja'), 'disableNotices' => true, ) ); @@ -787,12 +798,12 @@ public function testDoubleReroutingForTranslations() { $translate = new Zend_Translate( array( - 'adapter' => Zend_Translate::AN_ARRAY, - 'content' => dirname(__FILE__) . '/Translate/Adapter/_files/testarray/', - 'locale' => 'auto', - 'scan' => Zend_Translate::LOCALE_FILENAME, - 'ignore' => array('.', 'ignoreme', 'LC_TEST'), - 'route' => array('ja' => 'en_US', 'en_US' => 'ja'), + 'adapter' => Zend_Translate::AN_ARRAY, + 'content' => dirname(__FILE__) . '/Translate/Adapter/_files/testarray/', + 'locale' => 'auto', + 'scan' => Zend_Translate::LOCALE_FILENAME, + 'ignore' => array('.', 'ignoreme', 'LC_TEST'), + 'route' => array('ja' => 'en_US', 'en_US' => 'ja'), 'disableNotices' => true, ) ); @@ -820,9 +831,12 @@ public function testDoubleReroutingForTranslations() */ public function testSetCacheThroughOptions() { - $cache = Zend_Cache::factory('Core', 'File', - array('lifetime' => 120, 'automatic_serialization' => true), - array('cache_dir' => dirname(__FILE__) . '/_files/')); + $cache = Zend_Cache::factory( + 'Core', + 'File', + array('lifetime' => 120, 'automatic_serialization' => true), + array('cache_dir' => dirname(__FILE__) . '/_files/') + ); $translate = new Zend_Translate(array( 'adapter' => Zend_Translate::AN_ARRAY, @@ -845,7 +859,8 @@ public function testSettingLogPriorityForLog() $writer = new Zend_Log_Writer_Stream($stream); $log = new Zend_Log($writer); - $lang = new Zend_Translate(array( + $lang = new Zend_Translate( + array( 'adapter' => Zend_Translate::AN_CSV, 'content' => dirname(__FILE__) . '/Translate/Adapter/_files', 'locale' => 'en', @@ -887,7 +902,8 @@ public function errorHandlerIgnore($errno, $errstr, $errfile, $errline, array $e * @param integer $number * @return integer */ - public function customPlural($number) { + public function customPlural($number) + { return 1; } }