From 3e458706d4c1115ebb85c282af4c4f39cc7fdef3 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Sat, 30 Jun 2012 00:32:39 +0400 Subject: [PATCH 1/9] [I18n] Translator processor --- src/Factory.php | 86 +++++++++++-------- src/Processor/Filter.php | 2 +- src/Processor/Queue.php | 2 +- src/Processor/Token.php | 2 +- src/Processor/Translator.php | 4 +- src/ReaderPluginManager.php | 66 ++++++++++++++ test/ProcessorTest.php | 37 ++++---- .../{messages.php => translations-de_DE.php} | 0 8 files changed, 138 insertions(+), 61 deletions(-) create mode 100644 src/ReaderPluginManager.php rename test/_files/{messages.php => translations-de_DE.php} (100%) diff --git a/src/Factory.php b/src/Factory.php index cf6a292..19714c8 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -19,24 +19,25 @@ class Factory { /** - * Readers used for config files. - * array key is extension, array value is reader instance or class name + * Plugin manager for loading readers * - * @var array + * @var null|ReaderPluginManager */ - protected static $readers = array( - 'ini' => 'Zend\Config\Reader\Ini', - 'json' => 'Zend\Config\Reader\Json', - 'xml' => 'Zend\Config\Reader\Xml', - 'yaml' => 'Zend\Config\Reader\Yaml', - ); + public static $readers = null; /** - * The reader manager + * Registered config file extensions. + * key is extension, value is reader instance or plugin name * - * @var null|ReaderPluginManager + * @var array */ - protected static $plugins = null; + protected static $extensions = array( + 'ini' => 'ini', + 'json' => 'json', + 'xml' => 'xml', + 'yaml' => 'yaml', + ); + /** * Read a config from a file. @@ -44,6 +45,7 @@ class Factory * @param string $filename * @param boolean $returnConfigObject * @return array|Config + * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public static function fromFile($filename, $returnConfigObject = false) @@ -68,25 +70,11 @@ public static function fromFile($filename, $returnConfigObject = false) } $config = include $filename; - } elseif (isset(self::$readers[$extension])) { - $reader = self::$readers[$extension]; - if (is_string($reader)) { - if (!class_exists($reader)) { - throw new Exception\RuntimeException(sprintf( - 'Unable to locate reader class "%s"; class does not exist', - $reader - )); - } - - $reader = new $reader(); - } - + } elseif (isset(self::$extensions[$extension])) { + $reader = self::$extensions[$extension]; if (!$reader instanceof Reader\ReaderInterface) { - throw new Exception\RuntimeException(sprintf( - 'Reader should be an instance of %s\Reader\ReaderInterface; received "%s"', - __NAMESPACE__, - (is_object($reader) ? get_class($reader) : gettype($reader)) - )); + $reader = self::getReaderPluginManager()->get($reader); + self::$extensions[$extension] = $reader; } /** @var Reader\ReaderInterface $reader */ @@ -119,11 +107,34 @@ public static function fromFiles(array $files, $returnConfigObject = false) return ($returnConfigObject) ? new Config($config) : $config; } + /** + * Set reader plugin manager + * + * @param ReaderPluginManager $readers + */ + public static function setReaderPluginManager(ReaderPluginManager $readers) + { + self::$readers = $readers; + } + + /** + * Get the reader plugin manager + * + * @return ReaderPluginManager + */ + public static function getReaderPluginManager() + { + if (static::$readers === null) { + static::$readers = new ReaderPluginManager(); + } + return static::$readers; + } + /** * Set config reader for file extension * - * @param string $extension - * @param string|Reader\ReaderInterface $reader + * @param string $extension + * @param string|Reader\ReaderInterface $reader * @throws Exception\InvalidArgumentException */ public static function registerReader($extension, $reader) @@ -131,11 +142,14 @@ public static function registerReader($extension, $reader) $extension = strtolower($extension); if (!is_string($reader) && !$reader instanceof Reader\ReaderInterface) { - throw new Exception\InvalidArgumentException( - 'Reader should be class name or instance of Zend\Config\Reader\ReaderInterface' - ); + throw new Exception\InvalidArgumentException(sprintf( + 'Reader should be plugin name, class name or ' . + 'instance of %s\Reader\ReaderInterface; recieved "%s"', + __NAMESPACE__, + (is_object($reader) ? get_class($reader) : gettype($reader)) + )); } - self::$readers[$extension] = $reader; + self::$extensions[$extension] = $reader; } } diff --git a/src/Processor/Filter.php b/src/Processor/Filter.php index 3dbe6f5..9dc2b89 100644 --- a/src/Processor/Filter.php +++ b/src/Processor/Filter.php @@ -66,7 +66,7 @@ public function getFilter() public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } /** diff --git a/src/Processor/Queue.php b/src/Processor/Queue.php index 6f894c0..e369149 100644 --- a/src/Processor/Queue.php +++ b/src/Processor/Queue.php @@ -31,7 +31,7 @@ class Queue extends PriorityQueue implements ProcessorInterface public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } foreach ($this as $parser) { diff --git a/src/Processor/Token.php b/src/Processor/Token.php index 2e4f0a5..0a64174 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -206,7 +206,7 @@ protected function buildMap() public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } if ($this->map === null) { diff --git a/src/Processor/Translator.php b/src/Processor/Translator.php index 1768c1d..e260537 100644 --- a/src/Processor/Translator.php +++ b/src/Processor/Translator.php @@ -118,7 +118,7 @@ public function getTextDomain() public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } /** @@ -128,7 +128,7 @@ public function process(Config $config) if ($val instanceof Config) { $this->process($val); } else { - $config->$key = $this->translator->translate($val, $this->textDomain, $this->locale); + $config->{$key} = $this->translator->translate($val, $this->textDomain, $this->locale); } } diff --git a/src/ReaderPluginManager.php b/src/ReaderPluginManager.php new file mode 100644 index 0000000..008bd0d --- /dev/null +++ b/src/ReaderPluginManager.php @@ -0,0 +1,66 @@ + 'Zend\Config\Reader\Ini', + 'json' => 'Zend\Config\Reader\Json', + 'xml' => 'Zend\Config\Reader\Xml', + 'yaml' => 'Zend\Config\Reader\Yaml', + ); + + /** + * Validate the plugin + * Checks that the reader loaded is an instance of Reader\ReaderInterface. + * + * @param Reader\ReaderInterface $plugin + * @return void + * @throws Exception\InvalidArgumentException if invalid + */ + public function validatePlugin($plugin) + { + if ($plugin instanceof Reader\ReaderInterface) { + // we're okay + return; + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Plugin of type %s is invalid; must implement %s\Reader\ReaderInterface', + (is_object($plugin) ? get_class($plugin) : gettype($plugin)), + __NAMESPACE__ + )); + } +} diff --git a/test/ProcessorTest.php b/test/ProcessorTest.php index 9aff44d..196ed07 100644 --- a/test/ProcessorTest.php +++ b/test/ProcessorTest.php @@ -45,7 +45,7 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase { protected $nested; protected $tokenBare, $tokenPrefix, $tokenSuffix, $tokenSurround, $tokenSurroundMixed; - protected $translatorData, $translatorStrings; + protected $translatorData, $translatorFile; protected $userConstants, $phpConstants; protected $filter; @@ -131,10 +131,7 @@ public function setUp() ) ); - $this->translatorStrings = array( - 'one dog' => 'ein Hund', - 'two dogs' => 'zwei Hunde' - ); + $this->translatorFile = realpath(__DIR__ . '/_files/translations-de_DE.php'); $this->filter = array( 'simple' => 'some MixedCase VALue', @@ -214,7 +211,7 @@ public function testTokenReadOnly() $processor->addToken('BARETOKEN', 'some replaced value'); $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $processor->process($config); } @@ -351,37 +348,37 @@ public function testTranslator() { $config = new Config($this->translatorData, true); $translator = new Translator(); - $translator->addTranslationFile('phpArray', realpath(__DIR__ . '/_files/messages.php')); - $processor = new TranslatorProcessor($translator, 'default', 'de_DE'); + $translator->addTranslationFile('phparray', $this->translatorFile); + $processor = new TranslatorProcessor($translator); $processor->process($config); $this->assertEquals('oneDog', $config->pages[0]->id); $this->assertEquals('ein Hund', $config->pages[0]->label); - $this->assertEquals('twoDogs', $config->pages[1]->id); $this->assertEquals('zwei Hunde', $config->pages[1]->label); } - /* public function testTranslatorReadOnly() { - $config = new Config($this->translator, false); + $config = new Config($this->translatorData, false); $translator = new Translator(); - $processor = new TranslatorProcessor($translator, 'default', 'de_DE'); + $processor = new TranslatorProcessor($translator); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $processor->process($config); } public function testTranslatorSingleValue() { - $translator = new Translator(Translator::AN_ARRAY, $this->translatorStrings, 'de_DE'); - $processor = new TranslatorProcessor($translator); - $word = 'one dog'; - $this->assertEquals('ein Hund', $processor->processValue($word)); + $translator = new Translator(); + $translator->addTranslationFile('phparray', $this->translatorFile); + $processor = new TranslatorProcessor($translator); + + $this->assertEquals('ein Hund', $processor->processValue('one dog')); } - */ + public function testFilter() { $config = new Config($this->filter, true); @@ -402,7 +399,7 @@ public function testFilterReadOnly() $processor = new FilterProcessor($filter); $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $processor->process($config); } @@ -451,7 +448,7 @@ public function testQueueReadOnly() $queue->insert($lowerProcessor); $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $queue->process($config); } diff --git a/test/_files/messages.php b/test/_files/translations-de_DE.php similarity index 100% rename from test/_files/messages.php rename to test/_files/translations-de_DE.php From ccbdbdc2e0a4b1af96ca3c91602018f63df8dc0e Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Sat, 30 Jun 2012 01:25:10 +0400 Subject: [PATCH 2/9] fixed missing file exceptions --- src/Config.php | 15 ++++++++++----- src/Exception/InvalidArgumentException.php | 3 ++- src/Factory.php | 2 +- src/Reader/Ini.php | 2 +- src/Reader/Json.php | 2 +- src/Reader/Xml.php | 2 +- src/Reader/Yaml.php | 6 ++++-- test/FactoryTest.php | 20 ++++++++++++++++---- test/Reader/AbstractReaderTestCase.php | 3 ++- 9 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/Config.php b/src/Config.php index c6d6bfd..70fa03a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -16,6 +16,13 @@ use Zend\Stdlib\ArrayUtils; /** + * Provides a property based interface to an array. + * The data are read-only unless $allowModifications is set to true + * on construction. + * + * Implements Countable, Iterator and ArrayAccess + * to facilitate easy access to the data. + * * @category Zend * @package Zend_Config */ @@ -51,12 +58,10 @@ class Config implements Countable, Iterator, ArrayAccess protected $skipNextIteration; /** - * Zend\Config provides a property based interface to - * an array. The data are read-only unless $allowModifications - * is set to true on construction. + * Constructor. * - * Zend\Config also implements Countable, Iterator and ArrayAccess to - * facilitate easy access to the data. + * Data is read-only unless $allowModifications is set to true + * on construction. * * @param array $array * @param boolean $allowModifications diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 9738cb0..55773a6 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -15,5 +15,6 @@ * @package Zend_Config * @subpackage Exception */ -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +class InvalidArgumentException extends \InvalidArgumentException implements + ExceptionInterface {} diff --git a/src/Factory.php b/src/Factory.php index 19714c8..e18b2d1 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -53,7 +53,7 @@ public static function fromFile($filename, $returnConfigObject = false) $pathinfo = pathinfo($filename); if (!isset($pathinfo['extension'])) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( 'Filename "%s" is missing an extension and cannot be auto-detected', $filename )); diff --git a/src/Reader/Ini.php b/src/Reader/Ini.php index 209e36f..b02df3b 100644 --- a/src/Reader/Ini.php +++ b/src/Reader/Ini.php @@ -68,7 +68,7 @@ public function getNestSeparator() public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/src/Reader/Json.php b/src/Reader/Json.php index 2f5b59a..01a5f9e 100644 --- a/src/Reader/Json.php +++ b/src/Reader/Json.php @@ -41,7 +41,7 @@ class Json implements ReaderInterface public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/src/Reader/Xml.php b/src/Reader/Xml.php index 5fa2147..ed6ebe8 100644 --- a/src/Reader/Xml.php +++ b/src/Reader/Xml.php @@ -59,7 +59,7 @@ class Xml implements ReaderInterface public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/src/Reader/Yaml.php b/src/Reader/Yaml.php index 7b70ee6..5c638cc 100644 --- a/src/Reader/Yaml.php +++ b/src/Reader/Yaml.php @@ -61,7 +61,9 @@ public function __construct($yamlDecoder = null) public function setYamlDecoder($yamlDecoder) { if (!is_callable($yamlDecoder)) { - throw new Exception\InvalidArgumentException('Invalid parameter to setYamlDecoder() - must be callable'); + throw new Exception\RuntimeException( + 'Invalid parameter to setYamlDecoder() - must be callable' + ); } $this->yamlDecoder = $yamlDecoder; return $this; @@ -88,7 +90,7 @@ public function getYamlDecoder() public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/test/FactoryTest.php b/test/FactoryTest.php index fd0c3b8..29f91f9 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -122,13 +122,13 @@ public function testNonExistentFileThrowsRuntimeException() $config = Factory::fromFile('foo.bar'); } - public function testInvalidFileExtensionThrowsInvalidArgumentException() + public function testUnsupportedFileExtensionThrowsRuntimeException() { $this->setExpectedException('RuntimeException'); $config = Factory::fromFile(__DIR__ . '/TestAssets/bad.ext'); } - public function testFactoryCanRegisterCustomReaders() + public function testFactoryCanRegisterCustomReaderInstance() { Factory::registerReader('dum', new Reader\TestAssets\DummyReader()); @@ -136,9 +136,21 @@ public function testFactoryCanRegisterCustomReaders() $this->assertInstanceOf('Zend\Config\Config', $configObject); $this->assertEquals($configObject['one'], 1); - $this->assertEquals($configObject['two'], 2); - $this->assertEquals($configObject['three'], 3); } + public function testFactoryCanRegisterCustomReaderPlugn() + { + $dummyReader = new Reader\TestAssets\DummyReader(); + Factory::getReaderPluginManager()->setService('DummyReader',$dummyReader); + + Factory::registerReader('dum', 'DummyReader'); + + $configObject = Factory::fromFile(__DIR__ . '/TestAssets/dummy.dum', true); + $this->assertInstanceOf('Zend\Config\Config', $configObject); + + $this->assertEquals($configObject['one'], 1); + } + + } diff --git a/test/Reader/AbstractReaderTestCase.php b/test/Reader/AbstractReaderTestCase.php index 190aa3a..3b8b4b0 100644 --- a/test/Reader/AbstractReaderTestCase.php +++ b/test/Reader/AbstractReaderTestCase.php @@ -43,6 +43,7 @@ abstract class AbstractReaderTestCase extends TestCase /** * Get test asset name for current test case. * + * @param string $name * @return string */ abstract protected function getTestAssetPath($name); @@ -50,7 +51,7 @@ abstract protected function getTestAssetPath($name); public function testMissingFile() { $filename = $this->getTestAssetPath('no-file'); - $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', "doesn't exist or not readable"); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', "doesn't exist or not readable"); $config = $this->reader->fromFile($filename); } From d33369558f2036eec8f77dca074b6380be7233e8 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Mon, 2 Jul 2012 02:38:20 +0400 Subject: [PATCH 3/9] fix use statements --- src/Processor/Constant.php | 5 ----- src/Processor/Filter.php | 2 -- src/Processor/Token.php | 1 - src/Processor/Translator.php | 4 ++-- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Processor/Constant.php b/src/Processor/Constant.php index 4fc1604..9fbae8d 100644 --- a/src/Processor/Constant.php +++ b/src/Processor/Constant.php @@ -10,11 +10,6 @@ namespace Zend\Config\Processor; -use Zend\Config\Config; -use Zend\Config\Exception\InvalidArgumentException; -use Traversable; -use ArrayObject; - /** * @category Zend * @package Zend_Config diff --git a/src/Processor/Filter.php b/src/Processor/Filter.php index 9dc2b89..e8154da 100644 --- a/src/Processor/Filter.php +++ b/src/Processor/Filter.php @@ -13,8 +13,6 @@ use Zend\Config\Config; use Zend\Config\Exception; use Zend\Filter\FilterInterface as ZendFilter; -use Traversable; -use ArrayObject; /** * @category Zend diff --git a/src/Processor/Token.php b/src/Processor/Token.php index 0a64174..1b653ae 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -13,7 +13,6 @@ use Zend\Config\Config; use Zend\Config\Exception; use Traversable; -use ArrayObject; /** * @category Zend diff --git a/src/Processor/Translator.php b/src/Processor/Translator.php index e260537..8794a73 100644 --- a/src/Processor/Translator.php +++ b/src/Processor/Translator.php @@ -30,7 +30,7 @@ class Translator implements ProcessorInterface protected $translator; /** - * @var Locale|string|null + * @var string|null */ protected $locale = null; @@ -45,7 +45,7 @@ class Translator implements ProcessorInterface * * @param ZendTranslator $translator * @param string $textDomain - * @param Locale|string|null $locale + * @param string|null $locale */ public function __construct(ZendTranslator $translator, $textDomain = 'default', $locale = null) { From 6c552f596ba7077ca9e78cb88a4b3876fc65e868 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Mon, 2 Jul 2012 02:58:53 +0400 Subject: [PATCH 4/9] CS updates --- src/Exception/InvalidArgumentException.php | 3 +- src/Processor/Token.php | 8 +-- src/Processor/Translator.php | 5 +- src/Writer/AbstractWriter.php | 9 ---- test/ConfigTest.php | 2 +- test/Reader/AbstractReaderTestCase.php | 6 +-- test/Reader/IniTest.php | 2 +- test/Reader/JsonTest.php | 2 +- test/Reader/XmlTest.php | 2 +- test/Reader/YamlTest.php | 2 +- test/Writer/AbstractWriterTestCase.php | 8 +-- test/Writer/IniTest.php | 12 ++--- test/Writer/JsonTest.php | 11 ++-- test/Writer/PhpArrayTest.php | 6 +-- test/Writer/TestAssets/PhpReader.php | 11 ++++ test/Writer/XmlTest.php | 8 +-- test/Writer/YamlTest.php | 9 ++-- test/Writer/{files => _files}/allsections.ini | 52 +++++++++---------- .../Writer/{files => _files}/allsections.json | 0 test/Writer/{files => _files}/allsections.xml | 0 .../Writer/{files => _files}/allsections.yaml | 0 test/Writer/files/PhpReader.php | 9 ---- 22 files changed, 74 insertions(+), 93 deletions(-) create mode 100644 test/Writer/TestAssets/PhpReader.php rename test/Writer/{files => _files}/allsections.ini (93%) rename test/Writer/{files => _files}/allsections.json (100%) rename test/Writer/{files => _files}/allsections.xml (100%) rename test/Writer/{files => _files}/allsections.yaml (100%) delete mode 100644 test/Writer/files/PhpReader.php diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 55773a6..9738cb0 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -15,6 +15,5 @@ * @package Zend_Config * @subpackage Exception */ -class InvalidArgumentException extends \InvalidArgumentException implements - ExceptionInterface +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface {} diff --git a/src/Processor/Token.php b/src/Processor/Token.php index 1b653ae..cf725ba 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -53,8 +53,8 @@ class Token implements ProcessorInterface * Token Processor walks through a Config structure and replaces all * occurences of tokens with supplied values. * - * @param array|Config|ArrayObject|Traversable $tokens Associative array of TOKEN => value - * to replace it with + * @param array|Config|Traversable $tokens Associative array of TOKEN => value + * to replace it with * @param string $prefix * @param string $suffix * @internal param array $options @@ -111,8 +111,8 @@ public function getSuffix() /** * Set token registry. * - * @param array|Config|Traversable $tokens Associative array of TOKEN => value - * to replace it with + * @param array|Config|Traversable $tokens Associative array of TOKEN => value + * to replace it with * @return Token * @throws Exception\InvalidArgumentException */ diff --git a/src/Processor/Translator.php b/src/Processor/Translator.php index 8794a73..bb2c623 100644 --- a/src/Processor/Translator.php +++ b/src/Processor/Translator.php @@ -13,9 +13,6 @@ use Zend\Config\Config; use Zend\Config\Exception; use Zend\I18n\Translator\Translator as ZendTranslator; -use Locale; -use Traversable; -use ArrayObject; /** * @category Zend @@ -83,7 +80,7 @@ public function setLocale($locale) } /** - * @return Locale|string|null + * @return string|null */ public function getLocale() { diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php index 4d993ef..1d6df80 100644 --- a/src/Writer/AbstractWriter.php +++ b/src/Writer/AbstractWriter.php @@ -30,13 +30,8 @@ abstract class AbstractWriter implements WriterInterface * @param mixed $config * @param boolean $exclusiveLock * @return void -<<<<<<< HEAD * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException -======= - * @throws Exception\RuntimeException - * @throws Exception\InvalidArgumentException ->>>>>>> initial commit, remove Broker */ public function toFile($filename, $config, $exclusiveLock = true) { @@ -66,11 +61,7 @@ function($error, $message = '', $file = '', $line = 0) use ($filename) { * * @see WriterInterface::toString() * @param mixed $config -<<<<<<< HEAD - * @return void -======= * @return string ->>>>>>> initial commit, remove Broker * @throws Exception\InvalidArgumentException */ public function toString($config) diff --git a/test/ConfigTest.php b/test/ConfigTest.php index c67efc2..b1fe550 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config; -use \Zend\Config\Config; +use Zend\Config\Config; /** * @category Zend diff --git a/test/Reader/AbstractReaderTestCase.php b/test/Reader/AbstractReaderTestCase.php index 3b8b4b0..55644b8 100644 --- a/test/Reader/AbstractReaderTestCase.php +++ b/test/Reader/AbstractReaderTestCase.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Reader; -use \PHPUnit_Framework_TestCase as TestCase, - \Zend\Config\Reader\ReaderInterface, - \ReflectionClass; +use PHPUnit_Framework_TestCase as TestCase; +use Zend\Config\Reader\ReaderInterface; +use ReflectionClass; /** * @category Zend diff --git a/test/Reader/IniTest.php b/test/Reader/IniTest.php index 82b101e..f0d5edb 100644 --- a/test/Reader/IniTest.php +++ b/test/Reader/IniTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Ini; +use Zend\Config\Reader\Ini; /** * @category Zend diff --git a/test/Reader/JsonTest.php b/test/Reader/JsonTest.php index b52bb2d..522cdb7 100644 --- a/test/Reader/JsonTest.php +++ b/test/Reader/JsonTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Json; +use Zend\Config\Reader\Json; /** * @category Zend diff --git a/test/Reader/XmlTest.php b/test/Reader/XmlTest.php index eb25359..556ba6f 100644 --- a/test/Reader/XmlTest.php +++ b/test/Reader/XmlTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Xml; +use Zend\Config\Reader\Xml; /** * @category Zend diff --git a/test/Reader/YamlTest.php b/test/Reader/YamlTest.php index 33bd200..0e08d0b 100644 --- a/test/Reader/YamlTest.php +++ b/test/Reader/YamlTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Yaml as YamlReader; +use Zend\Config\Reader\Yaml as YamlReader; /** * @category Zend diff --git a/test/Writer/AbstractWriterTestCase.php b/test/Writer/AbstractWriterTestCase.php index 3c1e91c..2039b9c 100644 --- a/test/Writer/AbstractWriterTestCase.php +++ b/test/Writer/AbstractWriterTestCase.php @@ -21,8 +21,8 @@ namespace ZendTest\Config\Writer; -use \PHPUnit_Framework_TestCase as TestCase, - \Zend\Config\Config; +use PHPUnit_Framework_TestCase as TestCase; +use Zend\Config\Config; /** * @category Zend @@ -35,13 +35,13 @@ abstract class AbstractWriterTestCase extends TestCase { /** - * @var ReaderInterface + * @var \Zend\Config\Reader\ReaderInterface */ protected $reader; /** * - * @var WriterInterface + * @var \Zend\Config\Writer\WriterInterface */ protected $writer; diff --git a/test/Writer/IniTest.php b/test/Writer/IniTest.php index e9c1b25..94a0401 100644 --- a/test/Writer/IniTest.php +++ b/test/Writer/IniTest.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Writer; -use \Zend\Config\Writer\Ini as IniWriter; -use \Zend\Config\Config; -use \Zend\Config\Reader\Ini as IniReader; +use Zend\Config\Writer\Ini as IniWriter; +use Zend\Config\Config; +use Zend\Config\Reader\Ini as IniReader; /** * @category Zend @@ -35,15 +35,12 @@ */ class IniTest extends AbstractWriterTestCase { - public function setUp() { $this->reader = new IniReader(); $this->writer = new IniWriter(); } - - public function testNoSection() { $config = new Config(array('test' => 'foo', 'test2' => array('test3' => 'bar'))); @@ -58,13 +55,12 @@ public function testNoSection() public function testWriteAndReadOriginalFile() { - $config = $this->reader->fromFile(__DIR__ . '/files/allsections.ini'); + $config = $this->reader->fromFile(__DIR__ . '/_files/allsections.ini'); $this->writer->toFile($this->getTestAssetFileName(), $config); $config = $this->reader->fromFile($this->getTestAssetFileName()); $this->assertEquals('multi', $config['all']['one']['two']['three']); - } } diff --git a/test/Writer/JsonTest.php b/test/Writer/JsonTest.php index 51a57a7..44656bc 100644 --- a/test/Writer/JsonTest.php +++ b/test/Writer/JsonTest.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Writer; -use \Zend\Config\Writer\Json as JsonWriter; -use \Zend\Config\Config; -use \Zend\Config\Reader\Json as JsonReader; +use Zend\Config\Writer\Json as JsonWriter; +use Zend\Config\Config; +use Zend\Config\Reader\Json as JsonReader; /** * @category Zend @@ -35,15 +35,12 @@ */ class JsonTest extends AbstractWriterTestCase { - public function setUp() { $this->reader = new JsonReader(); $this->writer = new JsonWriter(); } - - public function testNoSection() { $config = new Config(array('test' => 'foo', 'test2' => array('test3' => 'bar'))); @@ -58,7 +55,7 @@ public function testNoSection() public function testWriteAndReadOriginalFile() { - $config = $this->reader->fromFile(__DIR__ . '/files/allsections.json'); + $config = $this->reader->fromFile(__DIR__ . '/_files/allsections.json'); $this->writer->toFile($this->getTestAssetFileName(), $config); diff --git a/test/Writer/PhpArrayTest.php b/test/Writer/PhpArrayTest.php index 5077a5e..8caf8e3 100644 --- a/test/Writer/PhpArrayTest.php +++ b/test/Writer/PhpArrayTest.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Writer; -use \Zend\Config\Writer\PhpArray; -use \Zend\Config\Config; -use ZendTest\Config\Writer\files\PhpReader; +use Zend\Config\Writer\PhpArray; +use Zend\Config\Config; +use ZendTest\Config\Writer\TestAssets\PhpReader; /** * @category Zend diff --git a/test/Writer/TestAssets/PhpReader.php b/test/Writer/TestAssets/PhpReader.php new file mode 100644 index 0000000..ba7a527 --- /dev/null +++ b/test/Writer/TestAssets/PhpReader.php @@ -0,0 +1,11 @@ +reader->fromFile(__DIR__ . '/files/allsections.yaml'); + $config = $this->reader->fromFile(__DIR__ . '/_files/allsections.yaml'); $this->writer->toFile($this->getTestAssetFileName(), $config); diff --git a/test/Writer/files/allsections.ini b/test/Writer/_files/allsections.ini similarity index 93% rename from test/Writer/files/allsections.ini rename to test/Writer/_files/allsections.ini index d4eef2d..4eaa75b 100644 --- a/test/Writer/files/allsections.ini +++ b/test/Writer/_files/allsections.ini @@ -1,26 +1,26 @@ -[all] -hostname = all -name = thisname -db.host = 127.0.0.1 -db.user = username -db.pass = password -db.name = live -one.two.three = multi - -[staging] -hostname = staging -db.name = dbstaging -debug = false - -[debug] -hostname = debug -debug = true -values.changed = yes -db.name = dbdebug -special.no = no -special.null = null -special.false = false - -[other_staging] -only_in = otherStaging -db.pass = anotherpwd +[all] +hostname = all +name = thisname +db.host = 127.0.0.1 +db.user = username +db.pass = password +db.name = live +one.two.three = multi + +[staging] +hostname = staging +db.name = dbstaging +debug = false + +[debug] +hostname = debug +debug = true +values.changed = yes +db.name = dbdebug +special.no = no +special.null = null +special.false = false + +[other_staging] +only_in = otherStaging +db.pass = anotherpwd diff --git a/test/Writer/files/allsections.json b/test/Writer/_files/allsections.json similarity index 100% rename from test/Writer/files/allsections.json rename to test/Writer/_files/allsections.json diff --git a/test/Writer/files/allsections.xml b/test/Writer/_files/allsections.xml similarity index 100% rename from test/Writer/files/allsections.xml rename to test/Writer/_files/allsections.xml diff --git a/test/Writer/files/allsections.yaml b/test/Writer/_files/allsections.yaml similarity index 100% rename from test/Writer/files/allsections.yaml rename to test/Writer/_files/allsections.yaml diff --git a/test/Writer/files/PhpReader.php b/test/Writer/files/PhpReader.php deleted file mode 100644 index d7e91fe..0000000 --- a/test/Writer/files/PhpReader.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Mon, 9 Jul 2012 16:19:42 +0200 Subject: [PATCH 5/9] [CS][Library] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:34:21 +0200 Subject: [PATCH 6/9] [CS][test] Remove @copyright & @license for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@copyright/d' $fl.old > $fl; rm -f $fl.old; done; for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@license/d' $fl.old > $fl; rm -f $fl.old; done; --- test/ConfigTest.php | 4 ---- test/FactoryTest.php | 4 ---- test/ProcessorTest.php | 4 ---- test/Reader/AbstractReaderTestCase.php | 4 ---- test/Reader/IniTest.php | 4 ---- test/Reader/JsonTest.php | 4 ---- test/Reader/XmlTest.php | 4 ---- test/Reader/YamlTest.php | 4 ---- test/Writer/AbstractWriterTestCase.php | 4 ---- test/Writer/IniTest.php | 4 ---- test/Writer/JsonTest.php | 4 ---- test/Writer/PhpArrayTest.php | 4 ---- test/Writer/XmlTest.php | 4 ---- test/Writer/YamlTest.php | 4 ---- 14 files changed, 56 deletions(-) diff --git a/test/ConfigTest.php b/test/ConfigTest.php index e5ea31c..8969e7d 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class ConfigTest extends \PHPUnit_Framework_TestCase diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 29f91f9..d34a045 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class FactoryTest extends \PHPUnit_Framework_TestCase diff --git a/test/ProcessorTest.php b/test/ProcessorTest.php index 196ed07..91cb319 100644 --- a/test/ProcessorTest.php +++ b/test/ProcessorTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config; @@ -37,8 +35,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class ProcessorTest extends \PHPUnit_Framework_TestCase diff --git a/test/Reader/AbstractReaderTestCase.php b/test/Reader/AbstractReaderTestCase.php index 55644b8..d0429c3 100644 --- a/test/Reader/AbstractReaderTestCase.php +++ b/test/Reader/AbstractReaderTestCase.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Reader; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ abstract class AbstractReaderTestCase extends TestCase diff --git a/test/Reader/IniTest.php b/test/Reader/IniTest.php index f0d5edb..c975c35 100644 --- a/test/Reader/IniTest.php +++ b/test/Reader/IniTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Reader; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class IniTest extends AbstractReaderTestCase diff --git a/test/Reader/JsonTest.php b/test/Reader/JsonTest.php index 522cdb7..34b9b3b 100644 --- a/test/Reader/JsonTest.php +++ b/test/Reader/JsonTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Reader; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class JsonTest extends AbstractReaderTestCase diff --git a/test/Reader/XmlTest.php b/test/Reader/XmlTest.php index 556ba6f..c80b333 100644 --- a/test/Reader/XmlTest.php +++ b/test/Reader/XmlTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Reader; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class XmlTest extends AbstractReaderTestCase diff --git a/test/Reader/YamlTest.php b/test/Reader/YamlTest.php index 0e08d0b..f90d510 100644 --- a/test/Reader/YamlTest.php +++ b/test/Reader/YamlTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Reader; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class YamlTest extends AbstractReaderTestCase diff --git a/test/Writer/AbstractWriterTestCase.php b/test/Writer/AbstractWriterTestCase.php index 7319703..78eb49c 100644 --- a/test/Writer/AbstractWriterTestCase.php +++ b/test/Writer/AbstractWriterTestCase.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Writer; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ abstract class AbstractWriterTestCase extends TestCase diff --git a/test/Writer/IniTest.php b/test/Writer/IniTest.php index 94a0401..41dea5e 100644 --- a/test/Writer/IniTest.php +++ b/test/Writer/IniTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Writer; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class IniTest extends AbstractWriterTestCase diff --git a/test/Writer/JsonTest.php b/test/Writer/JsonTest.php index 44656bc..91887e0 100644 --- a/test/Writer/JsonTest.php +++ b/test/Writer/JsonTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Writer; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class JsonTest extends AbstractWriterTestCase diff --git a/test/Writer/PhpArrayTest.php b/test/Writer/PhpArrayTest.php index 8caf8e3..b850cd3 100644 --- a/test/Writer/PhpArrayTest.php +++ b/test/Writer/PhpArrayTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Writer; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class PhpArrayTest extends AbstractWriterTestCase diff --git a/test/Writer/XmlTest.php b/test/Writer/XmlTest.php index ed8ad5a..700fa5c 100644 --- a/test/Writer/XmlTest.php +++ b/test/Writer/XmlTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Writer; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class XmlTest extends AbstractWriterTestCase diff --git a/test/Writer/YamlTest.php b/test/Writer/YamlTest.php index b21886c..ed71928 100644 --- a/test/Writer/YamlTest.php +++ b/test/Writer/YamlTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Config\Writer; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Config */ class YamlTest extends AbstractWriterTestCase From 391092327935930491946581319038e333d2ca87 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:41:27 +0200 Subject: [PATCH 7/9] [CS][Tests] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:46:59 -0500 Subject: [PATCH 8/9] [zen-49] Correct import statements across framework - Ran a script that would create multiple import statements out of multi-line import statements, and which would sort all import statements in alphabetic order. Script is at https://gist.github.com/3079222 and was run by dropping into the library/Zend folder and typing (in zsh) "for file in **/*.php;do php /path/to/replace-uses.php $file; done" --- src/Config.php | 2 +- src/Processor/Queue.php | 2 +- src/Processor/Token.php | 2 +- src/Reader/Json.php | 2 +- src/Writer/AbstractWriter.php | 2 +- src/Writer/Xml.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Config.php b/src/Config.php index 70fa03a..ece2b09 100644 --- a/src/Config.php +++ b/src/Config.php @@ -10,9 +10,9 @@ namespace Zend\Config; +use ArrayAccess; use Countable; use Iterator; -use ArrayAccess; use Zend\Stdlib\ArrayUtils; /** diff --git a/src/Processor/Queue.php b/src/Processor/Queue.php index e369149..fb276ba 100644 --- a/src/Processor/Queue.php +++ b/src/Processor/Queue.php @@ -11,8 +11,8 @@ namespace Zend\Config\Processor; use Zend\Config\Config; -use Zend\Stdlib\PriorityQueue; use Zend\Config\Exception; +use Zend\Stdlib\PriorityQueue; /** * @category Zend diff --git a/src/Processor/Token.php b/src/Processor/Token.php index cf725ba..022daf5 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -10,9 +10,9 @@ namespace Zend\Config\Processor; +use Traversable; use Zend\Config\Config; use Zend\Config\Exception; -use Traversable; /** * @category Zend diff --git a/src/Reader/Json.php b/src/Reader/Json.php index 01a5f9e..a84b7e4 100644 --- a/src/Reader/Json.php +++ b/src/Reader/Json.php @@ -11,8 +11,8 @@ namespace Zend\Config\Reader; use Zend\Config\Exception; -use Zend\Json\Json as JsonFormat; use Zend\Json\Exception as JsonException; +use Zend\Json\Json as JsonFormat; /** * JSON config reader. diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php index 1d6df80..b2817ec 100644 --- a/src/Writer/AbstractWriter.php +++ b/src/Writer/AbstractWriter.php @@ -11,8 +11,8 @@ namespace Zend\Config\Writer; use Traversable; -use Zend\Config\Exception; use Zend\Config\Config; +use Zend\Config\Exception; use Zend\Stdlib\ArrayUtils; /** diff --git a/src/Writer/Xml.php b/src/Writer/Xml.php index 1e6ec03..c4e0827 100644 --- a/src/Writer/Xml.php +++ b/src/Writer/Xml.php @@ -10,8 +10,8 @@ namespace Zend\Config\Writer; -use Zend\Config\Exception; use XMLWriter; +use Zend\Config\Exception; /** * @category Zend From 24c143c990aa0d8b28acfab233d02da94311eac2 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 12 Jul 2012 21:11:36 +0200 Subject: [PATCH 9/9] [PSR-2] fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed Applied php-cs-fixer --fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed --- src/Factory.php | 12 ++++----- src/Processor/Filter.php | 2 +- src/Reader/Ini.php | 4 +-- src/Reader/Json.php | 18 ++++++------- src/Reader/Xml.php | 8 +++--- src/Reader/Yaml.php | 24 ++++++++--------- src/ReaderPluginManager.php | 4 +-- src/Writer/AbstractWriter.php | 4 +-- src/Writer/Xml.php | 2 +- src/Writer/Yaml.php | 8 +++--- test/ConfigTest.php | 12 ++++----- test/FactoryTest.php | 16 ++++++------ test/ProcessorTest.php | 36 +++++++++++++------------- test/Reader/AbstractReaderTestCase.php | 12 ++++----- test/Reader/IniTest.php | 16 ++++++------ test/Reader/JsonTest.php | 20 +++++++------- test/Reader/XmlTest.php | 12 ++++----- test/Reader/YamlTest.php | 18 ++++++------- test/Writer/AbstractWriterTestCase.php | 14 +++++----- test/Writer/PhpArrayTest.php | 4 +-- test/Writer/XmlTest.php | 8 +++--- test/Writer/YamlTest.php | 6 ++--- 22 files changed, 129 insertions(+), 131 deletions(-) diff --git a/src/Factory.php b/src/Factory.php index e18b2d1..4631562 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -43,7 +43,7 @@ class Factory * Read a config from a file. * * @param string $filename - * @param boolean $returnConfigObject + * @param boolean $returnConfigObject * @return array|Config * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException @@ -51,16 +51,16 @@ class Factory public static function fromFile($filename, $returnConfigObject = false) { $pathinfo = pathinfo($filename); - + if (!isset($pathinfo['extension'])) { throw new Exception\RuntimeException(sprintf( 'Filename "%s" is missing an extension and cannot be auto-detected', $filename )); } - + $extension = strtolower($pathinfo['extension']); - + if ($extension === 'php') { if (!is_file($filename) || !is_readable($filename)) { throw new Exception\RuntimeException(sprintf( @@ -68,7 +68,7 @@ public static function fromFile($filename, $returnConfigObject = false) $filename )); } - + $config = include $filename; } elseif (isset(self::$extensions[$extension])) { $reader = self::$extensions[$extension]; @@ -93,7 +93,7 @@ public static function fromFile($filename, $returnConfigObject = false) * Read configuration from multiple files and merge them. * * @param array $files - * @param boolean $returnConfigObject + * @param boolean $returnConfigObject * @return array|Config */ public static function fromFiles(array $files, $returnConfigObject = false) diff --git a/src/Processor/Filter.php b/src/Processor/Filter.php index e8154da..1ed0f31 100644 --- a/src/Processor/Filter.php +++ b/src/Processor/Filter.php @@ -56,7 +56,7 @@ public function getFilter() /** * Process - * + * * @param Config $config * @return Config * @throws Exception\InvalidArgumentException diff --git a/src/Reader/Ini.php b/src/Reader/Ini.php index b02df3b..6498c0f 100644 --- a/src/Reader/Ini.php +++ b/src/Reader/Ini.php @@ -86,7 +86,7 @@ function($error, $message = '', $file = '', $line = 0) use ($filename) { ); $ini = parse_ini_file($filename, true); restore_error_handler(); - + return $this->process($ini); } @@ -114,7 +114,7 @@ function($error, $message = '', $file = '', $line = 0) { ); $ini = parse_ini_string($string, true); restore_error_handler(); - + return $this->process($ini); } diff --git a/src/Reader/Json.php b/src/Reader/Json.php index a84b7e4..5d6b7bd 100644 --- a/src/Reader/Json.php +++ b/src/Reader/Json.php @@ -46,15 +46,15 @@ public function fromFile($filename) $filename )); } - + $this->directory = dirname($filename); - + try { $config = JsonFormat::decode(file_get_contents($filename), JsonFormat::TYPE_ARRAY); } catch (JsonException\RuntimeException $e) { throw new Exception\RuntimeException($e->getMessage()); - } - + } + return $this->process($config); } @@ -73,19 +73,19 @@ public function fromString($string) } $this->directory = null; - + try { $config = JsonFormat::decode($string, JsonFormat::TYPE_ARRAY); } catch (JsonException\RuntimeException $e) { throw new Exception\RuntimeException($e->getMessage()); - } - + } + return $this->process($config); } /** * Process the array for @include - * + * * @param array $data * @return array * @throws Exception\RuntimeException @@ -103,7 +103,7 @@ protected function process(array $data) $reader = clone $this; unset($data[$key]); $data = array_replace_recursive($data, $reader->fromFile($this->directory . '/' . $value)); - } + } } return $data; } diff --git a/src/Reader/Xml.php b/src/Reader/Xml.php index ed6ebe8..98a1d0f 100644 --- a/src/Reader/Xml.php +++ b/src/Reader/Xml.php @@ -80,7 +80,7 @@ function($error, $message = '', $file = '', $line = 0) use ($filename) { ); $return = $this->process(); restore_error_handler(); - + return $return; } @@ -98,7 +98,7 @@ public function fromString($string) return array(); } $this->reader = new XMLReader(); - + $this->reader->xml($string, null, LIBXML_XINCLUDE); $this->directory = null; @@ -113,7 +113,7 @@ function($error, $message = '', $file = '', $line = 0) { ); $return = $this->process(); restore_error_handler(); - + return $return; } @@ -175,7 +175,7 @@ protected function processNextElement() $text .= $this->reader->value; } } - + return $children ?: $text; } diff --git a/src/Reader/Yaml.php b/src/Reader/Yaml.php index 5c638cc..c33ef29 100644 --- a/src/Reader/Yaml.php +++ b/src/Reader/Yaml.php @@ -23,21 +23,21 @@ class Yaml implements ReaderInterface { /** * Directory of the YAML file - * + * * @var string */ protected $directory; /** * YAML decoder callback - * + * * @var callable */ protected $yamlDecoder; /** * Constructor - * + * * @param callable $yamlDecoder */ public function __construct($yamlDecoder = null) @@ -99,14 +99,14 @@ public function fromFile($filename) if (null === $this->getYamlDecoder()) { throw new Exception\RuntimeException("You didn't specify a Yaml callback decoder"); } - + $this->directory = dirname($filename); - + $config = call_user_func($this->getYamlDecoder(), file_get_contents($filename)); if (null === $config) { throw new Exception\RuntimeException("Error parsing YAML data"); - } - + } + return $this->process($config); } @@ -126,14 +126,14 @@ public function fromString($string) if (empty($string)) { return array(); } - + $this->directory = null; - + $config = call_user_func($this->getYamlDecoder(), $string); if (null === $config) { throw new Exception\RuntimeException("Error parsing YAML data"); - } - + } + return $this->process($config); } @@ -157,7 +157,7 @@ protected function process(array $data) $reader = clone $this; unset($data[$key]); $data = array_replace_recursive($data, $reader->fromFile($this->directory . '/' . $value)); - } + } } return $data; } diff --git a/src/ReaderPluginManager.php b/src/ReaderPluginManager.php index c059725..2614fd0 100644 --- a/src/ReaderPluginManager.php +++ b/src/ReaderPluginManager.php @@ -20,7 +20,7 @@ class ReaderPluginManager extends AbstractPluginManager { /** * Default set of readers - * + * * @var array */ protected $invokableClasses = array( @@ -33,7 +33,7 @@ class ReaderPluginManager extends AbstractPluginManager /** * Validate the plugin * Checks that the reader loaded is an instance of Reader\ReaderInterface. - * + * * @param Reader\ReaderInterface $plugin * @return void * @throws Exception\InvalidArgumentException if invalid diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php index b2817ec..4726075 100644 --- a/src/Writer/AbstractWriter.php +++ b/src/Writer/AbstractWriter.php @@ -38,12 +38,12 @@ public function toFile($filename, $config, $exclusiveLock = true) if (empty($filename)) { throw new Exception\InvalidArgumentException('No file name specified'); } - + $flags = 0; if ($exclusiveLock) { $flags |= LOCK_EX; } - + set_error_handler( function($error, $message = '', $file = '', $line = 0) use ($filename) { throw new Exception\RuntimeException(sprintf( diff --git a/src/Writer/Xml.php b/src/Writer/Xml.php index c4e0827..844a38f 100644 --- a/src/Writer/Xml.php +++ b/src/Writer/Xml.php @@ -71,7 +71,7 @@ protected function addBranch($branchName, array $config, XMLWriter $writer) $writer->startElement($branchName); $branchType = 'string'; } - } else if ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) { + } elseif ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) { throw new Exception\RuntimeException('Mixing of string and numeric keys is not allowed'); } diff --git a/src/Writer/Yaml.php b/src/Writer/Yaml.php index fc4e8e8..9d4c309 100644 --- a/src/Writer/Yaml.php +++ b/src/Writer/Yaml.php @@ -21,14 +21,14 @@ class Yaml extends AbstractWriter { /** * YAML encoder callback - * + * * @var callable */ protected $yamlEncoder; /** * Constructor - * + * * @param callable|string|null $yamlEncoder */ public function __construct($yamlEncoder = null) @@ -80,12 +80,12 @@ public function processConfig(array $config) if (null === $this->getYamlEncoder()) { throw new Exception\RuntimeException("You didn't specify a Yaml callback encoder"); } - + $config = call_user_func($this->getYamlEncoder(), $config); if (null === $config) { throw new Exception\RuntimeException("Error generating YAML data"); } - + return $config; } } diff --git a/test/ConfigTest.php b/test/ConfigTest.php index fb91052..25eac99 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -483,8 +483,7 @@ public function testUnsettingFirstElementDuringForeachDoesNotSkipAnElement() ), true); $keyList = array(); - foreach ($config as $key => $value) - { + foreach ($config as $key => $value) { $keyList[] = $key; if ($key == 'first') { unset($config->$key); // uses magic Zend\Config\Config::__unset() method @@ -509,8 +508,7 @@ public function testUnsettingAMiddleElementDuringForeachDoesNotSkipAnElement() ), true); $keyList = array(); - foreach ($config as $key => $value) - { + foreach ($config as $key => $value) { $keyList[] = $key; if ($key == 'second') { unset($config->$key); // uses magic Zend\Config\Config::__unset() method @@ -535,8 +533,7 @@ public function testUnsettingLastElementDuringForeachDoesNotSkipAnElement() ), true); $keyList = array(); - foreach ($config as $key => $value) - { + foreach ($config as $key => $value) { $keyList[] = $key; if ($key == 'third') { unset($config->$key); // uses magic Zend\Config\Config::__unset() method @@ -576,7 +573,8 @@ public function testZF6995_toArrayDoesNotDisturbInternalIterator() * @depends testMerge * @link http://framework.zend.com/issues/browse/ZF2-186 */ - public function testZF2_186_mergeReplacingUnnamedConfigSettings(){ + public function testZF2_186_mergeReplacingUnnamedConfigSettings() + { $arrayA = array( 'flag' => true, 'text' => 'foo', diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 466c90f..ffd4836 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -23,17 +23,17 @@ class FactoryTest extends \PHPUnit_Framework_TestCase public function testFromIni() { $config = Factory::fromFile(__DIR__ . '/TestAssets/Ini/include-base.ini'); - + $this->assertEquals('bar', $config['base']['foo']); } - + public function testFromXml() { $config = Factory::fromFile(__DIR__ . '/TestAssets/Xml/include-base.xml'); - + $this->assertEquals('bar', $config['base']['foo']); } - + public function testFromIniFiles() { $files = array ( @@ -45,7 +45,7 @@ public function testFromIniFiles() $this->assertEquals('bar', $config['base']['foo']); $this->assertEquals('baz', $config['test']['bar']); } - + public function testFromXmlFiles() { $files = array ( @@ -57,7 +57,7 @@ public function testFromXmlFiles() $this->assertEquals('bar', $config['base']['foo']); $this->assertEquals('baz', $config['test']['bar']); } - + public function testFromPhpFiles() { $files = array ( @@ -69,7 +69,7 @@ public function testFromPhpFiles() $this->assertEquals('bar', $config['base']['foo']); $this->assertEquals('baz', $config['test']['bar']); } - + public function testFromIniAndXmlAndPhpFiles() { $files = array ( @@ -89,7 +89,7 @@ public function testReturnsConfigObjectIfRequestedAndArrayOtherwise() $files = array ( __DIR__ . '/TestAssets/Ini/include-base.ini', ); - + $configArray = Factory::fromFile($files[0]); $this->assertTrue(is_array($configArray)); diff --git a/test/ProcessorTest.php b/test/ProcessorTest.php index 9adc3fe..aaeb368 100644 --- a/test/ProcessorTest.php +++ b/test/ProcessorTest.php @@ -181,7 +181,7 @@ public function testAddInvalidToken() 'Cannot use ' . gettype(array()) . ' as token name.'); $processor->addToken(array(), 'bar'); } - + public function testSingleValueToken() { $processor = new TokenProcessor(); @@ -190,18 +190,18 @@ public function testSingleValueToken() $out = $processor->processValue($data); $this->assertEquals($out, 'test'); } - + public function testTokenReadOnly() { $config = new Config($this->tokenBare, false); $processor = new TokenProcessor(); $processor->addToken('BARETOKEN', 'some replaced value'); - + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'Cannot process config because it is read-only'); $processor->process($config); } - + public function testTokenPrefix() { $config = new Config($this->tokenPrefix, true); @@ -287,7 +287,7 @@ public function testUserConstants() $this->assertTrue(is_array($tokens)); $this->assertTrue(in_array('SOME_USERLAND_CONSTANT', $tokens)); $this->assertTrue(!$processor->getUserOnly()); - + $this->assertEquals('some constant value', $config->simple); $this->assertEquals('some text with some constant value inside', $config->inside); $this->assertEquals('some constant value', $config->nested->simple); @@ -305,17 +305,17 @@ public function testUserOnlyConstants() $processor->process($config); $tokens = $processor->getTokens(); - + $this->assertTrue(is_array($tokens)); $this->assertTrue(in_array('SOME_USERLAND_CONSTANT', $tokens)); $this->assertTrue($processor->getUserOnly()); - + $this->assertEquals('some constant value', $config->simple); $this->assertEquals('some text with some constant value inside', $config->inside); $this->assertEquals('some constant value', $config->nested->simple); $this->assertEquals('some text with some constant value inside', $config->nested->inside); } - + /** * @depends testTokenSurround */ @@ -358,7 +358,7 @@ public function testTranslatorReadOnly() } public function testTranslatorSingleValue() - { + { $translator = new Translator(); $translator->addTranslationFile('phparray', $this->translatorFile); $processor = new TranslatorProcessor($translator); @@ -371,7 +371,7 @@ public function testFilter() $config = new Config($this->filter, true); $filter = new StringToLower(); $processor = new FilterProcessor($filter); - + $this->assertTrue($processor->getFilter() instanceof StringToLower); $processor->process($config); @@ -384,21 +384,21 @@ public function testFilterReadOnly() $config = new Config($this->filter, false); $filter = new StringToLower(); $processor = new FilterProcessor($filter); - + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'Cannot process config because it is read-only'); $processor->process($config); } - + public function testFilterValue() { $filter = new StringToLower(); $processor = new FilterProcessor($filter); - + $value = 'TEST'; $this->assertEquals('test', $processor->processValue($value)); } - + /** * @depends testFilter */ @@ -421,7 +421,7 @@ public function testQueueFIFO() $this->assertEquals('some mixedcase value', $config->simple); $this->assertEquals('other mixed case value', $config->nested->simple); } - + public function testQueueReadOnly() { $config = new Config($this->filter, false); @@ -433,7 +433,7 @@ public function testQueueReadOnly() */ $queue = new Queue(); $queue->insert($lowerProcessor); - + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'Cannot process config because it is read-only'); $queue->process($config); @@ -452,10 +452,10 @@ public function testQueueSingleValue() $queue = new Queue(); $queue->insert($upperProcessor); $queue->insert($lowerProcessor); - + $data ='TeSt'; $this->assertEquals('test', $queue->processValue($data)); - + } /** diff --git a/test/Reader/AbstractReaderTestCase.php b/test/Reader/AbstractReaderTestCase.php index 05db52c..1e45a5c 100644 --- a/test/Reader/AbstractReaderTestCase.php +++ b/test/Reader/AbstractReaderTestCase.php @@ -26,28 +26,28 @@ abstract class AbstractReaderTestCase extends TestCase * @var ReaderInterface */ protected $reader; - + /** * Get test asset name for current test case. - * + * * @param string $name * @return string */ abstract protected function getTestAssetPath($name); - + public function testMissingFile() { $filename = $this->getTestAssetPath('no-file'); $this->setExpectedException('Zend\Config\Exception\RuntimeException', "doesn't exist or not readable"); - $config = $this->reader->fromFile($filename); + $config = $this->reader->fromFile($filename); } - + public function testFromFile() { $config = $this->reader->fromFile($this->getTestAssetPath('include-base')); $this->assertEquals('foo', $config['foo']); } - + public function testFromEmptyString() { $config = $this->reader->fromString(''); diff --git a/test/Reader/IniTest.php b/test/Reader/IniTest.php index e17452a..f814218 100644 --- a/test/Reader/IniTest.php +++ b/test/Reader/IniTest.php @@ -24,10 +24,10 @@ public function setUp() { $this->reader = new Ini(); } - + /** * getTestAssetPath(): defined by AbstractReaderTestCase. - * + * * @see AbstractReaderTestCase::getTestAssetPath() * @return string */ @@ -35,14 +35,14 @@ protected function getTestAssetPath($name) { return __DIR__ . '/TestAssets/Ini/' . $name . '.ini'; } - + public function testInvalidIniFile() { $this->reader = new Ini(); $this->setExpectedException('Zend\Config\Exception\RuntimeException'); $arrayIni = $this->reader->fromFile($this->getTestAssetPath('invalid')); } - + public function testFromString() { $ini = <<reader->fromString($ini); $this->assertEquals($arrayIni['test'], 'foo'); $this->assertEquals($arrayIni['bar'][0], 'baz'); $this->assertEquals($arrayIni['bar'][1], 'foo'); } - + public function testInvalidString() { $ini = <<setExpectedException('Zend\Config\Exception\RuntimeException'); $arrayIni = $this->reader->fromString($ini); } - + public function testFromStringWithSection() { $ini = <<reader->fromString($ini); $this->assertEquals($arrayIni['all']['test'], 'foo'); $this->assertEquals($arrayIni['all']['bar'][0], 'baz'); diff --git a/test/Reader/JsonTest.php b/test/Reader/JsonTest.php index 0832624..20cc681 100644 --- a/test/Reader/JsonTest.php +++ b/test/Reader/JsonTest.php @@ -24,10 +24,10 @@ public function setUp() { $this->reader = new Json(); } - + /** * getTestAssetPath(): defined by AbstractReaderTestCase. - * + * * @see AbstractReaderTestCase::getTestAssetPath() * @return string */ @@ -35,36 +35,36 @@ protected function getTestAssetPath($name) { return __DIR__ . '/TestAssets/Json/' . $name . '.json'; } - + public function testInvalidJsonFile() { $this->setExpectedException('Zend\Config\Exception\RuntimeException'); $arrayJson = $this->reader->fromFile($this->getTestAssetPath('invalid')); } - + public function testIncludeAsElement() { $arrayJson = $this->reader->fromFile($this->getTestAssetPath('include-base_nested')); $this->assertEquals($arrayJson['bar']['foo'], 'foo'); } - + public function testFromString() { $json = '{ "test" : "foo", "bar" : [ "baz", "foo" ] }'; - + $arrayJson = $this->reader->fromString($json); - + $this->assertEquals($arrayJson['test'], 'foo'); $this->assertEquals($arrayJson['bar'][0], 'baz'); $this->assertEquals($arrayJson['bar'][1], 'foo'); } - + public function testInvalidString() { $json = '{"foo":"bar"'; - + $this->setExpectedException('Zend\Config\Exception\RuntimeException'); $arrayIni = $this->reader->fromString($json); } - + } diff --git a/test/Reader/XmlTest.php b/test/Reader/XmlTest.php index 066a1eb..9258a74 100644 --- a/test/Reader/XmlTest.php +++ b/test/Reader/XmlTest.php @@ -24,10 +24,10 @@ public function setUp() { $this->reader = new Xml(); } - + /** * getTestAssetPath(): defined by AbstractReaderTestCase. - * + * * @see AbstractReaderTestCase::getTestAssetPath() * @return string */ @@ -35,14 +35,14 @@ protected function getTestAssetPath($name) { return __DIR__ . '/TestAssets/Xml/' . $name . '.xml'; } - + public function testInvalidXmlFile() { $this->reader = new Xml(); $this->setExpectedException('Zend\Config\Exception\RuntimeException'); $arrayXml = $this->reader->fromFile($this->getTestAssetPath('invalid')); } - + public function testFromString() { $xml = << ECS; - + $arrayXml= $this->reader->fromString($xml); $this->assertEquals($arrayXml['test'], 'foo'); $this->assertEquals($arrayXml['bar'][0], 'baz'); $this->assertEquals($arrayXml['bar'][1], 'foo'); } - + public function testInvalidString() { $xml = <<markTestSkipped('Yaml test for Zend\Config skipped'); } - + if (constant('TESTS_ZEND_CONFIG_YAML_LIB_INCLUDE')) { require_once constant('TESTS_ZEND_CONFIG_YAML_LIB_INCLUDE'); } - + $yamlReader = explode('::', constant('TESTS_ZEND_CONFIG_READER_YAML_CALLBACK')); if (isset($yamlReader[1])) { $this->reader = new YamlReader(array($yamlReader[0], $yamlReader[1])); @@ -38,10 +38,10 @@ public function setUp() $this->reader = new YamlReader(array($yamlReader[0])); } } - + /** * getTestAssetPath(): defined by AbstractReaderTestCase. - * + * * @see AbstractReaderTestCase::getTestAssetPath() * @return string */ @@ -49,13 +49,13 @@ protected function getTestAssetPath($name) { return __DIR__ . '/TestAssets/Yaml/' . $name . '.yaml'; } - + public function testInvalidIniFile() { $this->setExpectedException('Zend\Config\Exception\RuntimeException'); $arrayIni = $this->reader->fromFile($this->getTestAssetPath('invalid')); } - + public function testFromString() { $yaml = <<reader->fromString($yaml); $this->assertEquals($arrayYaml['test'], 'foo'); $this->assertEquals($arrayYaml['bar'][0], 'baz'); $this->assertEquals($arrayYaml['bar'][1], 'foo'); } - + public function testFromStringWithSection() { $yaml = <<tmpfile; } - + public function tearDown() { if (file_exists($this->getTestAssetFileName())) { @@ -60,7 +60,7 @@ public function tearDown() @unlink($this->getTestAssetFileName()); } } - + public function testNoFilenameSet() { $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No file name specified'); @@ -72,7 +72,7 @@ public function testFileNotValid() $this->setExpectedException('Zend\Config\Exception\RuntimeException'); $this->writer->toFile('.', new Config(array())); } - + public function testFileNotWritable() { $this->setExpectedException('Zend\Config\Exception\RuntimeException'); diff --git a/test/Writer/PhpArrayTest.php b/test/Writer/PhpArrayTest.php index 80d2e80..2dae349 100644 --- a/test/Writer/PhpArrayTest.php +++ b/test/Writer/PhpArrayTest.php @@ -36,7 +36,7 @@ public function setUp() public function testRender() { $config = new Config(array('test' => 'foo', 'bar' => array(0 => 'baz', 1 => 'foo'))); - + $configString = $this->writer->toString($config); // build string line by line as we are trailing-whitespace sensitive. @@ -49,7 +49,7 @@ public function testRender() $expected .= " 1 => 'foo',\n"; $expected .= " ),\n"; $expected .= ");\n"; - + $this->assertEquals($expected, $configString); } } diff --git a/test/Writer/XmlTest.php b/test/Writer/XmlTest.php index f2a8a7d..16f0c70 100644 --- a/test/Writer/XmlTest.php +++ b/test/Writer/XmlTest.php @@ -48,7 +48,7 @@ public function testToString() $this->assertEquals($expected, $configString); } - + public function testSectionsToString() { $config = new Config(array(), true); @@ -61,9 +61,9 @@ public function testSectionsToString() $config->production->database->params->username = 'production'; $config->production->database->params->password = 'secret'; $config->production->database->params->dbname = 'dbproduction'; - + $configString = $this->writer->toString($config); - + $expected = << @@ -81,7 +81,7 @@ public function testSectionsToString() ECS; - + $this->assertEquals($expected, $configString); } } diff --git a/test/Writer/YamlTest.php b/test/Writer/YamlTest.php index cc2c864..d0d9db1 100644 --- a/test/Writer/YamlTest.php +++ b/test/Writer/YamlTest.php @@ -27,18 +27,18 @@ public function setUp() if (!constant('TESTS_ZEND_CONFIG_YAML_ENABLED')) { $this->markTestSkipped('Yaml test for Zend\Config skipped'); } - + if (constant('TESTS_ZEND_CONFIG_YAML_LIB_INCLUDE')) { require_once constant('TESTS_ZEND_CONFIG_YAML_LIB_INCLUDE'); } - + $yamlReader = explode('::', constant('TESTS_ZEND_CONFIG_READER_YAML_CALLBACK')); if (isset($yamlReader[1])) { $this->reader = new YamlReader(array($yamlReader[0], $yamlReader[1])); } else { $this->reader = new YamlReader(array($yamlReader[0])); } - + $yamlWriter = explode('::', constant('TESTS_ZEND_CONFIG_WRITER_YAML_CALLBACK')); if (isset($yamlWriter[1])) { $this->writer = new YamlWriter(array($yamlWriter[0], $yamlWriter[1]));