Source for file PMO_MyConfig_Test.php
Documentation is available at PMO_MyConfig_Test.php
* This file is part of the PhpMyObject project,
* an Object-Relational Mapping (ORM) system.
* For questions, help, comments, discussion, etc., please join our
* forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770}
* or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
* PhpMyProject is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {@link http://www.gnu.org/licenses/}.
* @author Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
* @author Louis Lapointe <laplix@gmail.com>
* @link http://pmo.developpez.com/
* @since PhpMyObject v0.15
* @version $Revision: 400 $
* @copyright Copyright (c) 2007-2008 Nicolas Boiteux
* @copyright Copyright (c) 2008 Louis Lapointe
* @license GPLv3 {@link http://www.gnu.org/licenses/gpl}
* setup this test case if called individually
require_once(dirname(dirname(__FILE__ )). DIRECTORY_SEPARATOR. 'config.php');
require_once(SIMPLETEST. DS. 'autorun.php');
require_once(PMO_CORE. DS. 'PMO_MyConfig.php');
* This tests the PMO_MyConfig class.
/** constructor calls parent contructor. */
/** called before each test */
* @todo will probably need this later to reset the config or something
* exists has been deprecated
function test_exist_empty_var_name()
$conf = PMO_MyConfig::factory();
$this->fail('PMO_MyConfig::exists("") should have thrown an exception.');
$this->assertEqual($e->getMessage(), 'Error: Empty parameter',
'Asking if an empty varname exists throws an exception');
* this make sure we get an exception if we don't provide a parameter
$this->fail('PMO_MyConfig::set("") should have thrown an exception.');
//echo "<pre>".str_replace(' ','.',$e->getMessage())."</pre><br>";
$this->assertEqual($e->getMessage(),
sprintf("Error: Parameter %s doesn't exist",''),
'Writing to an empty varname throws an exception');
* this make sure PMO_MyConfig will throw an exception if we try
* to get an unsuported var.
$this->fail('PMO_MyConfig::get("") should have thrown an excepyion.');
$this->assertEqual($e->getMessage(),
sprintf("Error: Parameter %s doesn't exist",''),
"Reading an empty varname throws an exception");
* this make sure PMO_MyConfig will throw an exception if we try
* to set an unsuported var.
$conf->set('MyVar', 'I exist');
$this->fail('PMO_MyConfig::set("MyVar") should have thrown an exception');
$this->assertEqual($e->getMessage(),
sprintf("Error: Parameter %s doesn't exist",'MyVar'),
"Writing to a non-existant var throws an exception");
* this make sure PMO_MyConfig will throw an exception of we ask
$myvar = $conf->get('MyVar');
$this->fail('PMO_MyConfig::get("MyVar") should have thrown an exception');
$this->assertEqual($e->getMessage(),
sprintf("Error: Parameter %s doesn't exist",'MyVar'),
"Writing to a unknown var throws an exception");
* this will test that all PMO standard vars exist.
/***********************************
* la fonction exists() a été dépréciée
function test_exists_PMO_standard_vars()
$conf = PMO_MyConfig::factory();
$this->assertTrue($conf->exists('PMO_MyController.OBJECT_COLLECTOR_NAME'), 'PMO_MyController.OBJECT_COLLECTOR_NAME exists');
$this->assertTrue($conf->exists('PMO_MyDbms.DRIVER'), '"PMO_MyDbms.DRIVER" exists');
$this->assertTrue($conf->exists('PMO_MyDbms.PDODRIVER'), '"PMO_MyDbms.PDODRIVER" exists');
$this->assertTrue($conf->exists('PMO_MyDbms.HOST'), '"PMO_MyDbms.HOST" exists.');
$this->assertTrue($conf->exists('PMO_MyDbms.BASE'), '"PMO_MyDbms.BASE" exists.');
$this->assertTrue($conf->exists('PMO_MyDbms.USER'), '"PMO_MyDbms.USER" exists.');
$this->assertTrue($conf->exists('PMO_MyDbms.PASS'), '"PMO_MyDbms.PASS" exists.');
$this->assertTrue($conf->exists('PMO_MyDbms.DSN'), '"PMO_MyDbms.DSN" exists.');
$this->assertTrue($conf->exists('PMO_MyDbms.LOG'), '"PMO_MyDbms.LOG" exists.');
$this->assertTrue($conf->exists('PMO_MyDbms.LOG_FORMAT'), '"PMO_MyDbms.LOG_FORMAT" exists.');
$path = realpath($conf->get('PMO_MyObject.CLASSPATH'));
$expected = realpath(PMO_ROOT.DS.'class_loader'.DS);
$this->assertTrue($conf->exists('PMO_MyObject.CLASSPATH'), '"PMO_MyObject.CLASSPATH" exists.');
$this->assertTrue($conf->exists('PMO_MyTable.CLASS_WRITE_ON_DISK'), '"PMO_MyTable.CLASS_WRITE_ON_DISK" exists.');
$this->assertTrue($conf->exists('PMO_MyTable.CLASS_FILENAME_PREFIX'), '"PMO_MyTable.CLASS_FILENAME_PREFIX" exists.');
$path = realpath($conf->get('PMO_MyTable.CLASSPATH'));
$expected = realpath(PMO_CORE.DS.'PMO_MyTable'.DS);
$this->assertTrue($conf->exists('PMO_MyTable.CLASSPATH'), '"PMO_MyTable.CLASSPATH" exists.');
$this->assertTrue($conf->exists('PMO_MyMemCache.ACTIVE'), '"PMO_MyMemCache.ACTIVE" exists.');
$this->assertTrue($conf->exists('PMO_MyMemCache.HOST'), '"PMO_MyMemCache.HOST" exists.');
$this->assertTrue($conf->exists('PMO_MyMemCache.PORT'), '"PMO_MyMemCache.PORT" exists.');
$this->assertTrue($conf->exists('PMO_MyMemCache.TIMEOUT'), '"PMO_MyMemCache.TIMEOUT" exists.');
*******************************/
* this tests that all PMO standard vars are correcly initialized
$this->assertEqual($conf->get('PMO_MyController.OBJECT_COLLECTOR_NAME'), 'collector');
$this->assertEqual($conf->get('PMO_MyDbms.DRIVER'), '');
$this->assertEqual($conf->get('PMO_MyDbms.PDODRIVER'), '');
$this->assertEqual($conf->get('PMO_MyDbms.HOST'), '');
$this->assertEqual($conf->get('PMO_MyDbms.BASE'), '');
$this->assertEqual($conf->get('PMO_MyDbms.USER'), '');
$this->assertEqual($conf->get('PMO_MyDbms.PASS'), '');
$this->assertEqual($conf->get('PMO_MyDbms.DSN'), '');
$this->assertFalse($conf->get('PMO_MyDbms.LOG'));
$this->assertEqual($conf->get('PMO_MyDbms.LOG_FORMAT'), 'Y-m-d H:i:s');
$path = realpath($conf->get('PMO_MyObject.CLASSPATH'));
$expected = realpath(PMO_ROOT. DS. 'class_loader'. DS);
$this->assertEqual($path, $expected);
$this->assertEqual($conf->get('PMO_MyObject.CLASS_FILENAME_PREFIX'), 'class_');
$this->assertFalse($conf->get('PMO_MyMemCache.ACTIVE'));
$this->assertEqual($conf->get('PMO_MyMemCache.HOST'), '');
$this->assertEqual($conf->get('PMO_MyMemCache.PORT'), '');
$this->assertEqual($conf->get('PMO_MyMemCache.TIMEOUT'), '10');
$path = realpath($conf->get('PMO_MyTable.CLASSPATH'));
$expected = realpath(PMO_CORE. DS. 'PMO_MyTable'. DS);
$this->assertEqual($path, $expected);
$this->assertEqual($conf->get('PMO_MyTable.CLASS_FILENAME_PREFIX'), 'PMO_MyTable_');
$this->assertFalse($conf->get('PMO_MyTable.CLASS_WRITE_ON_DISK'));
$conf->set('PMO_MyDbms.DRIVER', 'pdo');
$conf->set('PMO_MyDbms.PDODRIVER', 'sqlite');
$conf->set('PMO_MyDbms.HOST', 'myHost');
$conf->set('PMO_MyDbms.USER', 'myUser');
$conf->set('PMO_MyDbms.PASS', 'myPass');
$conf->set('PMO_MyDbms.DSN', 'sqlite:/my/data/base.db');
$conf->set('PMO_MyDbms.LOG', TRUE);
$conf->set('PMO_MyDbms.LOG_FORMAT', 'd/m/Y H:m');
$conf->set('PMO_MyObject.CLASSPATH', '/my/new/classpath');
$conf->set('PMO_MyObject.CLASS_FILENAME_PREFIX', 'myFilePrefix_');
$conf->set('PMO_MyTable.CLASS_WRITE_ON_DISK', TRUE);
$conf->set('PMO_MyTable.CLASSPATH', 'my/pmo_classpath');
$conf->set('PMO_MyTable.CLASS_FILENAME_PREFIX', 'MyFile_');
$conf->set('PMO_MyMemCache.ACTIVE', TRUE);
$conf->set('PMO_MyMemCache.HOST', 'memhost');
$conf->set('PMO_MyMemCache.PORT', '3535');
$conf->set('PMO_MyMemCache.TIMEOUT', 45);
$this->assertEqual($conf->get('PMO_MyDbms.DRIVER'), 'pdo');
$this->assertEqual($conf->get('PMO_MyDbms.PDODRIVER'), 'sqlite');
$this->assertEqual($conf->get('PMO_MyDbms.HOST'), 'myHost');
$this->assertEqual($conf->get('PMO_MyDbms.USER'), 'myUser');
$this->assertEqual($conf->get('PMO_MyDbms.PASS'), 'myPass');
$this->assertEqual($conf->get('PMO_MyDbms.DSN'), 'sqlite:/my/data/base.db');
$this->assertTrue($conf->get('PMO_MyDbms.LOG'));
$this->assertEqual($conf->get('PMO_MyDbms.LOG_FORMAT'), 'd/m/Y H:m');
$this->assertEqual($conf->get('PMO_MyObject.CLASSPATH'), '/my/new/classpath');
$this->assertEqual($conf->get('PMO_MyObject.CLASS_FILENAME_PREFIX'), 'myFilePrefix_');
$this->assertTrue($conf->get('PMO_MyTable.CLASS_WRITE_ON_DISK'));
$this->assertEqual($conf->get('PMO_MyTable.CLASSPATH'), 'my/pmo_classpath');
$this->assertEqual($conf->get('PMO_MyTable.CLASS_FILENAME_PREFIX'), 'MyFile_');
$this->assertTrue($conf->get('PMO_MyMemCache.ACTIVE'));
$this->assertEqual($conf->get('PMO_MyMemCache.HOST'), 'memhost');
$this->assertEqual($conf->get('PMO_MyMemCache.PORT'), '3535');
$this->assertEqual($conf->get('PMO_MyMemCache.TIMEOUT'), 45);
if (isset ($_GET['level']))
$test = new TestSuite('PMO_MyConfig Test');
$test->run(new PMO_HTMLReporter($level));
|