Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaAgentUtils_Test
  • AlphaConfig_Test
  • AlphaController_Test
  • AlphaDAO_Test
  • AlphaDAOProviderFactory_Test
  • AlphaFeed_Test
  • AlphaFilters_Test
  • AlphaValidator_Test
  • AlphaView_Test
  • Boolean_Test
  • Date_Test
  • DEnum_Test
  • Double_Test
  • Enum_Test
  • Exceptions_Test
  • FrontController_Test
  • Image_Test
  • Integer_Test
  • Relation_Test
  • RelationLookup_Test
  • Sequence_Test
  • String_Test
  • Tag_Test
  • Text_Test
  • Timestamp_Test
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * Test cases for the Sequence data type
  6:  * 
  7:  * @package alpha::tests
  8:  * @since 1.0
  9:  * @author John Collins <dev@alphaframework.org>
 10:  * @version $Id: Sequence_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 Sequence_Test extends PHPUnit_Framework_TestCase {
 49:     /**
 50:      * a Sequence for testing
 51:      * 
 52:      * @var Sequence
 53:      * @since 1.0
 54:      */
 55:     private $sequence;
 56:     
 57:     /**
 58:      * Called before the test functions will be executed
 59:      * this function is defined in PHPUnit_TestCase and overwritten
 60:      * here
 61:      * 
 62:      * @since 1.0
 63:      */
 64:     protected function setUp() {        
 65:         $this->sequence = new Sequence();
 66:         $this->sequence->rebuildTable();
 67:         $this->sequence->set('prefix', 'TEST');
 68:         $this->sequence->set('sequence', 1);
 69:         $this->sequence->save();
 70:     }
 71:     
 72:     /** 
 73:      * Called after the test functions are executed
 74:      * this function is defined in PHPUnit_TestCase and overwritten
 75:      * here
 76:      * 
 77:      * @since 1.0
 78:      */    
 79:     protected function tearDown() {
 80:         $this->sequence->dropTable();
 81:         unset($this->sequence);
 82:     }
 83:     
 84:     /**
 85:      * Testing to ensure that a bad parameter will cause an IllegalArguementException
 86:      * 
 87:      * @since 1.0
 88:      */
 89:     public function testSetValueBad() {
 90:         try {
 91:             $this->sequence->setValue('invalid');
 92:             $this->fail('Testing to ensure that a bad parameter will cause an IllegalArguementException');
 93:         }catch (IllegalArguementException $e) {
 94:             $this->assertEquals($this->sequence->getHelper(), $e->getMessage(), 'Testing to ensure that a bad parameter will cause an IllegalArguementException');
 95:         }
 96:     }
 97:     
 98:     /**
 99:      * Testing to ensure that a good parameter will not cause an IllegalArguementException
100:      * 
101:      * @since 1.0
102:      */
103:     public function testSetValueGood() {
104:         try {
105:             $this->sequence->setValue('VALID-1');
106:             $this->assertEquals('VALID', $this->sequence->get('prefix'), 'Testing to ensure that a good parameter will not cause an IllegalArguementException');
107:             $this->assertEquals(1, $this->sequence->get('sequence'), 'Testing to ensure that a good parameter will not cause an IllegalArguementException');
108:         }catch (IllegalArguementException $e) {
109:             $this->fail('Testing to ensure that a good parameter will not cause an IllegalArguementException');
110:         }
111:     }
112:     
113:     /**
114:      * Testing that sequence prefixes are uppercase
115:      * 
116:      * @since 1.0
117:      */
118:     public function testPrefixValidation() {
119:         try {
120:             $this->sequence->set('prefix', 'bad');
121:         }catch (IllegalArguementException $e) {
122:             $this->assertEquals($this->sequence->getPropObject('prefix')->getHelper(), $e->getMessage(), 'Testing that sequence prefixes are uppercase');
123:         }
124:     }
125:     
126:     /**
127:      * Testing the setSequenceToNext methid increments the sequence number
128:      * 
129:      * @since 1.0
130:      */
131:     public function testSetSequenceToNext() {
132:         $this->sequence->setSequenceToNext();
133:         
134:         $this->assertEquals('TEST-2', $this->sequence->getValue(), 'Testing the setSequenceToNext methid increments the sequence number');
135:     }
136:     
137:     /**
138:      * Testing the toString method
139:      * 
140:      * @since 1.0
141:      */
142:     public function testToString() {
143:         $this->assertEquals('TEST-1', $this->sequence->__toString(), 'Testing the toString method');
144:     }
145: }
Alpha Framework ${alpha.version.new} API Documentation API documentation generated by ApiGen 2.8.0