Thread: [Argil-svn] SF.net SVN: argil: [504] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-03-21 16:27:13
|
Revision: 504
http://argil.svn.sourceforge.net/argil/?rev=504&view=rev
Author: tswicegood
Date: 2007-03-21 09:27:06 -0700 (Wed, 21 Mar 2007)
Log Message:
-----------
Add in a Model_Container object
Added Paths:
-----------
branches/experimental/src/Argil/Model/
branches/experimental/src/Argil/Model/Container.php
branches/experimental/tests/Argil/Model/
branches/experimental/tests/Argil/Model/ContainerTest.php
Added: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php (rev 0)
+++ branches/experimental/src/Argil/Model/Container.php 2007-03-21 16:27:06 UTC (rev 504)
@@ -0,0 +1,40 @@
+<?php
+
+class Argil_Model_Container
+{
+ private $_contained = array();
+
+ public function __construct() {
+ if (func_num_args() > 0) {
+ foreach (func_get_args() as $object) {
+ $this->_contained[get_class($object)] = $object;
+ }
+ }
+ }
+
+ public function is($name) {
+ return isset($this->_contained[$name]);
+ }
+
+ public function __set($key, $value) {
+ foreach ($this->_contained as $object) {
+ $vars = get_object_vars($object);
+ if (!isset($vars[$key])) {
+ continue;
+ }
+ $object->$key = $value;
+ return;
+ }
+
+ throw new Exception();
+ }
+
+ public function __get($key) {
+ foreach ($this->_contained as $object) {
+ $vars = get_object_vars($object);
+ if (isset($vars[$key])) {
+ return $object->$key;
+ }
+ }
+ }
+}
Added: branches/experimental/tests/Argil/Model/ContainerTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/ContainerTest.php (rev 0)
+++ branches/experimental/tests/Argil/Model/ContainerTest.php 2007-03-21 16:27:06 UTC (rev 504)
@@ -0,0 +1,49 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Model/Container.php';
+
+class ArgilSampleModel {
+ public $title = '';
+}
+class ArgilSampleModelTwo { }
+
+class Argil_Model_ContainerTest extends UnitTestCase
+{
+ public function testWillTellWhatTypeOfObjectThisContains() {
+ $container = new Argil_Model_Container(
+ new ArgilSampleModel()
+ );
+
+ $this->assertTrue($container->is('ArgilSampleModel'));
+ $this->assertFalse($container->is(__CLASS__));
+ }
+
+ public function testCanContainMultipleObjects() {
+ $container = new Argil_Model_Container(
+ new ArgilSampleModel(),
+ new ArgilSampleModelTwo()
+ );
+
+ $this->assertFalse($container->is(__CLASS__));
+ $this->assertTrue($container->is('ArgilSampleModel'));
+ $this->assertTrue($container->is('ArgilSampleModelTwo'));
+ }
+
+ public function testWillOnlyAllowSettingOfKnownProperties() {
+ $container = new Argil_Model_Container(
+ new ArgilSampleModel()
+ );
+
+ $container->title = 'Hello World';
+ $this->assertEqual($container->title, 'Hello World');
+
+ try {
+ $container->unknown = 'Throw Exception';
+ $this->fail('Exception not caught');
+ } catch (Exception $e) {
+
+ }
+ }
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-03-26 23:59:40
|
Revision: 507
http://argil.svn.sourceforge.net/argil/?rev=507&view=rev
Author: tswicegood
Date: 2007-03-26 16:59:40 -0700 (Mon, 26 Mar 2007)
Log Message:
-----------
Add in some basic wrapper to Reflection that'll be extended for annotations
Added Paths:
-----------
branches/experimental/src/Argil/Reflection/
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/src/Argil/Reflection/PropertyList.php
branches/experimental/tests/Argil/Reflection/
branches/experimental/tests/Argil/Reflection/ObjectTest.php
branches/experimental/tests/Argil/Reflection/PropertyListTest.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Added: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php (rev 0)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-03-26 23:59:40 UTC (rev 507)
@@ -0,0 +1,18 @@
+<?php
+
+class Argil_Reflection_Object
+{
+ private $_decorated = null;
+
+ public function __construct($object) {
+ assert('is_object($object)');
+ $this->_decorated = new ReflectionObject($object);
+ }
+
+ public function __call($method, $arguments) {
+ return call_user_func_array(
+ array($this->_decorated, $method),
+ $arguments
+ );
+ }
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php (rev 0)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-03-26 23:59:40 UTC (rev 507)
@@ -0,0 +1,17 @@
+<?php
+
+class Argil_Reflection_Property
+{
+ private $_decorated = null;
+
+ public function __construct(ReflectionProperty $property) {
+ $this->_decorated = $property;
+ }
+
+ public function __call($method, $arguments) {
+ return call_user_func_array(
+ array($this->_decorated, $method),
+ $arguments
+ );
+ }
+}
Added: branches/experimental/src/Argil/Reflection/PropertyList.php
===================================================================
--- branches/experimental/src/Argil/Reflection/PropertyList.php (rev 0)
+++ branches/experimental/src/Argil/Reflection/PropertyList.php 2007-03-26 23:59:40 UTC (rev 507)
@@ -0,0 +1,40 @@
+<?php
+
+require_once 'Argil/Reflection/Property.php';
+
+class Argil_Reflection_PropertyList
+ implements ArrayAccess, Countable, SeekableIterator
+{
+ private $_data = array();
+
+ public function __construct(array $propertyList) {
+ $this->_data = $propertyList;
+ }
+
+ public function offsetExists($offset) {
+ return isset($this->_data[$offset]);
+ }
+
+ public function offsetGet($offset) {
+ return new Argil_Reflection_Property($this->_data[$offset]);
+ }
+
+ public function offsetSet($offset, $value) {
+ throw new Exception();
+ }
+
+ public function offsetUnset($offset) {
+ throw new Exception();
+ }
+
+ public function count() {
+ return count($this->_data);
+ }
+
+ public function seek($index) { }
+ public function current() { }
+ public function key() { }
+ public function next() { }
+ public function rewind() { }
+ public function valid() { }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php (rev 0)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-03-26 23:59:40 UTC (rev 507)
@@ -0,0 +1,25 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Reflection/Object.php';
+
+class ArgilSampleReflectionObject {
+ public $publicProperty = '';
+ protected $protectedProperty = '';
+ private $privateProperty = '';
+}
+
+class Argil_Reflection_ObjectTest extends UnitTestCase
+{
+ public function testReturnsArrayOfProperties() {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObject()
+ );
+ $properties = $reflection->getProperties();
+
+ $this->assertTrue(is_array($properties));
+ $this->assertTrue(count($properties) == 3);
+
+ $this->assertIsA($properties[0], 'Argil_Reflection_Property');
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Reflection/PropertyListTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyListTest.php (rev 0)
+++ branches/experimental/tests/Argil/Reflection/PropertyListTest.php 2007-03-26 23:59:40 UTC (rev 507)
@@ -0,0 +1,83 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Reflection/PropertyList.php';
+
+class ArgilSampleReflectionObjectForProperties {
+ public $publicProperty = '';
+ protected $protectedProperty = '';
+ private $privateProperty = '';
+}
+
+class Argil_Reflection_PropertyListTest extends UnitTestCase {
+ public function testActsAsArray() {
+ $reflection = new ReflectionObject(
+ new ArgilSampleReflectionObjectForProperties()
+ );
+
+ $properties = new Argil_Reflection_PropertyList(
+ $reflection->getProperties()
+ );
+
+ $this->assertIsA($properties, 'Countable');
+ $this->assertIsA($properties, 'ArrayAccess');
+ $this->assertIsA($properties, 'SeekableIterator');
+
+ // sanity check for Countable
+ $this->assertEqual(3, count($properties));
+
+ // sanity check for ArrayAccess
+ $this->assertTrue(isset($properties[0]));
+ $this->assertNotNull($properties[0]);
+ }
+
+ public function testArrayIsReadOnly() {
+ $reflection = new ReflectionObject(
+ new ArgilSampleReflectionObjectForProperties()
+ );
+
+ $properties = new Argil_Reflection_PropertyList(
+ $reflection->getProperties()
+ );
+
+ try {
+ $properties['unknown'] = "Shouldn't work";
+ $this->fail('Exception not caught');
+ } catch (Exception $e) {
+ $this->pass('Exception caught');
+ }
+
+ try {
+ $this->assertTrue(isset($properties[0]));
+ $properties[0] = "Shouldn't work";
+ $this->fail('Exception not caught');
+ } catch (Exception $e) {
+ $this->pass('Exception caught');
+ }
+
+ try {
+ $this->assertTrue(isset($properties[0]));
+ unset($properties[0]);
+ $this->fail('Exception not caught');
+ } catch (Exception $e) {
+ $this->pass('Exception caught');
+ $this->assertTrue(isset($properties[0]));
+ }
+ }
+
+ public function testMapsAllValuesToArgilWrapper() {
+ $reflection = new ReflectionObject(
+ new ArgilSampleReflectionObjectForProperties()
+ );
+
+ $properties = new Argil_Reflection_PropertyList(
+ $reflection->getProperties()
+ );
+
+ // sanity check
+ $this->assertTrue(isset($properties[0]));
+ $this->assertIsA($properties[0], 'Argil_Reflection_Property');
+
+ $this->assertEqual('publicProperty', $properties[0]->getName());
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php (rev 0)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-03-26 23:59:40 UTC (rev 507)
@@ -0,0 +1,36 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Reflection/Property.php';
+
+class ArgilSamplePropertyObjectForReflection {
+ public $publicProperty;
+ protected $protectedProperty;
+ private $privateProperty;
+}
+
+class Argil_Reflection_PropertyTest extends UnitTestCase {
+ public function testWrapsReflectionPropertyObject() {
+ $reflection = new ReflectionObject(
+ new ArgilSamplePropertyObjectForReflection()
+ );
+
+ $properties = $reflection->getProperties();
+
+ $public = new Argil_Reflection_Property($properties[0]);
+ $this->assertTrue($public->isPublic());
+ $this->assertFalse($public->isProtected());
+ $this->assertFalse($public->isPrivate());
+ $this->assertEqual($public->getName(), 'publicProperty');
+
+ $protected = new Argil_Reflection_Property($properties[1]);
+ $this->assertTrue($protected->isProtected());
+ $this->assertFalse($protected->isPublic());
+ $this->assertFalse($protected->isPrivate());
+
+ $private = new Argil_Reflection_Property($properties[2]);
+ $this->assertTrue($private->isPrivate());
+ $this->assertFalse($private->isPublic());
+ $this->assertFalse($private->isProtected());
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-01 04:05:35
|
Revision: 508
http://argil.svn.sourceforge.net/argil/?rev=508&view=rev
Author: tswicegood
Date: 2007-03-31 21:05:36 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Make this actually work - not sure how it got commits
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-03-26 23:59:40 UTC (rev 507)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-04-01 04:05:36 UTC (rev 508)
@@ -1,5 +1,7 @@
<?php
+require_once 'Argil/Reflection/PropertyList.php';
+
class Argil_Reflection_Object
{
private $_decorated = null;
@@ -15,4 +17,10 @@
$arguments
);
}
+
+ public function getProperties() {
+ return new Argil_Reflection_PropertyList(
+ $this->_decorated->getProperties()
+ );
+ }
}
\ No newline at end of file
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-03-26 23:59:40 UTC (rev 507)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-04-01 04:05:36 UTC (rev 508)
@@ -17,7 +17,7 @@
);
$properties = $reflection->getProperties();
- $this->assertTrue(is_array($properties));
+ $this->assertTrue(is_array($properties) || $properties instanceof ArrayAccess);
$this->assertTrue(count($properties) == 3);
$this->assertIsA($properties[0], 'Argil_Reflection_Property');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-01 04:07:52
|
Revision: 510
http://argil.svn.sourceforge.net/argil/?rev=510&view=rev
Author: tswicegood
Date: 2007-03-31 21:07:53 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Add in a hard-coded example of using docblock parsing for validation
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:07:27 UTC (rev 509)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:07:53 UTC (rev 510)
@@ -14,4 +14,10 @@
$arguments
);
}
+
+ public function isValid($object) {
+ $name = $this->getName();
+ $len = strlen($object->$name);
+ return $len <= 10 && $len >= 5;
+ }
}
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:07:27 UTC (rev 509)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:07:53 UTC (rev 510)
@@ -4,6 +4,10 @@
require_once 'Argil/Reflection/Property.php';
class ArgilSamplePropertyObjectForReflection {
+ /**
+ * @is length <= 10
+ * @is length >= 5
+ */
public $publicProperty;
protected $protectedProperty;
private $privateProperty;
@@ -33,4 +37,24 @@
$this->assertFalse($private->isPublic());
$this->assertFalse($private->isProtected());
}
+
+ public function testUsesDocBlockToDetermineValidity() {
+ $reflection = new ReflectionObject(
+ new ArgilSamplePropertyObjectForReflection()
+ );
+
+ $properties = $reflection->getProperties();
+
+ $public = new Argil_Reflection_Property($properties[0]);
+
+ $object = new ArgilSamplePropertyObjectForReflection();
+ $object->publicProperty = '1234567890';
+ $this->assertTrue($public->isValid($object));
+
+ $object->publicProperty = '12345678901';
+ $this->assertFalse($public->isValid($object));
+
+ $object->publicProperty = '1234';
+ $this->assertFalse($public->isValid($object));
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-01 04:35:55
|
Revision: 512
http://argil.svn.sourceforge.net/argil/?rev=512&view=rev
Author: tswicegood
Date: 2007-03-31 21:35:56 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Add in the first pass at a Length Specification object
Added Paths:
-----------
branches/experimental/src/Argil/Specification/
branches/experimental/src/Argil/Specification/Length.php
branches/experimental/tests/Argil/Specification/
branches/experimental/tests/Argil/Specification/LengthTest.php
Added: branches/experimental/src/Argil/Specification/Length.php
===================================================================
--- branches/experimental/src/Argil/Specification/Length.php (rev 0)
+++ branches/experimental/src/Argil/Specification/Length.php 2007-04-01 04:35:56 UTC (rev 512)
@@ -0,0 +1,34 @@
+<?php
+
+class Argil_Specification_Length
+{
+ private
+ $_comparison,
+ $_length,
+ $_value;
+
+ public function __construct($value, $length, $comparison = '==') {
+ $this->_value = $value;
+ $this->_length = $length;
+ $this->_comparison = $comparison;
+ }
+
+ public function valid() {
+ $actualLength = strlen($this->_value);
+ switch ($this->_comparison) {
+ case '==' :
+ return $actualLength == $this->_length;
+ case '<=' :
+ return $actualLength <= $this->_length;
+ case '>=' :
+ return $actualLength >= $this->_length;
+ case '>' :
+ return $actualLength > $this->_length;
+ case '<' :
+ return $actualLength < $this->_length;
+ case '<>' :
+ case '!=' :
+ return $actualLength != $this->_length;
+ }
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Specification/LengthTest.php
===================================================================
--- branches/experimental/tests/Argil/Specification/LengthTest.php (rev 0)
+++ branches/experimental/tests/Argil/Specification/LengthTest.php 2007-04-01 04:35:56 UTC (rev 512)
@@ -0,0 +1,68 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Specification/Length.php';
+
+class Argil_Specification_LengthTest extends UnitTestCase
+{
+ public function testAllowsLengthEquals() {
+ $spec = new Argil_Specification_Length('12345', 5);
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 5);
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthLesserThanOrEquals() {
+ $spec = new Argil_Specification_Length('12345', 5, '<=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('1234', 5, '<=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 5, '<=');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthGreaterThanOrEquals() {
+ $spec = new Argil_Specification_Length('12345', 4, '>=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('1234', 4, '>=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123', 4, '>=');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthGreaterThan() {
+ $spec = new Argil_Specification_Length('12345', 4, '>');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('1234', 4, '>');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthLesserThan() {
+ $spec = new Argil_Specification_Length('12345', 6, '<');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 6, '<');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsBothNotEquals() {
+ $spec = new Argil_Specification_Length('123456', 5, '<>');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 5, '!=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('12345', 5, '<>');
+ $this->assertFalse($spec->valid());
+
+ $spec = new Argil_Specification_Length('12345', 5, '!=');
+ $this->assertFalse($spec->valid());
+ }
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-01 04:38:35
|
Revision: 513
http://argil.svn.sourceforge.net/argil/?rev=513&view=rev
Author: tswicegood
Date: 2007-03-31 21:38:34 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Add in exception handling to Length Spec
Modified Paths:
--------------
branches/experimental/src/Argil/Specification/Length.php
branches/experimental/tests/Argil/Specification/LengthTest.php
Modified: branches/experimental/src/Argil/Specification/Length.php
===================================================================
--- branches/experimental/src/Argil/Specification/Length.php 2007-04-01 04:35:56 UTC (rev 512)
+++ branches/experimental/src/Argil/Specification/Length.php 2007-04-01 04:38:34 UTC (rev 513)
@@ -30,5 +30,7 @@
case '!=' :
return $actualLength != $this->_length;
}
+
+ throw new Exception();
}
}
\ No newline at end of file
Modified: branches/experimental/tests/Argil/Specification/LengthTest.php
===================================================================
--- branches/experimental/tests/Argil/Specification/LengthTest.php 2007-04-01 04:35:56 UTC (rev 512)
+++ branches/experimental/tests/Argil/Specification/LengthTest.php 2007-04-01 04:38:34 UTC (rev 513)
@@ -65,4 +65,13 @@
$this->assertFalse($spec->valid());
}
+ public function testThrowsExceptionOnUnknownComparisonType() {
+ $spec = new Argil_Specification_Length('12345', 5, 'unknown');
+ try {
+ $spec->valid();
+ $this->fail('Exception not caught');
+ } catch (Exception $e) {
+ $this->pass('Exception caught');
+ }
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-01 04:51:44
|
Revision: 514
http://argil.svn.sourceforge.net/argil/?rev=514&view=rev
Author: tswicegood
Date: 2007-03-31 21:51:45 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Start using specification.
This still needs some work. A Specification Locator needs to be implemented so
multiple specs can be used and allow a flex point for scanning multiple places for
Specs, but this starts the code in the right direction.
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:38:34 UTC (rev 513)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:51:45 UTC (rev 514)
@@ -1,5 +1,7 @@
<?php
+require_once 'Argil/Specification/Length.php';
+
class Argil_Reflection_Property
{
private $_decorated = null;
@@ -16,8 +18,24 @@
}
public function isValid($object) {
+ $doc = $this->getDocComment();
$name = $this->getName();
- $len = strlen($object->$name);
- return $len <= 10 && $len >= 5;
+ $value = $object->$name;
+ if (preg_match_all('/@is ([a-z]+) (.*)/', $doc, $matches)) {
+ foreach ($matches[1] as $key => $spec) {
+ $spec = ucfirst($spec);
+ $reflection = new ReflectionClass('Argil_Specification_' . $spec);
+ $args = array_merge(
+ array($value),
+ explode(' ', $matches[2][$key])
+ );
+ $specObj = $reflection->newInstanceArgs($args);
+ if (!$specObj->valid()) {
+ return false;
+ }
+ }
+ }
+
+ return true;
}
}
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:38:34 UTC (rev 513)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:51:45 UTC (rev 514)
@@ -5,8 +5,8 @@
class ArgilSamplePropertyObjectForReflection {
/**
- * @is length <= 10
- * @is length >= 5
+ * @is length 10 <=
+ * @is length 5 >=
*/
public $publicProperty;
protected $protectedProperty;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-01 18:40:07
|
Revision: 515
http://argil.svn.sourceforge.net/argil/?rev=515&view=rev
Author: tswicegood
Date: 2007-04-01 11:40:08 -0700 (Sun, 01 Apr 2007)
Log Message:
-----------
Add in support for @isNot
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:51:45 UTC (rev 514)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 18:40:08 UTC (rev 515)
@@ -21,17 +21,26 @@
$doc = $this->getDocComment();
$name = $this->getName();
$value = $object->$name;
- if (preg_match_all('/@is ([a-z]+) (.*)/', $doc, $matches)) {
- foreach ($matches[1] as $key => $spec) {
+ if (preg_match_all('/@(is|isNot) ([a-z]+) (.*)/', $doc, $matches)) {
+ foreach ($matches[2] as $key => $spec) {
$spec = ucfirst($spec);
$reflection = new ReflectionClass('Argil_Specification_' . $spec);
$args = array_merge(
array($value),
- explode(' ', $matches[2][$key])
+ explode(' ', $matches[3][$key])
);
$specObj = $reflection->newInstanceArgs($args);
- if (!$specObj->valid()) {
- return false;
+ switch ($matches[1][$key]) {
+ case 'is' :
+ if (!$specObj->valid()) {
+ return false;
+ }
+ break;
+ case 'isNot' :
+ if ($specObj->valid()) {
+ return false;
+ }
+ break;
}
}
}
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:51:45 UTC (rev 514)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 18:40:08 UTC (rev 515)
@@ -11,6 +11,11 @@
public $publicProperty;
protected $protectedProperty;
private $privateProperty;
+
+ /**
+ * @isNot length 5 <
+ */
+ public $notLessThanFive;
}
class Argil_Reflection_PropertyTest extends UnitTestCase {
@@ -56,5 +61,12 @@
$object->publicProperty = '1234';
$this->assertFalse($public->isValid($object));
+
+ $object->notLessThanFive = '1234';
+ $attribute = new Argil_Reflection_Property($properties[3]);
+ $this->assertFalse($attribute->isValid($object));
+
+ $object->notLessThanFive = '12345';
+ $this->assertTrue($attribute->isValid($object));
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-05 03:14:14
|
Revision: 516
http://argil.svn.sourceforge.net/argil/?rev=516&view=rev
Author: tswicegood
Date: 2007-04-04 20:14:15 -0700 (Wed, 04 Apr 2007)
Log Message:
-----------
Add getProperty() method
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-04-01 18:40:08 UTC (rev 515)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-04-05 03:14:15 UTC (rev 516)
@@ -1,5 +1,6 @@
<?php
+require_once 'Argil/Reflection/Property.php';
require_once 'Argil/Reflection/PropertyList.php';
class Argil_Reflection_Object
@@ -23,4 +24,10 @@
$this->_decorated->getProperties()
);
}
+
+ public function getProperty($name) {
+ return new Argil_Reflection_Property(
+ $this->_decorated->getProperty($name)
+ );
+ }
}
\ No newline at end of file
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-04-01 18:40:08 UTC (rev 515)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-04-05 03:14:15 UTC (rev 516)
@@ -22,4 +22,13 @@
$this->assertIsA($properties[0], 'Argil_Reflection_Property');
}
+
+ public function testReturnsANamedProperty() {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObject()
+ );
+
+ $property = $reflection->getProperty('publicProperty');
+ $this->assertIsA($property, 'Argil_Reflection_Property');
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-04-05 03:21:23
|
Revision: 517
http://argil.svn.sourceforge.net/argil/?rev=517&view=rev
Author: tswicegood
Date: 2007-04-04 20:21:25 -0700 (Wed, 04 Apr 2007)
Log Message:
-----------
Add in first pass at doing validation checking at the Container
Modified Paths:
--------------
branches/experimental/src/Argil/Model/Container.php
branches/experimental/tests/Argil/Model/ContainerTest.php
Modified: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php 2007-04-05 03:14:15 UTC (rev 516)
+++ branches/experimental/src/Argil/Model/Container.php 2007-04-05 03:21:25 UTC (rev 517)
@@ -1,13 +1,17 @@
<?php
+require_once 'Argil/Reflection/Object.php';
+
class Argil_Model_Container
{
private $_contained = array();
+ private $_reflections = array();
public function __construct() {
if (func_num_args() > 0) {
foreach (func_get_args() as $object) {
$this->_contained[get_class($object)] = $object;
+ $this->_reflections[get_class($object)] = new Argil_Reflection_Object($object);
}
}
}
@@ -17,12 +21,19 @@
}
public function __set($key, $value) {
- foreach ($this->_contained as $object) {
+ foreach ($this->_contained as $objectName => $object) {
$vars = get_object_vars($object);
if (!isset($vars[$key])) {
continue;
}
+
+ $property = $this->_reflections[$objectName]->getProperty($key);
+ $oldValue = $object->$key;
$object->$key = $value;
+ if (!$property->isValid($object)) {
+ $object->$key = $oldValue;
+ throw new Exception();
+ }
return;
}
Modified: branches/experimental/tests/Argil/Model/ContainerTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/ContainerTest.php 2007-04-05 03:14:15 UTC (rev 516)
+++ branches/experimental/tests/Argil/Model/ContainerTest.php 2007-04-05 03:21:25 UTC (rev 517)
@@ -4,7 +4,15 @@
require_once 'Argil/Model/Container.php';
class ArgilSampleModel {
+ /**
+ * @is length 5 >
+ */
public $title = '';
+
+ /**
+ * @is length 10
+ */
+ public $lengthOfTen = '';
}
class ArgilSampleModelTwo { }
@@ -45,5 +53,42 @@
}
}
+
+ public function testProperlyValidatesUsingAnnotation() {
+ $container = new Argil_Model_Container(
+ new ArgilSampleModel()
+ );
+
+ try {
+ $container->lengthOfTen = '1234567890';
+ $this->pass('Exception not expected');
+ } catch(Exception $e) {
+ $this->fail('Unexpected exception?');
+ }
+
+ try {
+ $container->lengthOfTen = '123456789';
+ $this->fail('Exception not caught');
+ } catch(Exception $e) {
+ $this->pass('Exception caught');
+ }
+ }
+
+ public function testOriginalValueKeptWhenInvalidPropertySet() {
+ $container = new Argil_Model_Container(
+ new ArgilSampleModel()
+ );
+
+ $container->lengthOfTen = '1234567890';
+
+ try {
+ $container->lengthOfTen = '123456789';
+ $this->fail('Exception not caught');
+ } catch(Exception $e) {
+ $this->pass('Exception caught');
+ }
+
+ $this->assertEqual($container->lengthOfTen, '1234567890');
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-24 01:40:27
|
Revision: 522
http://argil.svn.sourceforge.net/argil/?rev=522&view=rev
Author: tswicegood
Date: 2007-05-23 18:39:14 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Add a String spec object that's tested
Added Paths:
-----------
branches/experimental/src/Argil/Specification/String.php
branches/experimental/tests/Argil/Specification/StringTest.php
Added: branches/experimental/src/Argil/Specification/String.php
===================================================================
--- branches/experimental/src/Argil/Specification/String.php (rev 0)
+++ branches/experimental/src/Argil/Specification/String.php 2007-05-24 01:39:14 UTC (rev 522)
@@ -0,0 +1,19 @@
+<?php
+
+class Argil_Specification_String
+{
+ private $_valid = false;
+
+ public function __construct($string)
+ {
+ if (is_string($string) || (is_object($string) && method_exists($string, '__toString'))) {
+ $this->_valid = true;
+ }
+
+ }
+
+ public function valid()
+ {
+ return $this->_valid;
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Specification/StringTest.php
===================================================================
--- branches/experimental/tests/Argil/Specification/StringTest.php (rev 0)
+++ branches/experimental/tests/Argil/Specification/StringTest.php 2007-05-24 01:39:14 UTC (rev 522)
@@ -0,0 +1,41 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Specification/String.php';
+
+
+class ArgilSpecificationStringableObject
+{
+ public function __toString() { }
+}
+
+class Argil_Specification_StringTest extends UnitTestCase
+{
+ public function testValidatesStrings()
+ {
+ $spec = new Argil_Specification_String('Hello World');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_String($this);
+ $this->assertFalse($spec->valid());
+
+ $spec = new Argil_Specification_String(123);
+ $this->assertFalse($spec->valid());
+
+ $spec = new Argil_Specification_String(123.321);
+ $this->assertFalse($spec->valid());
+
+ $spec = new Argil_Specification_String(false);
+ $this->assertFalse($spec->valid());
+
+ $spec = new Argil_Specification_String(array());
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsObjectsThatHaveAToStringMagicMethod()
+ {
+ $string = new ArgilSpecificationStringableObject();
+ $spec = new Argil_Specification_String($string);
+ $this->assertTrue($spec->valid());
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-24 01:50:39
|
Revision: 523
http://argil.svn.sourceforge.net/argil/?rev=523&view=rev
Author: tswicegood
Date: 2007-05-23 18:50:40 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Add in test to fix issue with annotations that have no parameters and
refactor loading of specs so everything can be loaded.
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-05-24 01:39:14 UTC (rev 522)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-05-24 01:50:40 UTC (rev 523)
@@ -1,5 +1,5 @@
<?php
-require_once 'Argil/Specification/Length.php';
+
class Argil_Reflection_Property
{
private $_decorated = null;
@@ -14,15 +14,21 @@
$method
) , $arguments);
}
+
+ /**
+ * @todo refactor out specification loading into Argil_Loader_Specification
+ */
public function isValid($object)
{
$doc = $this->getDocComment();
$name = $this->getName();
$value = $object->$name;
- if (preg_match_all('/@(is|isNot) ([a-z]+) (.*)/', $doc, $matches)) {
+ if (preg_match_all('/@(is|isNot) ([a-z]+) ?(.*)/i', $doc, $matches)) {
foreach($matches[2] as $key => $spec) {
$spec = ucfirst($spec);
- $reflection = new ReflectionClass('Argil_Specification_' . $spec);
+ $specName = 'Argil_Specification_' . $spec;
+ require_once str_replace('_', '/', $specName) . '.php';
+ $reflection = new ReflectionClass($specName);
$args = array_merge(array(
$value
) , explode(' ', $matches[3][$key]));
@@ -42,6 +48,7 @@
}
}
}
+
return true;
}
}
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-05-24 01:39:14 UTC (rev 522)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-05-24 01:50:40 UTC (rev 523)
@@ -14,6 +14,11 @@
* @isNot length 5 <
*/
public $notLessThanFive;
+
+ /**
+ * @is String
+ */
+ public $string = '';
}
class Argil_Reflection_PropertyTest extends UnitTestCase
{
@@ -53,4 +58,18 @@
$object->notLessThanFive = '12345';
$this->assertTrue($attribute->isValid($object));
}
+
+ public function testAllowsSpecsWithoutParameters()
+ {
+ $object = new ArgilSamplePropertyObjectForReflection();
+ $reflection = new ReflectionObject($object);
+
+ $properties = $reflection->getProperties();
+ $stringReflection = new Argil_Reflection_Property($properties[4]);
+
+ $this->assertEqual('string', $stringReflection->getName(), 'sanity check');
+ $object->string = 123;
+ $this->assertFalse($stringReflection->isValid($object));
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 00:44:01
|
Revision: 526
http://argil.svn.sourceforge.net/argil/?rev=526&view=rev
Author: tswicegood
Date: 2007-05-24 17:44:02 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Add in the start of some annontation parsing
Added Paths:
-----------
branches/experimental/src/Argil/Util/
branches/experimental/src/Argil/Util/Annotation/
branches/experimental/src/Argil/Util/Annotation/Collection.php
branches/experimental/src/Argil/Util/Annotation/Value.php
branches/experimental/tests/Argil/Util/
branches/experimental/tests/Argil/Util/Annotation/
branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Collection.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Collection.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Collection.php 2007-05-25 00:44:02 UTC (rev 526)
@@ -0,0 +1,16 @@
+<?php
+
+class Argil_Util_Annotation_Collection
+{
+ private $_stack = array();
+
+ public function add(Argil_Util_Annotation_Value $annontation)
+ {
+ $this->_stack[] = $annotation;
+ }
+
+ public function count()
+ {
+ return count($this->_stack);
+ }
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Util/Annotation/Value.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 00:44:02 UTC (rev 526)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_Annotation_Value
+{
+
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php 2007-05-25 00:44:02 UTC (rev 526)
@@ -0,0 +1,15 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Collection.php';
+
+class Argil_Util_Annotation_CollectionTest extends UnitTestCase
+{
+ public function testCanBeAddedTo()
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ $this->assertEqual(0, $collection->count());
+ $collection->add(new MockArgil_Util_Annotation_Value());
+ $this->assertEqual(1, $collection->count());
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <tsw...@us...> - 2007-05-25 18:52:22
|
Revision: 528
http://argil.svn.sourceforge.net/argil/?rev=528&view=rev
Author: tswicegood
Date: 2007-05-25 11:51:33 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Make second parameter an array only
Modified Paths:
--------------
branches/experimental/src/Argil/Util/Annotation/Value.php
branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
Modified: branches/experimental/src/Argil/Util/Annotation/Value.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 18:44:04 UTC (rev 527)
+++ branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 18:51:33 UTC (rev 528)
@@ -7,7 +7,7 @@
private $_name = null;
private $_params = array();
- public function __construct($name, $params = array())
+ public function __construct($name, array $params = array())
{
if (!is_string($name)) {
throw new Argil_Util_Annotation_Value_Exception(
Modified: branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ValueTest.php 2007-05-25 18:44:04 UTC (rev 527)
+++ branches/experimental/tests/Argil/Util/Annotation/ValueTest.php 2007-05-25 18:51:33 UTC (rev 528)
@@ -71,4 +71,15 @@
$this->assertEqual('non-string provided for name at construct', $e->getMessage());
}
}
+
+ public function testOnlyTakesAnOptionalArrayForSecondParamter()
+ {
+ $refl = new ReflectionClass('Argil_Util_Annotation_Value');
+ $constructor = $refl->getConstructor();
+ $params = $constructor->getParameters();
+
+ $secondParam = $params[1];
+ $this->assertTrue($secondParam->isArray());
+ $this->assertTrue($secondParam->isOptional());
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:00:06
|
Revision: 529
http://argil.svn.sourceforge.net/argil/?rev=529&view=rev
Author: tswicegood
Date: 2007-05-25 16:00:08 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in the fleshing out of the Annotation_Collection object
Modified Paths:
--------------
branches/experimental/src/Argil/Util/Annotation/Collection.php
branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
Modified: branches/experimental/src/Argil/Util/Annotation/Collection.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Collection.php 2007-05-25 18:51:33 UTC (rev 528)
+++ branches/experimental/src/Argil/Util/Annotation/Collection.php 2007-05-25 23:00:08 UTC (rev 529)
@@ -1,10 +1,11 @@
<?php
-class Argil_Util_Annotation_Collection
+class Argil_Util_Annotation_Collection implements Iterator
{
+ private $_cursor = 0;
private $_stack = array();
- public function add(Argil_Util_Annotation_Value $annontation)
+ public function add(Argil_Util_Annotation_Value $annotation)
{
$this->_stack[] = $annotation;
}
@@ -13,4 +14,70 @@
{
return count($this->_stack);
}
+
+ public function has($name)
+ {
+ $stackCount = $this->count();
+ for ($i = 0; $i < $stackCount; $i++) {
+ if ($this->_stack[$i]->name == $name) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public function filter($names)
+ {
+ $names = (array)$names;
+
+ $return = new self();
+ $stackCount = $this->count();
+ for ($i = 0; $i < $stackCount; $i++) {
+ if (in_array($this->_stack[$i]->name, $names)) {
+ $return->add($this->_stack[$i]);
+ }
+ }
+
+ return $return;
+ }
+
+ public function filterOut($names)
+ {
+ $names = (array)$names;
+
+ $return = new self();
+ $stackCount = $this->count();
+ for ($i = 0; $i < $stackCount; $i++) {
+ if (!in_array($this->_stack[$i]->name, $names)) {
+ $return->add($this->_stack[$i]);
+ }
+ }
+
+ return $return;
+ }
+
+ public function current()
+ {
+ return $this->_stack[$this->_cursor];
+ }
+
+ public function key()
+ {
+ return $this->valid() ? $this->_cursor : null;
+ }
+
+ public function next()
+ {
+ $this->_cursor++;
+ }
+
+ public function rewind()
+ {
+ $this->_cursor = 0;
+ }
+
+ public function valid()
+ {
+ return $this->_cursor < $this->count();
+ }
}
\ No newline at end of file
Modified: branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php 2007-05-25 18:51:33 UTC (rev 528)
+++ branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php 2007-05-25 23:00:08 UTC (rev 529)
@@ -12,4 +12,117 @@
$collection->add(new MockArgil_Util_Annotation_Value());
$this->assertEqual(1, $collection->count());
}
+
+ public function testHasTellsWhetherTheCollectionContainsASpecificAnnotation()
+ {
+ $annotation = new MockArgil_Util_Annotation_Value();
+ $annotation->setReturnValue('__get', 'known', array('name'));
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($annotation);
+
+ $this->assertTrue($collection->has('known'));
+ $this->assertFalse($collection->has('unknown'));
+ }
+
+ public function testCanReturnANewCollectionWithFilteredResults()
+ {
+ $is = new Argil_Util_Annotation_Value('is');
+ $isNot = new Argil_Util_Annotation_Value('isNot');
+
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($is);
+ $collection->add($isNot);
+
+ $this->assertEqual(2, $collection->count(), 'sanity check');
+ $this->assertTrue($collection->has('is'), 'sanity check');
+ $this->assertTrue($collection->has('isNot'), 'sanity check');
+
+ $isCollection = $collection->filter('is');
+ $this->assertEqual(1, $isCollection->count());
+ $this->assertTrue($isCollection->has('is'));
+ $this->assertFalse($isCollection->has('isNot'));
+
+ $isNotCollection = $collection->filter('isNot');
+ $this->assertEqual(1, $isNotCollection->count());
+ $this->assertFalse($isNotCollection->has('is'));
+ $this->assertTrue($isNotCollection->has('isNot'));
+ }
+
+ public function testCanReturnANewCollectionWithMultipleFilteredResults()
+ {
+ $is = new Argil_Util_Annotation_Value('is');
+ $isNot = new Argil_Util_Annotation_Value('isNot');
+
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($is);
+ $collection->add($isNot);
+
+ $this->assertEqual(2, $collection->count(), 'sanity check');
+ $this->assertTrue($collection->has('is'), 'sanity check');
+ $this->assertTrue($collection->has('isNot'), 'sanity check');
+
+ $newCollection = $collection->filter(array('is', 'isNot'));
+ $this->assertEqual(2, $newCollection->count());
+ $this->assertTrue($newCollection->has('is'));
+ $this->assertTrue($newCollection->has('isNot'));
+
+ $this->assertTrue(
+ $collection == $newCollection,
+ '$collection and $newCollection are equal in what they contains'
+ );
+ $this->assertTrue(
+ $collection !== $newCollection,
+ '$collection and $newCollection are not the exact same object'
+ );
+ }
+
+ public function testCanFilterOutAnnotationsAsWell()
+ {
+ $is = new Argil_Util_Annotation_Value('is');
+ $isNot = new Argil_Util_Annotation_Value('isNot');
+
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($is);
+ $collection->add($isNot);
+
+ $this->assertEqual(2, $collection->count(), 'sanity check');
+ $this->assertTrue($collection->has('is'), 'sanity check');
+ $this->assertTrue($collection->has('isNot'), 'sanity check');
+
+ $isOutCollection = $collection->filterOut('is');
+ $this->assertEqual(1, $isOutCollection->count());
+ $this->assertFalse($isOutCollection->has('is'));
+ $this->assertTrue($isOutCollection->has('isNot'));
+
+ $isNotOutCollection = $collection->filterOut('isNot');
+ $this->assertEqual(1, $isNotOutCollection->count());
+ $this->assertTrue($isNotOutCollection->has('is'));
+ $this->assertFalse($isNotOutCollection->has('isNot'));
+ }
+
+ public function testIsAnIterator()
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ $this->assertIsA($collection, 'Iterator');
+
+ $this->assertFalse($collection->valid());
+ $this->assertNull($collection->key());
+ $this->assertNull($collection->current());
+
+ $is = new Argil_Util_Annotation_Value('is');
+ $collection->add($is);
+ $this->assertTrue($collection->valid());
+ $this->assertEqual($collection->current(), $is);
+ $this->assertIdentical($collection->key(), 0);
+
+ $collection->next();
+ $this->assertFalse($collection->valid());
+ $this->assertNull($collection->current());
+ $this->assertNull($collection->key());
+
+ $collection->rewind();
+ $this->assertTrue($collection->valid());
+ $this->assertEqual($collection->current(), $is);
+ $this->assertIdentical($collection->key(), 0);
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:00:37
|
Revision: 530
http://argil.svn.sourceforge.net/argil/?rev=530&view=rev
Author: tswicegood
Date: 2007-05-25 16:00:37 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in the Annotation_Parser object and appropriate tests
Added Paths:
-----------
branches/experimental/src/Argil/Util/Annotation/Parser.php
branches/experimental/tests/Argil/Util/Annotation/ParserTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Parser.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Parser.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Parser.php 2007-05-25 23:00:37 UTC (rev 530)
@@ -0,0 +1,21 @@
+<?php
+
+require_once 'Argil/Util/Annotation/Collection.php';
+
+class Argil_Util_Annotation_Parser
+{
+ public function parse($string)
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ if (!preg_match_all('/@([a-z]+) ?(.*)/i', $string, $matches)) {
+ return $collection;
+ }
+
+ foreach ($matches[1] as $key => $match) {
+ $params = !empty($matches[2][$key]) ? explode(' ', $matches[2][$key]) : array();
+
+ $collection->add(new Argil_Util_Annotation_Value($match, $params));
+ }
+ return $collection;
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/ParserTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ParserTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/ParserTest.php 2007-05-25 23:00:37 UTC (rev 530)
@@ -0,0 +1,54 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Parser.php';
+
+class Argil_Util_Annontation_ParserTest extends UnitTestCase
+{
+ public function testReturnsACollectionOfAnnotationsAfterParsing()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $list = $parser->parse('');
+
+ $this->assertIsA($list, 'Argil_Util_Annotation_Collection');
+ $this->assertEqual(0, $list->count());
+ unset($list);
+
+ $random = rand(10, 20);
+ $str = <<<END
+/**
+ * @is String
+ * @dummy
+ * @table string_table
+ * @isNot Length {$random} <
+ */
+END;
+ $list = $parser->parse($str);
+ $this->assertEqual(4, $list->count());
+
+ $this->assertTrue($list->has('is'));
+ $this->assertTrue($list->has('dummy'));
+ $this->assertTrue($list->has('table'));
+ $this->assertTrue($list->has('isNot'));
+
+ $is = $list->filter('is')->current();
+ $this->assertIsA($is, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($is->name, 'is');
+ $this->assertEqual($is->params, array('String'));
+
+ $dummy = $list->filter('dummy')->current();
+ $this->assertIsA($dummy, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($dummy->name, 'dummy');
+ $this->assertEqual($dummy->params, array());
+
+ $table = $list->filter('table')->current();
+ $this->assertIsA($table, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($table->name, 'table');
+ $this->assertEqual($table->params, array('string_table'));
+
+ $isNot = $list->filter('isNot')->current();
+ $this->assertIsA($isNot, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($isNot->name, 'isNot');
+ $this->assertEqual($isNot->params, array('Length', $random, '<'));
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:07:47
|
Revision: 531
http://argil.svn.sourceforge.net/argil/?rev=531&view=rev
Author: tswicegood
Date: 2007-05-25 16:07:49 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add getTable() to the reflection object
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-25 23:00:37 UTC (rev 530)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-25 23:07:49 UTC (rev 531)
@@ -1,6 +1,8 @@
<?php
require_once 'Argil/Reflection/Property.php';
require_once 'Argil/Reflection/PropertyList.php';
+require_once 'Argil/Util/Annotation/Parser.php';
+
class Argil_Reflection_Object
{
private $_decorated = null;
@@ -24,4 +26,16 @@
{
return new Argil_Reflection_Property($this->_decorated->getProperty($name));
}
+
+ public function getTable()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $collection = $parser->parse($this->_decorated->getDocComment());
+
+ if (!$collection->has('table')) {
+ return '';
+ }
+
+ return array_shift($collection->filter('table')->current()->params);
+ }
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-25 23:00:37 UTC (rev 530)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-25 23:07:49 UTC (rev 531)
@@ -7,6 +7,12 @@
protected $protectedProperty = '';
private $privateProperty = '';
}
+
+/**
+ * @table a_custom_table
+ */
+class ArgilSampleReflectionObjectWithTable { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -23,4 +29,19 @@
$property = $reflection->getProperty('publicProperty');
$this->assertIsA($property, 'Argil_Reflection_Property');
}
+
+ public function testReturnsTableNameIfTableAnnotationSet()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithTable()
+ );
+
+ $this->assertEqual('a_custom_table', $reflection->getTable());
+ }
+
+ public function testReturnsEmptyStringIfTableAnnotationIsNotSet()
+ {
+ $reflection = new Argil_Reflection_Object($this);
+ $this->assertEqual('', $reflection->getTable());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:35:49
|
Revision: 532
http://argil.svn.sourceforge.net/argil/?rev=532&view=rev
Author: tswicegood
Date: 2007-05-25 16:35:50 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in a camel caps to underscore converter
Added Paths:
-----------
branches/experimental/src/Argil/Util/Template/
branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/
branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php
branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php
branches/experimental/tests/Argil/Util/Template/
branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php
Added: branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php
===================================================================
--- branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php 2007-05-25 23:35:50 UTC (rev 532)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_Template_CamelCapsToUnderscore_Exception extends Exception
+{
+
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php
===================================================================
--- branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php (rev 0)
+++ branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php 2007-05-25 23:35:50 UTC (rev 532)
@@ -0,0 +1,21 @@
+<?php
+
+require_once 'Argil/Util/Template/CamelCapsToUnderscore/Exception.php';
+
+class Argil_Util_Template_CamelCapsToUnderscore
+{
+ private $value = 'camel_caps';
+
+ public function __construct($string)
+ {
+ if (!is_string($string) || empty($string)) {
+ throw new Argil_Util_Template_CamelCapsToUnderscore_Exception();
+ }
+ $this->value = strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $string));
+ }
+
+ public function __toString()
+ {
+ return $this->value;
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php 2007-05-25 23:35:50 UTC (rev 532)
@@ -0,0 +1,58 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Template/CamelCapsToUnderscore.php';
+
+class Argil_Util_Template_CamelCapsToUnderscoreTest extends UnitTestCase
+{
+ public function testConvertsCamelCapsToUnderscoredStrings()
+ {
+ $template = new Argil_Util_Template_CamelCapsToUnderscore('CamelCaps');
+ $this->assertEqual((string)$template, 'camel_caps');
+ unset($template);
+
+ $template = new Argil_Util_Template_CamelCapsToUnderscore('CamelCapsButLonger');
+ $this->assertEqual((string)$template, 'camel_caps_but_longer');
+ }
+
+ public function testRequiresANonEmptyStringAsOnlyParameterInConstruct()
+ {
+ new Argil_Util_Template_CamelCapsToUnderscore('non-empty');
+ $this->pass('exception not thrown');
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore('');
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore(1);
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore(array());
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore(123.321);
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore($this);
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:41:45
|
Revision: 533
http://argil.svn.sourceforge.net/argil/?rev=533&view=rev
Author: tswicegood
Date: 2007-05-25 16:40:24 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add getTable() to the Container
Modified Paths:
--------------
branches/experimental/src/Argil/Model/Container.php
branches/experimental/tests/Argil/Model/ContainerTest.php
Modified: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php 2007-05-25 23:35:50 UTC (rev 532)
+++ branches/experimental/src/Argil/Model/Container.php 2007-05-25 23:40:24 UTC (rev 533)
@@ -1,5 +1,7 @@
<?php
require_once 'Argil/Reflection/Object.php';
+require_once 'Argil/Util/Template/CamelCapsToUnderscore.php';
+
class Argil_Model_Container
{
private $_contained = array();
@@ -44,4 +46,16 @@
}
}
}
+
+ public function getTable()
+ {
+ reset($this->_contained);
+ $reflection = new Argil_Reflection_Object(current($this->_contained));
+ $table = $reflection->getTable();
+ if (!empty($table)) {
+ return $table;
+ }
+
+ return (string)new Argil_Util_Template_CamelCapsToUnderscore($reflection->getName());
+ }
}
Modified: branches/experimental/tests/Argil/Model/ContainerTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-25 23:35:50 UTC (rev 532)
+++ branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-25 23:40:24 UTC (rev 533)
@@ -1,6 +1,7 @@
<?php
require_once dirname(__FILE__) . '/../../config.php';
require_once 'Argil/Model/Container.php';
+
class ArgilSampleModel
{
/**
@@ -15,6 +16,14 @@
class ArgilSampleModelTwo
{
}
+
+/**
+ * @table some_table
+ */
+class ArgilModelWithTable
+{
+}
+
class Argil_Model_ContainerTest extends UnitTestCase
{
public function testWillTellWhatTypeOfObjectThisContains()
@@ -73,4 +82,20 @@
}
$this->assertEqual($container->lengthOfTen, '1234567890');
}
+
+ public function testCanDetermineTableName()
+ {
+ $container = new Argil_Model_Container(new ArgilSampleModel());
+ $this->assertEqual($container->getTable(), 'argil_sample_model');
+ unset($container);
+
+ $container = new Argil_Model_Container(new ArgilSampleModelTwo());
+ $this->assertEqual($container->getTable(), 'argil_sample_model_two');
+ }
+
+ public function testUsesModelTablePropertyIfSet()
+ {
+ $container = new Argil_Model_Container(new ArgilModelWithTable());
+ $this->assertEqual($container->getTable(), 'some_table');
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-29 18:10:53
|
Revision: 536
http://argil.svn.sourceforge.net/argil/?rev=536&view=rev
Author: tswicegood
Date: 2007-05-29 11:10:46 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Add in Argil_Config and the appropriate tests
Added Paths:
-----------
branches/experimental/src/Argil/Config/
branches/experimental/src/Argil/Config/Exception.php
branches/experimental/src/Argil/Config.php
branches/experimental/tests/Argil/ConfigTest.php
Added: branches/experimental/src/Argil/Config/Exception.php
===================================================================
--- branches/experimental/src/Argil/Config/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Config/Exception.php 2007-05-29 18:10:46 UTC (rev 536)
@@ -0,0 +1,3 @@
+<?php
+
+class Argil_Config_Exception extends Exception { }
\ No newline at end of file
Added: branches/experimental/src/Argil/Config.php
===================================================================
--- branches/experimental/src/Argil/Config.php (rev 0)
+++ branches/experimental/src/Argil/Config.php 2007-05-29 18:10:46 UTC (rev 536)
@@ -0,0 +1,30 @@
+<?php
+
+require_once 'Argil/Config/Exception.php';
+
+class Argil_Config
+{
+ private $_stack = array();
+
+ public function __construct(array $values = array())
+ {
+ $this->_stack = $values;
+ }
+
+ public function __get($key)
+ {
+ return $this->_stack[$key];
+ }
+
+ public function __set($key, $value)
+ {
+ throw new Argil_Config_Exception(
+ 'attempted to set read-only property [' . $key . ']'
+ );
+ }
+
+ public function __isset($key)
+ {
+ return isset($this->_stack[$key]);
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/ConfigTest.php
===================================================================
--- branches/experimental/tests/Argil/ConfigTest.php (rev 0)
+++ branches/experimental/tests/Argil/ConfigTest.php 2007-05-29 18:10:46 UTC (rev 536)
@@ -0,0 +1,58 @@
+<?php
+
+require_once dirname(__FILE__) . '/../config.php';
+require_once 'Argil/Config.php';
+
+class Argil_ConfigTest extends UnitTestCase
+{
+ public function testTakesAnOptionalArrayAtConstruct()
+ {
+ new Argil_Config(array());
+ $this->assertNoErrors();
+
+ new Argil_config();
+ $this->assertNoErrors();
+
+ $reflection = new ReflectionObject(new Argil_Config(array()));
+ $param = array_shift($reflection->getConstructor()->getParameters());
+ $this->assertTrue($param->isArray());
+ $this->assertTrue($param->isOptional());
+ }
+
+ public function testArrayKeysAreAccessibleViaObjectProperty()
+ {
+ $array = array(
+ 'string' => 'hello world',
+ 'int' => 123,
+ 'random' => rand(10, 20),
+ );
+
+ $config = new Argil_Config($array);
+ foreach ($array as $key => $value) {
+ $this->assertTrue(isset($config->$key));
+ // mutate the key and make sure it still doesn't work
+ $badKey = $key . '_mutated';
+ $this->assertFalse(isset($config->$badKey));
+
+ $this->assertEqual($config->$key, $value);
+ }
+ }
+
+ public function testPropertiesAreReadOnly()
+ {
+ $key = 'random_' . rand(10, 20);
+ $random = rand(10, 20);
+ $config = new Argil_Config(array($key => $random));
+ $this->assertEqual($config->$key, $random, 'sanity check');
+ try {
+ $config->$key = 'new value';
+ $this->fail('exception not thrown');
+ } catch (Argil_Config_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual(
+ $e->getMessage(),
+ 'attempted to set read-only property [' . $key . ']'
+ );
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-29 19:59:38
|
Revision: 537
http://argil.svn.sourceforge.net/argil/?rev=537&view=rev
Author: tswicegood
Date: 2007-05-29 12:59:35 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Add in a stub for Argil_Pdo
Added Paths:
-----------
branches/experimental/src/Argil/Pdo.php
branches/experimental/tests/Argil/PdoTest.php
Added: branches/experimental/src/Argil/Pdo.php
===================================================================
--- branches/experimental/src/Argil/Pdo.php (rev 0)
+++ branches/experimental/src/Argil/Pdo.php 2007-05-29 19:59:35 UTC (rev 537)
@@ -0,0 +1,36 @@
+<?php
+
+class Argil_Pdo
+{
+ public function __construct() { }
+
+ public function __sleep() { }
+
+ public function __wakeup() { }
+
+ public function beginTransaction() { }
+
+ public function commit() { }
+
+ public function errorCode() { }
+
+ public function errorInfo() { }
+
+ public function exec($statement) { }
+
+ public function getAttribute($attribute) { }
+
+ public function getAvailableDrivers() { }
+
+ public function lastInsertId($name = null) { }
+
+ public function prepare($string, array $driver_options = array()) { }
+
+ public function query($statement, $p2 = null, $p3 = null, array $p4 = null) { }
+
+ public function quote($string, $parameter_type = PDO::PARAM_STR) { }
+
+ public function rollBack() { }
+
+ public function setAttribute($attribute, $value) { }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/PdoTest.php
===================================================================
--- branches/experimental/tests/Argil/PdoTest.php (rev 0)
+++ branches/experimental/tests/Argil/PdoTest.php 2007-05-29 19:59:35 UTC (rev 537)
@@ -0,0 +1,25 @@
+<?php
+
+require_once dirname(__FILE__) . '/../config.php';
+require_once 'Argil/Pdo.php';
+
+class Argil_PdoTest extends UnitTestCase
+{
+ public function testHasAllOfTheSameMethodsAsPdo()
+ {
+ $argil = new ReflectionClass('Argil_Pdo');
+ $pdo = new ReflectionClass('PDO');
+
+ $argilMethods = array();
+ foreach ($argil->getMethods() as $argilMethod) {
+ $argilMethods[] = $argilMethod->getName();
+ }
+
+ foreach ($pdo->getMethods() as $pdoMethod) {
+ $this->assertTrue(
+ in_array($pdoMethod->getName(), $argilMethods),
+ "Checking that {$pdoMethod->getName()} is declared"
+ );
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-30 20:58:11
|
Revision: 538
http://argil.svn.sourceforge.net/argil/?rev=538&view=rev
Author: tswicegood
Date: 2007-05-30 13:58:12 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Add a getPrimaryKey() method
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-29 19:59:35 UTC (rev 537)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-30 20:58:12 UTC (rev 538)
@@ -38,4 +38,16 @@
return array_shift($collection->filter('table')->current()->params);
}
+
+ public function getPrimaryKey()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $collection = $parser->parse($this->_decorated->getDocComment());
+
+ if (!$collection->has('primaryKey')) {
+ return '';
+ }
+
+ return array_shift($collection->filter('primaryKey')->current()->params);
+ }
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-29 19:59:35 UTC (rev 537)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-30 20:58:12 UTC (rev 538)
@@ -13,6 +13,11 @@
*/
class ArgilSampleReflectionObjectWithTable { }
+/**
+ * @primaryKey a_custom_id
+ */
+class ArgilSampleReflectionObjectWithPrimaryKey { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -44,4 +49,18 @@
$reflection = new Argil_Reflection_Object($this);
$this->assertEqual('', $reflection->getTable());
}
+
+ public function testReturnsPrimaryKeyIfPrimaryKeyAnnotationSet()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithPrimaryKey()
+ );
+ $this->assertEqual('a_custom_id', $reflection->getPrimaryKey());
+ }
+
+ public function testReturnsEmptyStringIfPrimaryAnnotationIsNotSet()
+ {
+ $reflection = new Argil_Reflection_Object($this);
+ $this->assertEqual('', $reflection->getPrimaryKey());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-30 21:11:14
|
Revision: 539
http://argil.svn.sourceforge.net/argil/?rev=539&view=rev
Author: tswicegood
Date: 2007-05-30 14:11:16 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Adds the ability for @primaryKey to allow multi-column keys
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-30 20:58:12 UTC (rev 538)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-30 21:11:16 UTC (rev 539)
@@ -48,6 +48,7 @@
return '';
}
- return array_shift($collection->filter('primaryKey')->current()->params);
+ $keys = $collection->filter('primaryKey')->current()->params;
+ return ((count($keys) == 1) ? array_shift($keys) : $keys);
}
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-30 20:58:12 UTC (rev 538)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-30 21:11:16 UTC (rev 539)
@@ -18,6 +18,11 @@
*/
class ArgilSampleReflectionObjectWithPrimaryKey { }
+/**
+ * @primaryKey col1 col2
+ */
+class ArgilSampleReflectionObjectWithCompoundPrimaryKey { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -63,4 +68,12 @@
$reflection = new Argil_Reflection_Object($this);
$this->assertEqual('', $reflection->getPrimaryKey());
}
+
+ public function testReturnsAnArrayForMultiColumnPrimaryKeys()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithCompoundPrimaryKey()
+ );
+ $this->assertEqual(array('col1', 'col2'), $reflection->getPrimaryKey());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-30 22:41:30
|
Revision: 540
http://argil.svn.sourceforge.net/argil/?rev=540&view=rev
Author: tswicegood
Date: 2007-05-30 15:41:32 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Add in getPrimaryKey() to use when locating an object in persistent storage
Modified Paths:
--------------
branches/experimental/src/Argil/Model/Container.php
branches/experimental/tests/Argil/Model/ContainerTest.php
Modified: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php 2007-05-30 21:11:16 UTC (rev 539)
+++ branches/experimental/src/Argil/Model/Container.php 2007-05-30 22:41:32 UTC (rev 540)
@@ -58,4 +58,16 @@
return (string)new Argil_Util_Template_CamelCapsToUnderscore($reflection->getName());
}
+
+ public function getPrimaryKey()
+ {
+ reset($this->_contained);
+ $reflection = new Argil_Reflection_Object(current($this->_contained));
+ $primary_key = $reflection->getPrimaryKey();
+ if (!empty($primary_key)) {
+ return $primary_key;
+ }
+
+ return $this->getTable() . '_id';
+ }
}
Modified: branches/experimental/tests/Argil/Model/ContainerTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-30 21:11:16 UTC (rev 539)
+++ branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-30 22:41:32 UTC (rev 540)
@@ -24,6 +24,13 @@
{
}
+/**
+ * @primaryKey id
+ */
+class ArgilModelWithId
+{
+}
+
class Argil_Model_ContainerTest extends UnitTestCase
{
public function testWillTellWhatTypeOfObjectThisContains()
@@ -98,4 +105,20 @@
$container = new Argil_Model_Container(new ArgilModelWithTable());
$this->assertEqual($container->getTable(), 'some_table');
}
+
+ public function testCanDeterminePrimaryKeyBasedOnTableNamePlusUnderscoreId()
+ {
+ $container = new Argil_Model_Container(new ArgilSampleModel());
+ $this->assertEqual($container->getPrimaryKey(), 'argil_sample_model_id');
+ unset($container);
+
+ $container = new Argil_Model_Container(new ArgilModelWithTable());
+ $this->assertEqual($container->getPrimaryKey(), 'some_table_id');
+ }
+
+ public function testUsesModelPrimaryAnnotationIfSet()
+ {
+ $container = new Argil_Model_Container(new ArgilModelWithId());
+ $this->assertEqual($container->getPrimaryKey(), 'id');
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|