diff --git a/phalcon/translate/adapter/csv.zep b/phalcon/translate/adapter/csv.zep index 1f952f196e9..6796bbd59ce 100644 --- a/phalcon/translate/adapter/csv.zep +++ b/phalcon/translate/adapter/csv.zep @@ -49,13 +49,13 @@ class Csv extends Adapter implements AdapterInterface, \ArrayAccess "enclosure": "\"" ], options); - if is_readable(options["content"]) === false { - throw new Exception("Error opening translation file '" . options["content"] . "'"); - } - var file; let file = fopen(options["content"], "rb"); + if typeof file !== "resource" { + throw new Exception("Error opening translation file '" . options["content"] . "'"); + } + var data; loop { diff --git a/unit-tests/ConfigTest.php b/unit-tests/ConfigTest.php index 8d9c39550c5..4987d3511f4 100644 --- a/unit-tests/ConfigTest.php +++ b/unit-tests/ConfigTest.php @@ -24,228 +24,228 @@ class ConfigTest extends PHPUnit_Framework_TestCase { - private $_config = array( - "phalcon" => array( - "baseuri" => "/phalcon/" - ), - "models" => array( - "metadata" => "memory" - ), - "database" => array( - "adapter" => "mysql", - "host" => "localhost", - "username" => "user", - "password" => "passwd", - "name" => "demo" - ), - "test" => array( - "parent" => array( - "property" => 1, - ), - "parent" => array( - "property2" => "yeah" - ) - ) - ); + private $_config = array( + "phalcon" => array( + "baseuri" => "/phalcon/" + ), + "models" => array( + "metadata" => "memory" + ), + "database" => array( + "adapter" => "mysql", + "host" => "localhost", + "username" => "user", + "password" => "passwd", + "name" => "demo" + ), + "test" => array( + "parent" => array( + "property" => 1, + ), + "parent" => array( + "property2" => "yeah" + ) + ) + ); - private function _compareConfig($c, $config) - { - foreach ($c as $k => $v) { - $this->assertTrue(isset($config->$k)); - if (is_array($v)) { - if (isset($config->$k)) { - foreach ($v as $kk => $vv) { - $this->assertTrue(isset($config->$k->$kk)); - if (isset($config->$k->$kk)) { - if (is_array($vv)) { - foreach ($vv as $kkk => $vvv) { - if (isset($config->$k->$kk->$kkk)) { - $this->assertTrue(isset($config->$k->$kk->$kkk)); - $this->assertEquals($vvv, $config->$k->$kk->$kkk); - } - } - } else { - $this->assertEquals($vv, $config->$k->$kk); - } - } - } - } - } - } - return true; - } + private function _compareConfig($c, $config) + { + foreach ($c as $k => $v) { + $this->assertTrue(isset($config->$k)); + if (is_array($v)) { + if (isset($config->$k)) { + foreach ($v as $kk => $vv) { + $this->assertTrue(isset($config->$k->$kk)); + if (isset($config->$k->$kk)) { + if (is_array($vv)) { + foreach ($vv as $kkk => $vvv) { + if (isset($config->$k->$kk->$kkk)) { + $this->assertTrue(isset($config->$k->$kk->$kkk)); + $this->assertEquals($vvv, $config->$k->$kk->$kkk); + } + } + } else { + $this->assertEquals($vv, $config->$k->$kk); + } + } + } + } + } + } + return true; + } - public function testIniConfig() - { - $config = new Phalcon\Config\Adapter\Ini('unit-tests/config/config.ini'); - $this->assertTrue($this->_compareConfig($this->_config, $config)); - } + public function testIniConfig() + { + $config = new Phalcon\Config\Adapter\Ini('unit-tests/config/config.ini'); + $this->assertTrue($this->_compareConfig($this->_config, $config)); + } - public function testStandardConfig() - { - $config = new Phalcon\Config($this->_config); - $this->_compareConfig($this->_config, $config); - } + public function testStandardConfig() + { + $config = new Phalcon\Config($this->_config); + $this->_compareConfig($this->_config, $config); + } - public function testStandardConfigSimpleArray() - { + public function testStandardConfigSimpleArray() + { - $expectedConfig = Phalcon\Config::__set_state(array( - 'database' => Phalcon\Config::__set_state(array( - 'adapter' => 'Mysql', - 'host' => 'localhost', - 'username' => 'scott', - 'password' => 'cheetah', - 'name' => 'test_db', - )), - 'other' => array( - 0 => 1, - 1 => 2, - 2 => 3, - 3 => 4, - ), - )); + $expectedConfig = Phalcon\Config::__set_state(array( + 'database' => Phalcon\Config::__set_state(array( + 'adapter' => 'Mysql', + 'host' => 'localhost', + 'username' => 'scott', + 'password' => 'cheetah', + 'name' => 'test_db', + )), + 'other' => array( + 0 => 1, + 1 => 2, + 2 => 3, + 3 => 4, + ), + )); - $settings = array( - "database" => array( - "adapter" => "Mysql", - "host" => "localhost", - "username" => "scott", - "password" => "cheetah", - "name" => "test_db", - ), - "other" => array(1, 2, 3, 4) - ); - $config = new Phalcon\Config($settings); + $settings = array( + "database" => array( + "adapter" => "Mysql", + "host" => "localhost", + "username" => "scott", + "password" => "cheetah", + "name" => "test_db", + ), + "other" => array(1, 2, 3, 4) + ); + $config = new Phalcon\Config($settings); - $this->assertEquals($config, $expectedConfig); - } + $this->assertEquals($config, $expectedConfig); + } - public function testConfigMerge() - { + public function testConfigMerge() + { - $config1 = new Phalcon\Config(array( - "controllersDir" => "../x/y/z", - "modelsDir" => "../x/y/z", - "database" => array( - "adapter" => "Mysql", - "host" => "localhost", - "username" => "scott", - "password" => "cheetah", - "name" => "test_db", - "charset" => array( - "primary" => "utf8" - ), - "alternatives" => array( - "primary" => "latin1", - "second" => "latin1" - ) - ), - )); + $config1 = new Phalcon\Config(array( + "controllersDir" => "../x/y/z", + "modelsDir" => "../x/y/z", + "database" => array( + "adapter" => "Mysql", + "host" => "localhost", + "username" => "scott", + "password" => "cheetah", + "name" => "test_db", + "charset" => array( + "primary" => "utf8" + ), + "alternatives" => array( + "primary" => "latin1", + "second" => "latin1" + ) + ), + )); - $config2 = new Phalcon\Config(array( - "modelsDir" => "../x/y/z", - "database" => array( - "adapter" => "Postgresql", - "host" => "localhost", - "username" => "peter", - "options" => array( - "case" => "lower", + $config2 = new Phalcon\Config(array( + "modelsDir" => "../x/y/z", + "database" => array( + "adapter" => "Postgresql", + "host" => "localhost", + "username" => "peter", + "options" => array( + "case" => "lower", // PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', - ), - "alternatives" => array( - "primary" => "swedish", - "third" => "american" - ) - ), - )); + ), + "alternatives" => array( + "primary" => "swedish", + "third" => "american" + ) + ), + )); - $config1->merge($config2); + $config1->merge($config2); - $expected = Phalcon\Config::__set_state(array( - 'controllersDir' => '../x/y/z', - 'modelsDir' => '../x/y/z', - 'database' => Phalcon\Config::__set_state(array( - 'adapter' => 'Postgresql', - 'host' => 'localhost', - 'username' => 'peter', - 'password' => 'cheetah', - 'name' => 'test_db', - 'charset' => Phalcon\Config::__set_state(array( - 'primary' => 'utf8', - )), - 'alternatives' => Phalcon\Config::__set_state(array( - 'primary' => 'swedish', - 'second' => 'latin1', - 'third' => 'american', - )), - 'options' => Phalcon\Config::__set_state(array( - 'case' => 'lower', - // todo: add support numeric keys as properties + $expected = Phalcon\Config::__set_state(array( + 'controllersDir' => '../x/y/z', + 'modelsDir' => '../x/y/z', + 'database' => Phalcon\Config::__set_state(array( + 'adapter' => 'Postgresql', + 'host' => 'localhost', + 'username' => 'peter', + 'password' => 'cheetah', + 'name' => 'test_db', + 'charset' => Phalcon\Config::__set_state(array( + 'primary' => 'utf8', + )), + 'alternatives' => Phalcon\Config::__set_state(array( + 'primary' => 'swedish', + 'second' => 'latin1', + 'third' => 'american', + )), + 'options' => Phalcon\Config::__set_state(array( + 'case' => 'lower', + // todo: add support numeric keys as properties // (string)PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', - )), - )), - )); + )), + )), + )); - $this->assertEquals($config1, $expected); + $this->assertEquals($config1, $expected); - } + } public function testConfigCount() { - $config = new Phalcon\Config(array( - "controllersDir" => "../x/y/z", - "modelsDir" => "../x/y/z", - )); + $config = new Phalcon\Config(array( + "controllersDir" => "../x/y/z", + "modelsDir" => "../x/y/z", + )); - $this->assertEquals(2, count($config)); + $this->assertEquals(2, count($config)); } - public function testIniConfigDirective() - { - $config = new \Phalcon\Config\Adapter\Ini('unit-tests/config/directive.ini'); - $actual = $config->toArray(); - $expected = array( - 'test' => array( - 'parent' => array( - 'property' => 1, - 'property2' => 'yeah', - 'property3' => array('baseuri' => '/phalcon/'), - 'property4' => array( - 'models' => array('metadata' => 'memory'), - ), - 'property5' => array( - 'database' => array( - 'adapter' => 'mysql', - 'host' => 'localhost', - 'username' => 'user', - 'password' => 'passwd', - 'name' => 'demo'), - ), - 'property6' => array( - 'test' => array('a', 'b', 'c'), - ), - ), - ), - ); + public function testIniConfigDirective() + { + $config = new \Phalcon\Config\Adapter\Ini('unit-tests/config/directive.ini'); + $actual = $config->toArray(); + $expected = array( + 'test' => array( + 'parent' => array( + 'property' => 1, + 'property2' => 'yeah', + 'property3' => array('baseuri' => '/phalcon/'), + 'property4' => array( + 'models' => array('metadata' => 'memory'), + ), + 'property5' => array( + 'database' => array( + 'adapter' => 'mysql', + 'host' => 'localhost', + 'username' => 'user', + 'password' => 'passwd', + 'name' => 'demo'), + ), + 'property6' => array( + 'test' => array('a', 'b', 'c'), + ), + ), + ), + ); - $this->assertEquals($actual, $expected); - } + $this->assertEquals($actual, $expected); + } - public function testPhpConfig() - { - $config = new Phalcon\Config\Adapter\Php('unit-tests/config/config.php'); - $this->assertTrue($this->_compareConfig($this->_config, $config)); - } + public function testPhpConfig() + { + $config = new Phalcon\Config\Adapter\Php('unit-tests/config/config.php'); + $this->assertTrue($this->_compareConfig($this->_config, $config)); + } - public function testJsonConfig() - { - $config = new Phalcon\Config\Adapter\Json('unit-tests/config/config.json'); - $this->assertTrue($this->_compareConfig($this->_config, $config)); - } + public function testJsonConfig() + { + $config = new Phalcon\Config\Adapter\Json('unit-tests/config/config.json'); + $this->assertTrue($this->_compareConfig($this->_config, $config)); + } - public function testYamlConfig() + public function testYamlConfig() { $config = new Phalcon\Config\Adapter\Yaml('unit-tests/config/config.yml'); $this->assertTrue($this->_compareConfig($this->_config, $config)); @@ -254,10 +254,11 @@ public function testYamlConfig() public function testYamlConfigCallback() { $config = new Phalcon\Config\Adapter\Yaml('unit-tests/config/config.yml', array( - '!decrypt' => function($value) { - return (new Phalcon\Crypt)->setCipher('blowfish')->decryptBase64($value, CONFKEY); + '!decrypt' => function ($value) { + $crypt = new Phalcon\Crypt; + return $crypt->setCipher('blowfish')->decryptBase64($value, CONFKEY); }, - '!approot' => function($value) { + '!approot' => function ($value) { return APPROOT . $value; } ));