[Argil-svn] SF.net SVN: argil: [527] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-05-25 18:44:25
|
Revision: 527
http://argil.svn.sourceforge.net/argil/?rev=527&view=rev
Author: tswicegood
Date: 2007-05-25 11:44:04 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in Annotation Value object and tests
Modified Paths:
--------------
branches/experimental/src/Argil/Util/Annotation/Value.php
Added Paths:
-----------
branches/experimental/src/Argil/Util/Annotation/Value/
branches/experimental/src/Argil/Util/Annotation/Value/Exception.php
branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Value/Exception.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Value/Exception.php 2007-05-25 18:44:04 UTC (rev 527)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_Annotation_Value_Exception extends Exception
+{
+
+}
\ No newline at end of file
Modified: branches/experimental/src/Argil/Util/Annotation/Value.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 00:44:02 UTC (rev 526)
+++ branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 18:44:04 UTC (rev 527)
@@ -1,6 +1,35 @@
<?php
+require_once 'Argil/Util/Annotation/Value/Exception.php';
+
class Argil_Util_Annotation_Value
{
+ private $_name = null;
+ private $_params = array();
+ public function __construct($name, $params = array())
+ {
+ if (!is_string($name)) {
+ throw new Argil_Util_Annotation_Value_Exception(
+ 'non-string provided for name at construct'
+ );
+ }
+ $this->_name = $name;
+ $this->_params = $params;
+ }
+
+ public function __get($key)
+ {
+ switch ($key) {
+ case 'name':
+ case 'params':
+ $real_key = "_{$key}";
+ return $this->$real_key;
+ }
+ }
+
+ public function __set($key, $value)
+ {
+ throw new Argil_Util_Annotation_Value_Exception();
+ }
}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ValueTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/ValueTest.php 2007-05-25 18:44:04 UTC (rev 527)
@@ -0,0 +1,74 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Value.php';
+
+class Argil_Util_Annotation_ValueTest extends UnitTestCase
+{
+ public function testHasReadOnlyNamePropertyWhichIsSetAsFirstParameterOfConstructor()
+ {
+ $value = new Argil_Util_Annotation_Value('is');
+ $this->assertEqual('is', $value->name);
+
+ try {
+ $value->name = 'something else';
+ $this->fail('Exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ }
+ }
+
+ public function testHasReadOnlyParamsArrayPropertyAsSecondParameter()
+ {
+ $value = new Argil_Util_Annotation_Value('is', array());
+ $this->assertEqual(array(), $value->params);
+ unset($value);
+
+ $array = array('Hello World', 'random' => rand(10, 20));
+ $value = new Argil_Util_Annotation_Value('is', $array);
+ $this->assertEqual($array, $value->params);
+ }
+
+ public function testThrowsExceptionOnNoneStringFirstParameter()
+ {
+ try {
+ new Argil_Util_Annotation_Value(1);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value(array());
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value(123.321);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value(true);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value($this);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|