PhpMyObject
[ class tree: PhpMyObject ] [ index: PhpMyObject ] [ all elements ]

Source for file PMO_MyConfig_Test.php

Documentation is available at PMO_MyConfig_Test.php

  1. <?php
  2. /**
  3.  *
  4.  * This file is part of the PhpMyObject project,
  5.  * an Object-Relational Mapping (ORM) system.
  6.  * 
  7.  * For questions, help, comments, discussion, etc., please join our
  8.  * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770}
  9.  * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
  10.  *
  11.  * PhpMyProject is free software: you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation, either version 3 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
  23.  *
  24.  * @package            PhpMyObject
  25.  * @subpackage     PMO_Tests
  26.  * @author            Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  27.  * @author            Louis Lapointe <laplix@gmail.com>
  28.  * @link                http://pmo.developpez.com/
  29.  * @since            PhpMyObject v0.15
  30.  * @version            $Revision: 400 $
  31.  * @copyright        Copyright (c) 2007-2008 Nicolas Boiteux
  32.  * @copyright        Copyright (c) 2008 Louis Lapointe
  33.  * @license            GPLv3 {@link http://www.gnu.org/licenses/gpl}
  34.  * @filesource
  35.  */
  36.  
  37. /**
  38.  * setup this test case if called individually
  39.  */
  40. if (!defined('PMO_TEST_SUITE')) {
  41.     require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config.php');
  42.     require_once(SIMPLETEST.DS.'autorun.php');
  43. }
  44.  
  45. /**
  46.  * requires PMO_MyConfig
  47.  */
  48. require_once(PMO_CORE.DS.'PMO_MyConfig.php');
  49.  
  50. /**
  51.  * This tests the PMO_MyConfig class.
  52.  */
  53. class PMO_MyConfig_Test extends UnitTestCase 
  54. {
  55.     /** constructor calls parent contructor. */
  56.     function PMO_MyConfig_Test()
  57.     {
  58.         $this->UnitTestCase();
  59.     }
  60.  
  61.     /** called before each test */
  62.     function setUp({
  63.     }
  64.  
  65.     /**
  66.      * called after each test
  67.      * @todo will probably need this later to reset the config or something
  68.      */
  69.     function tearDown(}
  70.  
  71.     /**********
  72.      * exists has been deprecated
  73.     function test_exist_empty_var_name()
  74.     {
  75.         $conf = PMO_MyConfig::factory();
  76.         try {
  77.             $conf->exists('');
  78.             $this->fail('PMO_MyConfig::exists("") should have thrown an exception.');
  79.         }
  80.         catch(Exception $e) {
  81.             $this->assertEqual($e->getMessage(), 'Error: Empty parameter',
  82.                 'Asking if an empty varname exists throws an exception');
  83.         }
  84.     }
  85.     ****************/
  86.  
  87.     /**
  88.      * this make sure we get an exception if we don't provide a parameter
  89.      * just to make sure ;)
  90.      */
  91.     function test_set_empty_var_name()
  92.     {
  93.         $conf PMO_MyConfig::factory();
  94.         // empty args
  95.         try {
  96.             $conf->set('','');
  97.             $this->fail('PMO_MyConfig::set("") should have thrown an exception.');
  98.         }
  99.         catch (Exception $e{
  100.             //echo "<pre>".str_replace(' ','.',$e->getMessage())."</pre><br>";
  101.             $this->assertEqual($e->getMessage(),
  102.                 sprintf("Error: Parameter %s doesn't exist",''),
  103.                 'Writing to an empty varname throws an exception');
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * this make sure PMO_MyConfig will throw an exception if we try
  109.      * to get an unsuported var.
  110.      */
  111.     function test_get_empty_var_name()
  112.     {
  113.         $conf PMO_MyConfig::factory();
  114.         try {
  115.             $conf->get('');
  116.             $this->fail('PMO_MyConfig::get("") should have thrown an excepyion.');
  117.         }
  118.         catch (Exception $e{
  119.             $this->assertEqual($e->getMessage(),
  120.                 sprintf("Error: Parameter %s doesn't exist",''),
  121.                 "Reading an empty varname throws an exception");
  122.         }
  123.     }
  124.  
  125.     /**
  126.      * this make sure PMO_MyConfig will throw an exception if we try
  127.      * to set an unsuported var.
  128.      */
  129.     function test_set_unsupported_var()
  130.     {
  131.         $conf PMO_MyConfig::factory();
  132.         try {
  133.             $conf->set('MyVar''I exist');
  134.             $this->fail('PMO_MyConfig::set("MyVar") should have thrown an exception');
  135.         }
  136.         catch(Exception $e{
  137.             $this->assertEqual($e->getMessage()
  138.                 sprintf("Error: Parameter %s doesn't exist",'MyVar'),
  139.                 "Writing to a non-existant var throws an exception");
  140.         }
  141.     }
  142.  
  143.     /**
  144.      * this make sure PMO_MyConfig will throw an exception of we ask
  145.      * for an unsuported var.
  146.      */
  147.     function test_get_unsupported_var()
  148.     {
  149.         $conf PMO_MyConfig::factory();
  150.         try {
  151.             $myvar $conf->get('MyVar');
  152.             $this->fail('PMO_MyConfig::get("MyVar") should have thrown an exception');
  153.         }
  154.         catch(Exception $e{
  155.             $this->assertEqual($e->getMessage()
  156.                 sprintf("Error: Parameter %s doesn't exist",'MyVar'),
  157.                 "Writing to a unknown var throws an exception");
  158.         }
  159.     }
  160.  
  161.     /**
  162.      * this will test that all PMO standard vars exist.
  163.      */
  164.     /***********************************
  165.      * la fonction exists() a été dépréciée
  166.     function test_exists_PMO_standard_vars()
  167.     {
  168.         $conf = PMO_MyConfig::factory();
  169.  
  170.         $this->assertTrue($conf->exists('PMO_MyController.OBJECT_COLLECTOR_NAME'), 'PMO_MyController.OBJECT_COLLECTOR_NAME exists');
  171.         $this->assertTrue($conf->exists('PMO_MyDbms.DRIVER'),        '"PMO_MyDbms.DRIVER" exists');
  172.         $this->assertTrue($conf->exists('PMO_MyDbms.PDODRIVER'), '"PMO_MyDbms.PDODRIVER" exists');
  173.         $this->assertTrue($conf->exists('PMO_MyDbms.HOST'),        '"PMO_MyDbms.HOST" exists.');
  174.         $this->assertTrue($conf->exists('PMO_MyDbms.BASE'),        '"PMO_MyDbms.BASE" exists.');
  175.         $this->assertTrue($conf->exists('PMO_MyDbms.USER'),        '"PMO_MyDbms.USER" exists.');
  176.         $this->assertTrue($conf->exists('PMO_MyDbms.PASS'),        '"PMO_MyDbms.PASS" exists.');
  177.         $this->assertTrue($conf->exists('PMO_MyDbms.DSN'),            '"PMO_MyDbms.DSN" exists.');
  178.         $this->assertTrue($conf->exists('PMO_MyDbms.LOG'),            '"PMO_MyDbms.LOG" exists.');
  179.         $this->assertTrue($conf->exists('PMO_MyDbms.LOG_FORMAT'), '"PMO_MyDbms.LOG_FORMAT" exists.');
  180.  
  181.         $path = realpath($conf->get('PMO_MyObject.CLASSPATH'));
  182.         $expected = realpath(PMO_ROOT.DS.'class_loader'.DS);
  183.         $this->assertTrue($conf->exists('PMO_MyObject.CLASSPATH'), '"PMO_MyObject.CLASSPATH" exists.');
  184.  
  185.         $this->assertTrue($conf->exists('PMO_MyTable.CLASS_WRITE_ON_DISK'),        '"PMO_MyTable.CLASS_WRITE_ON_DISK" exists.');
  186.         $this->assertTrue($conf->exists('PMO_MyTable.CLASS_FILENAME_PREFIX'),    '"PMO_MyTable.CLASS_FILENAME_PREFIX" exists.');
  187.         $path = realpath($conf->get('PMO_MyTable.CLASSPATH'));
  188.         $expected = realpath(PMO_CORE.DS.'PMO_MyTable'.DS);
  189.         $this->assertTrue($conf->exists('PMO_MyTable.CLASSPATH'), '"PMO_MyTable.CLASSPATH" exists.');
  190.  
  191.         $this->assertTrue($conf->exists('PMO_MyMemCache.ACTIVE'),    '"PMO_MyMemCache.ACTIVE" exists.');
  192.         $this->assertTrue($conf->exists('PMO_MyMemCache.HOST'),        '"PMO_MyMemCache.HOST" exists.');
  193.         $this->assertTrue($conf->exists('PMO_MyMemCache.PORT'),        '"PMO_MyMemCache.PORT" exists.');
  194.         $this->assertTrue($conf->exists('PMO_MyMemCache.TIMEOUT'),    '"PMO_MyMemCache.TIMEOUT" exists.');
  195.     }
  196.     *******************************/
  197.     
  198.     /**
  199.      * this tests that all PMO standard vars are correcly initialized
  200.      */
  201.     function test_MyConfig_default_values({
  202.         $conf PMO_MyConfig::factory();
  203.  
  204.         $this->assertEqual($conf->get('PMO_MyController.OBJECT_COLLECTOR_NAME')'collector');
  205.         $this->assertEqual($conf->get('PMO_MyDbms.DRIVER')'');
  206.         $this->assertEqual($conf->get('PMO_MyDbms.PDODRIVER')'');
  207.         $this->assertEqual($conf->get('PMO_MyDbms.HOST')'');
  208.         $this->assertEqual($conf->get('PMO_MyDbms.BASE')'');
  209.         $this->assertEqual($conf->get('PMO_MyDbms.USER')'');
  210.         $this->assertEqual($conf->get('PMO_MyDbms.PASS')'');
  211.         $this->assertEqual($conf->get('PMO_MyDbms.DSN')'');
  212.         $this->assertFalse($conf->get('PMO_MyDbms.LOG'));
  213.         $this->assertEqual($conf->get('PMO_MyDbms.LOG_FORMAT')'Y-m-d H:i:s');
  214.  
  215.         $path realpath($conf->get('PMO_MyObject.CLASSPATH'));
  216.         $expected realpath(PMO_ROOT.DS.'class_loader'.DS);
  217.         $this->assertEqual($path$expected);
  218.  
  219.         $this->assertEqual($conf->get('PMO_MyObject.CLASS_FILENAME_PREFIX')'class_');
  220.         $this->assertFalse($conf->get('PMO_MyMemCache.ACTIVE'));
  221.         $this->assertEqual($conf->get('PMO_MyMemCache.HOST')'');
  222.         $this->assertEqual($conf->get('PMO_MyMemCache.PORT')'');
  223.         $this->assertEqual($conf->get('PMO_MyMemCache.TIMEOUT')'10');
  224.  
  225.         $path realpath($conf->get('PMO_MyTable.CLASSPATH'));
  226.         $expected realpath(PMO_CORE.DS.'PMO_MyTable'.DS);
  227.         $this->assertEqual($path$expected);
  228.  
  229.         $this->assertEqual($conf->get('PMO_MyTable.CLASS_FILENAME_PREFIX')'PMO_MyTable_');
  230.         $this->assertFalse($conf->get('PMO_MyTable.CLASS_WRITE_ON_DISK'));
  231.     }
  232.  
  233.     function test_setup_MyConfig({
  234.         $conf PMO_MyConfig::factory();
  235.         $conf->set('PMO_MyDbms.DRIVER''pdo');
  236.         $conf->set('PMO_MyDbms.PDODRIVER''sqlite');
  237.         $conf->set('PMO_MyDbms.HOST''myHost');
  238.         $conf->set('PMO_MyDbms.USER''myUser');
  239.         $conf->set('PMO_MyDbms.PASS''myPass');
  240.         $conf->set('PMO_MyDbms.DSN',    'sqlite:/my/data/base.db');
  241.         $conf->set('PMO_MyDbms.LOG'TRUE);
  242.         $conf->set('PMO_MyDbms.LOG_FORMAT''d/m/Y H:m');
  243.         $conf->set('PMO_MyObject.CLASSPATH''/my/new/classpath');
  244.         $conf->set('PMO_MyObject.CLASS_FILENAME_PREFIX''myFilePrefix_');
  245.         $conf->set('PMO_MyTable.CLASS_WRITE_ON_DISK'TRUE);
  246.         $conf->set('PMO_MyTable.CLASSPATH''my/pmo_classpath');
  247.         $conf->set('PMO_MyTable.CLASS_FILENAME_PREFIX''MyFile_');
  248.         $conf->set('PMO_MyMemCache.ACTIVE'TRUE);
  249.         $conf->set('PMO_MyMemCache.HOST''memhost');
  250.         $conf->set('PMO_MyMemCache.PORT''3535');
  251.         $conf->set('PMO_MyMemCache.TIMEOUT'45);
  252.  
  253.  
  254.         $this->assertEqual($conf->get('PMO_MyDbms.DRIVER')'pdo');
  255.         $this->assertEqual($conf->get('PMO_MyDbms.PDODRIVER')'sqlite');
  256.         $this->assertEqual($conf->get('PMO_MyDbms.HOST')'myHost');
  257.         $this->assertEqual($conf->get('PMO_MyDbms.USER')'myUser');
  258.         $this->assertEqual($conf->get('PMO_MyDbms.PASS')'myPass');
  259.         $this->assertEqual($conf->get('PMO_MyDbms.DSN')'sqlite:/my/data/base.db');
  260.         $this->assertTrue($conf->get('PMO_MyDbms.LOG'));
  261.         $this->assertEqual($conf->get('PMO_MyDbms.LOG_FORMAT')'d/m/Y H:m');
  262.         $this->assertEqual($conf->get('PMO_MyObject.CLASSPATH')'/my/new/classpath');
  263.         $this->assertEqual($conf->get('PMO_MyObject.CLASS_FILENAME_PREFIX')'myFilePrefix_');
  264.         $this->assertTrue($conf->get('PMO_MyTable.CLASS_WRITE_ON_DISK'));
  265.         $this->assertEqual($conf->get('PMO_MyTable.CLASSPATH')'my/pmo_classpath');
  266.         $this->assertEqual($conf->get('PMO_MyTable.CLASS_FILENAME_PREFIX')'MyFile_');
  267.         $this->assertTrue($conf->get('PMO_MyMemCache.ACTIVE'));
  268.         $this->assertEqual($conf->get('PMO_MyMemCache.HOST')'memhost');
  269.         $this->assertEqual($conf->get('PMO_MyMemCache.PORT')'3535');
  270.         $this->assertEqual($conf->get('PMO_MyMemCache.TIMEOUT')45);
  271.     }
  272.  
  273.  
  274. }
  275.  
  276. if (!defined('PMO_TEST_SUITE')) {
  277.     $level '';
  278.     if (isset($_GET['level']))
  279.         $level $_GET['level'];
  280.  
  281.     $test new TestSuite('PMO_MyConfig Test');
  282.     $test->add(new PMO_MyConfig_Test);
  283.     $test->run(new PMO_HTMLReporter($level));
  284. }

Documentation generated on Wed, 15 Oct 2008 09:16:55 -0400 by phpDocumentor 1.4.1