      1: <?php
      2:
      3: /**
      4:  *
      5:  * Test cases for the AlphaConfig class
      6:  *
      7:  * @package alpha::tests
      8:  * @since 1.0
      9:  * @author John Collins <dev@alphaframework.org>
     10:  * @version $Id: AlphaConfig_Test.php 1496 2012-02-12 20:32:21Z alphadev $
     11:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     12:  * @copyright Copyright (c) 2012, John Collins (founder of Alpha Framework).
     13:  * All rights reserved.
     14:  *
     15:  * <pre>
     16:  * Redistribution and use in source and binary forms, with or
     17:  * without modification, are permitted provided that the
     18:  * following conditions are met:
     19:  *
     20:  * * Redistributions of source code must retain the above
     21:  *   copyright notice, this list of conditions and the
     22:  *   following disclaimer.
     23:  * * Redistributions in binary form must reproduce the above
     24:  *   copyright notice, this list of conditions and the
     25:  *   following disclaimer in the documentation and/or other
     26:  *   materials provided with the distribution.
     27:  * * Neither the name of the Alpha Framework nor the names
     28:  *   of its contributors may be used to endorse or promote
     29:  *   products derived from this software without specific
     30:  *   prior written permission.
     31:  *
     32:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     33:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     34:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     35:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     36:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     37:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     38:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     39:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     40:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     41:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     42:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     43:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     44:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     45:  * </pre>
     46:  *
     47:  */
     48: class AlphaConfig_Test extends PHPUnit_Framework_TestCase {
     49:     /**
     50:      * A copy of the global config singleton that we will use for testing
     51:      *
     52:      * @var AlphaConfig
     53:      */
     54:     private $configCopy;
     55:
     56:     /**
     57:      * Called before the test functions will be executed
     58:      * this function is defined in PHPUnit_TestCase and overwritten
     59:      * here
     60:      *
     61:      * @since 1.0
     62:      */
     63:     protected function setUp() {
     64:         global $config;
     65:
     66:         $this->configCopy = clone $config;
     67:     }
     68:
     69:     /**
     70:      * Called after the test functions are executed
     71:      * this function is defined in PHPUnit_TestCase and overwritten
     72:      * here
     73:      *
     74:      * @since 1.0
     75:      */
     76:     protected function tearDown() {
     77:         unset($this->configCopy);
     78:     }
     79:
     80:     /**
     81:      * Testing that the AlphaConfig getInstance method is returning the same instance object each time
     82:      *
     83:      * @since 1.0
     84:      */
     85:     public function testGetInstance() {
     86:         $config1 = AlphaConfig::getInstance();
     87:         $config2 = AlphaConfig::getInstance();
     88:
     89:         $config1->set('testkey', 'somevalue');
     90:
     91:         $this->assertEquals('somevalue', $config2->get('testkey'), 'testing that the AlphaConfig getInstance method is returning the same instance object each time');
     92:     }
     93:
     94:     /**
     95:      * Testing that attempting to access a config value that is not set will cause an exception
     96:      *
     97:      * @since 1.0
     98:      */
     99:     public function testGetBad() {
    100:         try {
    101:             $this->configCopy->get('keyDoesNotExist');
    102:             $this->fail('Testing that attempting to access a config value that is not set will cause an exception');
    103:         }catch (IllegalArguementException $e) {
    104:             $this->assertEquals('The config property [keyDoesNotExist] is not set in the .ini config file', $e->getMessage(), 'Testing that attempting to access a config value that is not set will cause an exception');
    105:         }
    106:     }
    107: }
    108:
    109: ?>