3 // Copyright (c) 2011 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite
\test
;
18 use \hoplite
\base
as base
;
20 require_once HOPLITE_ROOT
. '/base/struct.php';
22 class TestStruct
extends base\Struct
24 protected $fields = array(
31 class StructTest
extends \PHPUnit_Framework_TestCase
35 public function setUp()
37 $this->struct
= new TestStruct();
40 public function testCount()
42 $this->assertEquals(3, $this->struct
->Count());
43 $this->struct
->first
= 'foo';
44 $this->assertEquals(3, $this->struct
->Count());
47 public function testSet()
49 $this->struct
->first
= 1;
50 $this->struct
->second
= 2;
51 $this->struct
->third
= 3;
54 public function testSetInvalid()
56 $this->setExpectedException('hoplite\base\StructException');
57 $this->struct
->fourth
= 4;
60 public function testGetNull()
62 $this->assertNull($this->struct
->first
);
63 $this->assertNull($this->struct
->second
);
64 $this->assertNull($this->struct
->third
);
67 public function testGet()
69 $this->struct
->first
= 1;
70 $this->assertEquals(1, $this->struct
->first
);
73 public function testGetInvalid()
75 $this->setExpectedException('hoplite\base\StructException');
76 $foo = $this->struct
->fourth
;
79 public function testSetFromArray()
86 $this->struct
->SetFrom($array);
87 $this->assertEquals(1, $this->struct
->first
);
88 $this->assertEquals(2, $this->struct
->second
);
89 $this->assertNull($this->struct
->third
);
90 $this->assertEquals(3, $this->struct
->Count());
93 public function testSetFromObject()
95 $obj = new \
StdClass();
99 $this->struct
->SetFrom($obj);
100 $this->assertEquals(1, $this->struct
->first
);
101 $this->assertEquals(2, $this->struct
->second
);
102 $this->assertNull($this->struct
->third
);
103 $this->assertEquals(3, $this->struct
->Count());
106 public function testToArray()
108 $this->struct
->first
= 'alpha';
109 $this->struct
->third
= 'bravo';
114 $this->assertEquals($array, $this->struct
->ToArray());