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

Source for file PMO_MyTest.php

Documentation is available at PMO_MyTest.php

  1. <?php
  2. /**
  3.  * This file contains the PMO_MyTest basic class
  4.  *
  5.  * This file is part of the PhpMyObject project,
  6.  * an Object-Relational Mapping (ORM) system.
  7.  * 
  8.  * For questions, help, comments, discussion, etc., please join our
  9.  * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770}
  10.  * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
  11.  *
  12.  * PhpMyObject is free software: you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation, either version 3 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
  24.  *
  25.  * @package            PhpMyObject
  26.  * @subpackage        PMO_Tests
  27.  * @author            Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  28.  * @author            Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  29.  * @link                http://pmo.developpez.com/
  30.  * @since            PhpMyObject v0.15
  31.  * @version            $Revision: 404 $
  32.  * @copyright        Copyright (C) 2007-2008 Nicolas Boiteux
  33.  * @license            GPLv3 {@link http://www.gnu.org/licenses/gpl}
  34.  * @filesource
  35.  *
  36.  */ 
  37.  
  38. /**
  39.  * we need this class to provide some general setUp and tearDown
  40.  * plus some helper methods.
  41.  *
  42.  * Unfortunately, we can't make this an abstract class since it
  43.  * has to extends the UnitTestCase class.
  44.  *
  45.  * @package            PhpMyObject
  46.  * @subpackage        PMO_Tests
  47.  */
  48. class PMO_MyTest extends UnitTestCase
  49. {
  50.  
  51.     public function __construct({
  52.         parent::UnitTestCase();
  53.         $this->setData();
  54.     }
  55.  
  56.     function setUp({
  57.         include (dirname(__FILE__).'/your_config.php');
  58.         PMO_MyDbms::killInstance();
  59.       }
  60.  
  61.     function tearDown(}
  62.  
  63.     /**
  64.      * destroys and recretes the sqlite table actor
  65.      */
  66.     protected function resetSqliteActor({
  67.         $ctrl new PMO_MyController;
  68.         foreach ($this->drops as $drop{
  69.             $ctrl->rawquery($drop);
  70.         }
  71.         foreach ($this->creates as $create{
  72.             $ctrl->rawquery($create);
  73.         }
  74.         foreach($this->inserts as $insert{
  75.             $ctrl->rawquery($insert);
  76.         }
  77.     }
  78.  
  79.     /**
  80.      * loads the sql to drop and recreate the sqlite actor tab,e
  81.      */
  82.     protected function setData({
  83.         include(realpath(dirname(__FILE__).'/../__db/pmo_test_data.php'));
  84.  
  85.         $this->creates $creates;
  86.         $this->drops     $drops;
  87.         $this->deletes $deletes;
  88.         $this->inserts $inserts;
  89.     }
  90.  
  91.     /**
  92.      * this is used to set a database for inserts/updates/deletes
  93.      * we want to keep sakila pristine so we know in advance
  94.      * what data we have
  95.      *
  96.      * @param string $type         mysql|sqlite
  97.      * @param string $base         database to use, sakila or pmo_test
  98.      */
  99.     protected function setConfig($type$base='sakila'{
  100.  
  101.         if ($type == 'mysql'{
  102.             $config PMO_MyConfig::factory();
  103.             $config->set('PMO_MyDbms.DRIVER','mysql');
  104.             $config->set('PMO_MyDbms.PDODRIVER''');
  105.             $config->set('PMO_MyDbms.HOST','localhost');
  106.             $config->set('PMO_MyDbms.USER','pmo');
  107.             $config->set('PMO_MyDbms.PASS','pmo');
  108.             $config->set('PMO_MyDbms.BASE',$base);
  109.             $config->set('PMO_MyDbms.DSN','');
  110.         }
  111.         elseif ($type == 'sqlite'{
  112.             $config PMO_MyConfig::factory();
  113.             $config->set('PMO_MyDbms.DRIVER','pdo');
  114.             $config->set('PMO_MyDbms.PDODRIVER''sqlite');
  115.             $config->set('PMO_MyDbms.HOST','');
  116.             $config->set('PMO_MyDbms.USER','');
  117.             $config->set('PMO_MyDbms.PASS','');
  118.             $config->set('PMO_MyDbms.BASE','');
  119.             $config->set('PMO_MyDbms.DSN''sqlite:'.realpath(dirname(__FILE__).'/../__db/').'pmo_test.db'
  120.             );
  121.         }
  122.     }
  123. }

Documentation generated on Wed, 15 Oct 2008 09:17:57 -0400 by phpDocumentor 1.4.1