1: <?php
2:
3: /**
4: *
5: * Test case for the Boolean data type
6: *
7: * @package alpha::tests
8: * @since 1.0
9: * @author John Collins <dev@alphaframework.org>
10: * @version $Id: Boolean_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 Boolean_Test extends PHPUnit_Framework_TestCase {
49: /**
50: * An Boolean for testing
51: *
52: * @var Boolean
53: * @since 1.0
54: */
55: private $boolean;
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->boolean = new Boolean();
66: }
67:
68: /**
69: * Called after the test functions are executed
70: * this function is defined in PHPUnit_TestCase and overwritten
71: * here
72: *
73: * @since 1.0
74: */
75: protected function tearDown() {
76: unset($this->boolean);
77: }
78:
79: /**
80: * Testing the constructor has set the Boolean to true by default
81: *
82: * @since 1.0
83: */
84: public function testDefaultBooleanValue() {
85: $this->assertTrue($this->boolean->getBooleanValue(), "testing the constructor has set the Boolean to true by default");
86: $this->assertEquals($this->boolean->getValue(), 1, "testing the constructor has set the Boolean to true by default");
87: }
88:
89: /**
90: * Testing the constructor default can be overridden
91: *
92: * @since 1.0
93: */
94: public function testOverrideDefaultBooleanValue() {
95: $this->boolean = new Boolean(false);
96:
97: $this->assertFalse($this->boolean->getBooleanValue(), "testing the constructor default can be overridden");
98: $this->assertEquals($this->boolean->getValue(), 0, "testing the constructor default can be overridden");
99: }
100:
101: /**
102: * Testing passing invalid data to the constructor
103: *
104: * @since 1.0
105: */
106: public function testConstructorInvalid() {
107: try {
108: $this->boolean = new Boolean(7);
109: $this->boolean = new Boolean('abc');
110: $this->fail("testing passing invalid data to the constructor");
111: }catch (IllegalArguementException $e) {
112: $this->assertTrue(true, "testing passing invalid data to the constructor");
113: }
114: }
115:
116: /**
117: * Testing passing valid data to setValue
118: *
119: * @since 1.0
120: */
121: public function testSetValueValid() {
122: $this->boolean->setValue(true);
123:
124: $this->assertTrue($this->boolean->getBooleanValue(), "testing passing valid data to setValue");
125: $this->assertEquals($this->boolean->getValue(), 1, "testing passing valid data to setValue");
126: }
127:
128: /**
129: * Testing passing invalid data to setValue
130: *
131: * @since 1.0
132: */
133: public function testSetValueInvalid() {
134: try {
135: $this->boolean->setValue(3);
136: $this->fail("testing passing invalid data to setValue");
137: }catch (IllegalArguementException $e) {
138: $this->assertTrue(true, "testing passing invalid data to setValue");
139: }
140: }
141:
142: /**
143: * Testing the toString method
144: *
145: * @since 1.0
146: */
147: public function testToString() {
148: $this->assertEquals('true', $this->boolean->__toString(), 'Testing the toString method');
149: }
150: }
151:
152: ?>